use of dr.evolution.io.TreeTrace in project beast-mcmc by beast-dev.
the class TreeTraceAnalysis method analyze.
/**
* Actually analyzes the trace given the burnin
*
* @param verbose if true then progress is logged to stdout
*/
void analyze(boolean verbose) {
if (verbose) {
if (traces.length > 1)
System.out.println("Combining " + traces.length + " traces.");
}
final Tree tree0 = getTree(0);
double[][] changed = new double[tree0.getNodeCount()][tree0.getNodeCount()];
double[] rateConditionalOnChange = new double[tree0.getNodeCount()];
boolean changesFound = false;
cladeSet = new CladeSet(tree0);
treeSet = new FrequencySet<String>();
treeSet.add(TreeUtils.uniqueNewick(tree0, tree0.getRoot()));
final int reportRate = 60;
for (TreeTrace trace : traces) {
final int treeCount = trace.getTreeCount(burnin * trace.getStepSize());
final double stepSize = treeCount / (double) reportRate;
int counter = 1;
if (verbose) {
System.out.println("Analyzing " + treeCount + " trees...");
System.out.println("0 25 50 75 100");
System.out.println("|--------------|--------------|--------------|--------------|");
System.out.print("*");
}
for (int i = 1; i < treeCount; i++) {
Tree tree = trace.getTree(i, burnin * trace.getStepSize());
for (int j = 0; j < tree.getNodeCount(); j++) {
if (tree.getNode(j) != tree.getRoot() && tree.getNodeAttribute(tree.getNode(j), "changed") != null) {
changesFound = true;
final Object o = tree.getNodeAttribute(tree.getNode(j), "changed");
if (o != null) {
boolean ch = getChanged(tree, j);
if (ch) {
rateConditionalOnChange[j] += (Double) tree.getNodeAttribute(tree.getNode(j), "rate");
}
for (int k = 0; k < tree.getNodeCount(); k++) {
if (tree.getNode(k) != tree.getRoot()) {
changed[j][k] += (ch && getChanged(tree, k)) ? 1 : 0;
}
}
}
}
}
cladeSet.add(tree);
treeSet.add(TreeUtils.uniqueNewick(tree, tree.getRoot()));
if (verbose && i >= (int) Math.round(counter * stepSize) && counter <= reportRate) {
System.out.print("*");
System.out.flush();
counter += 1;
}
}
if (verbose) {
System.out.println("*");
}
}
if (changesFound) {
for (int j = 0; j < tree0.getNodeCount(); j++) {
System.out.println(j + "\t" + rateConditionalOnChange[j]);
}
System.out.println();
for (int j = 0; j < tree0.getNodeCount(); j++) {
for (int k = 0; k < tree0.getNodeCount(); k++) {
System.out.print(changed[j][k] + "\t");
}
System.out.println();
}
}
}
use of dr.evolution.io.TreeTrace in project beast-mcmc by beast-dev.
the class TreeTraceAnalysis method getTree.
final Tree getTree(int index) {
int oldTreeCount = 0;
int newTreeCount = 0;
for (TreeTrace trace : traces) {
final int br = burnin * trace.getStepSize();
newTreeCount += trace.getTreeCount(br);
if (index < newTreeCount) {
return trace.getTree(index - oldTreeCount, br);
}
oldTreeCount = newTreeCount;
}
throw new RuntimeException("Couldn't find tree " + index);
}
use of dr.evolution.io.TreeTrace in project beast-mcmc by beast-dev.
the class WeightedMultiplicativeBinary method analyzeTrace.
/**
* Actually analyzes the trace given the burn-in. Each tree from the trace
* is read and the conditional clade frequencies incremented.
*
* @param verbose if true then progress is logged to stdout
*/
public void analyzeTrace(boolean verbose) {
if (verbose) {
if (traces.length > 1)
System.out.println("Combining " + traces.length + " traces.");
}
// get first tree to extract the taxon
Tree tree = getTree(0);
// read every tree from the trace
for (TreeTrace trace : traces) {
// do some output stuff
int treeCount = trace.getTreeCount(burnin * trace.getStepSize());
double stepSize = treeCount / 60.0;
int counter = 1;
if (verbose) {
System.out.println("Analyzing " + treeCount + " trees...");
System.out.println("0 25 50 75 100");
System.out.println("|--------------|--------------|--------------|--------------|");
System.out.print("*");
}
for (int i = 1; i < treeCount; i++) {
// get the next tree
tree = trace.getTree(i, burnin * trace.getStepSize());
// add the tree and its clades to the frequencies
addTree(tree);
// some more output stuff
if (i >= (int) Math.round(counter * stepSize) && counter <= 60) {
if (verbose) {
System.out.print("*");
System.out.flush();
}
counter += 1;
}
}
if (verbose) {
System.out.println("*");
}
}
}
use of dr.evolution.io.TreeTrace in project beast-mcmc by beast-dev.
the class WeightedMultiplicativeBinary method getTree.
/**
* get the i'th tree of the trace
*
* @param index
* @return the i'th tree of the trace
*/
public final Tree getTree(int index) {
int oldTreeCount = 0;
int newTreeCount = 0;
for (TreeTrace trace : traces) {
newTreeCount += trace.getTreeCount(burnin * trace.getStepSize());
if (index < newTreeCount) {
return trace.getTree(index - oldTreeCount, burnin * trace.getStepSize());
}
oldTreeCount = newTreeCount;
}
throw new RuntimeException("Couldn't find tree " + index);
}
use of dr.evolution.io.TreeTrace in project beast-mcmc by beast-dev.
the class ConditionalCladeFrequency method getTree.
/**
* get the i'th tree of the trace
*
* @param index
* @return the i'th tree of the trace
*/
public final Tree getTree(int index) {
int oldTreeCount = 0;
int newTreeCount = 0;
for (TreeTrace trace : traces) {
newTreeCount += trace.getTreeCount(burnin * trace.getStepSize());
if (index < newTreeCount) {
return trace.getTree(index - oldTreeCount, burnin * trace.getStepSize());
}
oldTreeCount = newTreeCount;
}
throw new RuntimeException("Couldn't find tree " + index);
}
Aggregations