Search in sources :

Example 6 with NumberFormatter

use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.

the class PathogenFrame method setStatusMessage.

private void setStatusMessage() {
    Tree tree = pathogenPanel.getTree();
    if (tree != null) {
        String message = "";
        message += "Tree loaded, " + tree.getTaxonCount() + " taxa";
        TemporalRooting tr = pathogenPanel.getTemporalRooting();
        if (tr.isContemporaneous()) {
            message += ", contemporaneous tips";
        } else {
            NumberFormatter nf = new NumberFormatter(3);
            message += ", dated tips with range " + nf.format(tr.getDateRange());
        }
        statusLabel.setText(message);
    }
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree) NumberFormatter(dr.util.NumberFormatter)

Example 7 with NumberFormatter

use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.

the class TempestPanel method setupPanel.

public void setupPanel() {
    StringBuilder sb = new StringBuilder();
    NumberFormatter nf = new NumberFormatter(6);
    if (tree != null) {
        temporalRooting = new TemporalRooting(tree);
        currentTree = this.tree;
        if (bestFittingRoot && bestFittingRootTree != null) {
            currentTree = bestFittingRootTree;
            sb.append("Best-fitting root");
        } else {
            sb.append("User root");
        }
        if (temporalRooting.isContemporaneous()) {
            if (tabbedPane.getSelectedIndex() == 2) {
                tabbedPane.setSelectedIndex(1);
            }
            tabbedPane.setEnabledAt(2, false);
        } else {
            tabbedPane.setEnabledAt(2, true);
        }
        RootedTree jtree = dr.evolution.tree.TreeUtils.asJeblTree(currentTree);
        List<Color> colours = new ArrayList<Color>();
        for (Node tip : jtree.getExternalNodes()) {
            Taxon taxon = jtree.getTaxon(tip);
            colours.add((Color) taxon.getAttribute("!color"));
        }
        if (temporalRooting.isContemporaneous()) {
            double[] dv = temporalRooting.getRootToTipDistances(currentTree);
            List<Double> values = new ArrayList<Double>();
            for (double d : dv) {
                values.add(d);
            }
            rootToTipChart.removeAllPlots();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(9, 70, 15));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            List<Double> dummyValues = new ArrayList<Double>();
            for (int i = 0; i < values.size(); i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues.add(yOffset + y);
            }
            rootToTipPlot = new ScatterPlot(values, dummyValues);
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(dp);
            rootToTipPanel.setXAxisTitle("root-to-tip divergence");
            rootToTipPanel.setYAxisTitle("proportion");
            residualChart.removeAllPlots();
            sb.append(", contemporaneous tips");
            sb.append(", mean root-tip distance: " + nf.format(DiscreteStatistics.mean(dv)));
            sb.append(", coefficient of variation: " + nf.format(DiscreteStatistics.stdev(dv) / DiscreteStatistics.mean(dv)));
            sb.append(", stdev: " + nf.format(DiscreteStatistics.stdev(dv)));
            sb.append(", variance: " + nf.format(DiscreteStatistics.variance(dv)));
            showMRCACheck.setVisible(false);
        } else {
            Regression r = temporalRooting.getRootToTipRegression(currentTree);
            double[] residuals = temporalRooting.getRootToTipResiduals(currentTree, r);
            pointMap.clear();
            for (int i = 0; i < currentTree.getExternalNodeCount(); i++) {
                NodeRef tip = currentTree.getExternalNode(i);
                Node node = jtree.getNode(Taxon.getTaxon(currentTree.getNodeTaxon(tip).getId()));
                node.setAttribute("residual", residuals[i]);
                pointMap.put(node, i);
            }
            rootToTipChart.removeAllPlots();
            if (showMRCACheck.isSelected()) {
                double[] dv = temporalRooting.getParentRootToTipDistances(currentTree);
                List<Double> parentDistances = new ArrayList<Double>();
                for (int i = 0; i < dv.length; i++) {
                    parentDistances.add(i, dv[i]);
                }
                List<Double> parentTimes = new ArrayList<Double>();
                for (int i = 0; i < parentDistances.size(); i++) {
                    parentTimes.add(i, r.getX(parentDistances.get(i)));
                }
                mrcaPlot = new ParentPlot(r.getXData(), r.getYData(), parentTimes, parentDistances);
                mrcaPlot.setLineColor(new Color(105, 202, 105));
                mrcaPlot.setLineStroke(new BasicStroke(0.5F));
                rootToTipChart.addPlot(mrcaPlot);
            }
            if (true) {
                double[] datePrecisions = temporalRooting.getTipDatePrecisions(currentTree);
                Variate.D ed = new Variate.D();
                for (int i = 0; i < datePrecisions.length; i++) {
                    ed.add(datePrecisions[i]);
                }
                errorBarPlot = new ErrorBarPlot(ErrorBarPlot.Orientation.HORIZONTAL, r.getXData(), r.getYData(), ed);
                errorBarPlot.setLineColor(new Color(44, 44, 44));
                errorBarPlot.setLineStroke(new BasicStroke(1.0F));
                rootToTipChart.addPlot(errorBarPlot);
            }
            rootToTipPlot = new ScatterPlot(r.getXData(), r.getYData());
            rootToTipPlot.addListener(new Plot.Adaptor() {

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(new RegressionPlot(r));
            rootToTipChart.getXAxis().addRange(r.getXIntercept(), (Double) r.getXData().getMax());
            rootToTipPanel.setXAxisTitle("time");
            rootToTipPanel.setYAxisTitle("root-to-tip divergence");
            residualChart.removeAllPlots();
            Variate.D values = (Variate.D) r.getYResidualData();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(103, 128, 144));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            Double[] dummyValues = new Double[values.getCount()];
            for (int i = 0; i < dummyValues.length; i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues[i] = yOffset + y;
            }
            Variate.D yOffsetValues = new Variate.D(dummyValues);
            residualPlot = new ScatterPlot(values, yOffsetValues);
            residualPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                @Override
                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            residualPlot.setColours(colours);
            residualPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            residualPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            residualChart.addPlot(residualPlot);
            residualChart.addPlot(dp);
            residualPanel.setXAxisTitle("residual");
            residualPanel.setYAxisTitle("proportion");
            if (SHOW_NODE_DENSITY) {
                Regression r2 = temporalRooting.getNodeDensityRegression(currentTree);
                nodeDensityChart.removeAllPlots();
                nodeDensityPlot = new ScatterPlot(r2.getXData(), r2.getYData());
                nodeDensityPlot.addListener(new Plot.Adaptor() {

                    public void selectionChanged(final Set<Integer> selectedPoints) {
                        plotSelectionChanged(selectedPoints);
                    }
                });
                nodeDensityPlot.setColours(colours);
                nodeDensityPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
                nodeDensityPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
                nodeDensityChart.addPlot(nodeDensityPlot);
                nodeDensityChart.addPlot(new RegressionPlot(r2));
                nodeDensityChart.getXAxis().addRange(r2.getXIntercept(), (Double) r2.getXData().getMax());
                nodeDensityPanel.setXAxisTitle("time");
                nodeDensityPanel.setYAxisTitle("node density");
            }
            sb.append(", dated tips");
            sb.append(", date range: " + nf.format(temporalRooting.getDateRange()));
            sb.append(", slope (rate): " + nf.format(r.getGradient()));
            sb.append(", x-intercept (TMRCA): " + nf.format(r.getXIntercept()));
            sb.append(", corr. coeff: " + nf.format(r.getCorrelationCoefficient()));
            sb.append(", R^2: " + nf.format(r.getRSquared()));
            showMRCACheck.setVisible(true);
        }
        treePanel.setTree(jtree);
        treePanel.setColourBy("residual");
    } else {
        treePanel.setTree(null);
        rootToTipChart.removeAllPlots();
        sb.append("No trees loaded");
    }
    textArea.setText(sb.toString());
    statisticsModel.fireTableStructureChanged();
    repaint();
}
Also used : Variate(dr.stats.Variate) Node(jebl.evolution.graphs.Node) Taxon(jebl.evolution.taxa.Taxon) Regression(dr.stats.Regression) RootedTree(jebl.evolution.trees.RootedTree) NumberFormatter(dr.util.NumberFormatter)

Example 8 with NumberFormatter

use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.

the class PathogenPanel method setupPanel.

public void setupPanel() {
    StringBuilder sb = new StringBuilder();
    NumberFormatter nf = new NumberFormatter(6);
    if (tree != null) {
        temporalRooting = new TemporalRooting(tree);
        currentTree = this.tree;
        if (bestFittingRoot && bestFittingRootTree != null) {
            currentTree = bestFittingRootTree;
            sb.append("Best-fitting root");
        } else {
            sb.append("User root");
        }
        if (temporalRooting.isContemporaneous()) {
            if (tabbedPane.getSelectedIndex() == 2) {
                tabbedPane.setSelectedIndex(1);
            }
            tabbedPane.setEnabledAt(2, false);
        } else {
            tabbedPane.setEnabledAt(2, true);
        }
        RootedTree jtree = dr.evolution.tree.TreeUtils.asJeblTree(currentTree);
        List<Color> colours = new ArrayList<Color>();
        for (Node tip : jtree.getExternalNodes()) {
            Taxon taxon = jtree.getTaxon(tip);
            colours.add((Color) taxon.getAttribute("!color"));
        }
        if (temporalRooting.isContemporaneous()) {
            double[] dv = temporalRooting.getRootToTipDistances(currentTree);
            List<Double> values = new ArrayList<Double>();
            for (double d : dv) {
                values.add(d);
            }
            rootToTipChart.removeAllPlots();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(9, 70, 15));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            List<Double> dummyValues = new ArrayList<Double>();
            for (int i = 0; i < values.size(); i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues.add(yOffset + y);
            }
            rootToTipPlot = new ScatterPlot(values, dummyValues);
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(dp);
            rootToTipPanel.setXAxisTitle("root-to-tip divergence");
            rootToTipPanel.setYAxisTitle("proportion");
            residualChart.removeAllPlots();
            sb.append(", contemporaneous tips");
            sb.append(", mean root-tip distance: " + nf.format(DiscreteStatistics.mean(dv)));
            sb.append(", coefficient of variation: " + nf.format(DiscreteStatistics.stdev(dv) / DiscreteStatistics.mean(dv)));
            sb.append(", stdev: " + nf.format(DiscreteStatistics.stdev(dv)));
            sb.append(", variance: " + nf.format(DiscreteStatistics.variance(dv)));
            showMRCACheck.setVisible(false);
        } else {
            Regression r = temporalRooting.getRootToTipRegression(currentTree);
            double[] residuals = temporalRooting.getRootToTipResiduals(currentTree, r);
            pointMap.clear();
            for (int i = 0; i < currentTree.getExternalNodeCount(); i++) {
                NodeRef tip = currentTree.getExternalNode(i);
                Node node = jtree.getNode(Taxon.getTaxon(currentTree.getNodeTaxon(tip).getId()));
                node.setAttribute("residual", residuals[i]);
                pointMap.put(node, i);
            }
            rootToTipChart.removeAllPlots();
            if (showMRCACheck.isSelected()) {
                double[] dv = temporalRooting.getParentRootToTipDistances(currentTree);
                List<Double> parentDistances = new ArrayList<Double>();
                for (int i = 0; i < dv.length; i++) {
                    parentDistances.add(i, dv[i]);
                }
                List<Double> parentTimes = new ArrayList<Double>();
                for (int i = 0; i < parentDistances.size(); i++) {
                    parentTimes.add(i, r.getX(parentDistances.get(i)));
                }
                mrcaPlot = new ParentPlot(r.getXData(), r.getYData(), parentTimes, parentDistances);
                mrcaPlot.setLineColor(new Color(105, 202, 105));
                mrcaPlot.setLineStroke(new BasicStroke(0.5F));
                rootToTipChart.addPlot(mrcaPlot);
            }
            if (true) {
                double[] datePrecisions = temporalRooting.getTipDatePrecisions(currentTree);
                Variate.D ed = new Variate.D();
                for (int i = 0; i < datePrecisions.length; i++) {
                    ed.add(datePrecisions[i]);
                }
                errorBarPlot = new ErrorBarPlot(ErrorBarPlot.Orientation.HORIZONTAL, r.getXData(), r.getYData(), ed);
                errorBarPlot.setLineColor(new Color(44, 44, 44));
                errorBarPlot.setLineStroke(new BasicStroke(1.0F));
                rootToTipChart.addPlot(errorBarPlot);
            }
            rootToTipPlot = new ScatterPlot(r.getXData(), r.getYData());
            rootToTipPlot.addListener(new Plot.Adaptor() {

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(new RegressionPlot(r));
            rootToTipChart.getXAxis().addRange(r.getXIntercept(), (Double) r.getXData().getMax());
            rootToTipPanel.setXAxisTitle("time");
            rootToTipPanel.setYAxisTitle("root-to-tip divergence");
            residualChart.removeAllPlots();
            Variate.D values = (Variate.D) r.getYResidualData();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(103, 128, 144));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            Double[] dummyValues = new Double[values.getCount()];
            for (int i = 0; i < dummyValues.length; i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues[i] = yOffset + y;
            }
            Variate.D yOffsetValues = new Variate.D(dummyValues);
            residualPlot = new ScatterPlot(values, yOffsetValues);
            residualPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                @Override
                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            residualPlot.setColours(colours);
            residualPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            residualPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            residualChart.addPlot(residualPlot);
            residualChart.addPlot(dp);
            residualPanel.setXAxisTitle("residual");
            residualPanel.setYAxisTitle("proportion");
            if (SHOW_NODE_DENSITY) {
                Regression r2 = temporalRooting.getNodeDensityRegression(currentTree);
                nodeDensityChart.removeAllPlots();
                nodeDensityPlot = new ScatterPlot(r2.getXData(), r2.getYData());
                nodeDensityPlot.addListener(new Plot.Adaptor() {

                    public void selectionChanged(final Set<Integer> selectedPoints) {
                        plotSelectionChanged(selectedPoints);
                    }
                });
                nodeDensityPlot.setColours(colours);
                nodeDensityPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
                nodeDensityPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
                nodeDensityChart.addPlot(nodeDensityPlot);
                nodeDensityChart.addPlot(new RegressionPlot(r2));
                nodeDensityChart.getXAxis().addRange(r2.getXIntercept(), (Double) r2.getXData().getMax());
                nodeDensityPanel.setXAxisTitle("time");
                nodeDensityPanel.setYAxisTitle("node density");
            }
            sb.append(", dated tips");
            sb.append(", date range: " + nf.format(temporalRooting.getDateRange()));
            sb.append(", slope (rate): " + nf.format(r.getGradient()));
            sb.append(", x-intercept (TMRCA): " + nf.format(r.getXIntercept()));
            sb.append(", corr. coeff: " + nf.format(r.getCorrelationCoefficient()));
            sb.append(", R^2: " + nf.format(r.getRSquared()));
            showMRCACheck.setVisible(true);
        }
        treePanel.setTree(jtree);
        treePanel.setColourBy("residual");
    } else {
        treePanel.setTree(null);
        rootToTipChart.removeAllPlots();
        sb.append("No trees loaded");
    }
    textArea.setText(sb.toString());
    statisticsModel.fireTableStructureChanged();
    repaint();
}
Also used : Variate(dr.stats.Variate) Node(jebl.evolution.graphs.Node) Taxon(jebl.evolution.taxa.Taxon) Regression(dr.stats.Regression) RootedTree(jebl.evolution.trees.RootedTree) NumberFormatter(dr.util.NumberFormatter)

Example 9 with NumberFormatter

use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.

the class TreeTraceAnalysis method report.

/**
 * @param minCladeProbability clades with at least this posterior probability will be included in report.
 * @throws IOException if general I/O error occurs
 */
public void report(double minCladeProbability, double credSetProbability, int minNT) throws IOException {
    System.err.println("making report");
    final int fieldWidth = 14;
    NumberFormatter formatter = new NumberFormatter(6);
    formatter.setPadding(true);
    formatter.setFieldWidth(fieldWidth);
    final int nTreeSet = treeSet.size();
    int totalTrees = treeSet.getSumFrequency();
    System.out.println();
    System.out.println("burnIn=" + burnin);
    System.out.println("total trees used =" + totalTrees);
    System.out.println();
    System.out.println((Math.round(credSetProbability * 100.0)) + "% credible set (" + nTreeSet + " unique trees, " + totalTrees + " total):");
    System.out.println("Count\tPercent\tTree");
    int credSet = (int) (credSetProbability * totalTrees);
    int sumFreq = 0;
    int skipped = 0;
    NumberFormatter nf = new NumberFormatter(8);
    for (int i = 0; i < nTreeSet; i++) {
        final int freq = treeSet.getFrequency(i);
        boolean show = true;
        if (minNT > 0 && freq <= minNT) {
            show = false;
            skipped += 1;
        }
        final double prop = ((double) freq) / totalTrees;
        if (show) {
            System.out.print(freq);
            System.out.print("\t" + nf.formatDecimal(prop * 100.0, 2) + "%");
        }
        sumFreq += freq;
        final double sumProp = ((double) sumFreq) / totalTrees;
        if (show) {
            System.out.print("\t" + nf.formatDecimal(sumProp * 100.0, 2) + "%");
            String newickTree = treeSet.get(i);
            if (freq > 100) {
                // calculate conditional average node heights
                Tree meanTree = analyzeTree(newickTree);
                System.out.println("\t" + TreeUtils.newick(meanTree));
            } else {
                System.out.println("\t" + newickTree);
            }
        }
        if (sumFreq >= credSet) {
            if (skipped > 0) {
                System.out.println();
                System.out.println("... (" + skipped + ") trees.");
            }
            System.out.println();
            System.out.println("95% credible set has " + (i + 1) + " trees.");
            break;
        }
    }
    System.out.println();
    System.out.println(Math.round(minCladeProbability * 100.0) + "%-rule clades (" + cladeSet.size() + " unique clades):");
    final int nCladeSet = cladeSet.size();
    for (int i = 0; i < nCladeSet; i++) {
        final int freq = cladeSet.getFrequency(i);
        final double prop = ((double) freq) / totalTrees;
        if (prop >= minCladeProbability) {
            System.out.print(freq);
            System.out.print("\t" + nf.formatDecimal(prop * 100.0, 2) + "%");
            System.out.print("\t" + cladeSet.getMeanNodeHeight(i));
            System.out.println("\t" + cladeSet.getClade(i));
        }
    }
    System.out.flush();
    System.out.println("Clade credible sets:");
    int fiveCredSet = (5 * totalTrees) / 100;
    int halfCredSet = (50 * totalTrees) / 100;
    sumFreq = 0;
    assert nTreeSet == treeSet.size();
    final CladeSet tempCladeSet = new CladeSet();
    for (int nt = 0; nt < nTreeSet; nt++) {
        sumFreq += treeSet.getFrequency(nt);
        String newickTree = treeSet.get(nt);
        NewickImporter importer = new NewickImporter(new StringReader(newickTree));
        try {
            Tree tree = importer.importNextTree();
            tempCladeSet.add(tree);
        } catch (Importer.ImportException e) {
            System.err.println("Err");
        }
        if (sumFreq >= fiveCredSet) {
            System.out.println();
            System.out.println("5% credible set has " + tempCladeSet.getCladeCount() + " clades.");
            // don't do it more than once
            fiveCredSet = totalTrees + 1;
        }
        if (sumFreq >= halfCredSet) {
            System.out.println();
            System.out.println("50% credible set has " + tempCladeSet.getCladeCount() + " clades.");
            // don't do it more than once
            halfCredSet = totalTrees + 1;
        }
    }
    System.out.flush();
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) StringReader(java.io.StringReader) NumberFormatter(dr.util.NumberFormatter) NewickImporter(dr.evolution.io.NewickImporter) Importer(dr.evolution.io.Importer)

Example 10 with NumberFormatter

use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.

the class MCMCMC method finish.

/**
 * cleans up when the chain finishes (possibly early).
 */
private void finish() {
    NumberFormatter formatter = new NumberFormatter(8);
    MCLogger[] loggers = mcLoggers[coldChain];
    for (MCLogger logger : loggers) {
        logger.log(currentState);
        logger.stopLogging();
    }
    System.out.println();
    System.out.println("Time taken: " + timer.toString());
    if (showOperatorAnalysis) {
        System.out.println();
        System.out.println("Operator analysis");
        System.out.println(formatter.formatToFieldWidth("Operator", 30) + formatter.formatToFieldWidth("", 8) + formatter.formatToFieldWidth("Pr(accept)", 11) + " Performance suggestion");
        OperatorAnalysisPrinter.showOperatorAnalysis(System.out, schedules[coldChain], mcmcOptions.useAdaptation());
        System.out.println();
    }
}
Also used : MCLogger(dr.inference.loggers.MCLogger) NumberFormatter(dr.util.NumberFormatter)

Aggregations

NumberFormatter (dr.util.NumberFormatter)14 FlexibleTree (dr.evolution.tree.FlexibleTree)2 Tree (dr.evolution.tree.Tree)2 MCLogger (dr.inference.loggers.MCLogger)2 Regression (dr.stats.Regression)2 Variate (dr.stats.Variate)2 Node (jebl.evolution.graphs.Node)2 Taxon (jebl.evolution.taxa.Taxon)2 RootedTree (jebl.evolution.trees.RootedTree)2 Importer (dr.evolution.io.Importer)1 NewickImporter (dr.evolution.io.NewickImporter)1 Taxa (dr.evolution.util.Taxa)1 Taxon (dr.evolution.util.Taxon)1 BirthDeathGernhard08Model (dr.evomodel.speciation.BirthDeathGernhard08Model)1 SpeciationLikelihood (dr.evomodel.speciation.SpeciationLikelihood)1 SpeciationModel (dr.evomodel.speciation.SpeciationModel)1 BeagleTreeLikelihood (dr.evomodel.treelikelihood.BeagleTreeLikelihood)1 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)1 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)1 MCMC (dr.inference.mcmc.MCMC)1