use of dr.util.ComparableDouble in project beast-mcmc by beast-dev.
the class GaussianProcessSkytrackTreeOperator method collectAllTimes.
private static void collectAllTimes(Tree tree, NodeRef top, NodeRef[] excludeBelow, ArrayList<ComparableDouble> times, ArrayList<Integer> childs) {
times.add(new ComparableDouble(tree.getNodeHeight(top)));
childs.add(tree.getChildCount(top));
for (int i = 0; i < tree.getChildCount(top); i++) {
NodeRef child = tree.getChild(top, i);
if (excludeBelow == null) {
collectAllTimes(tree, child, excludeBelow, times, childs);
} else {
// check if this subtree is included in the coalescent density
boolean include = true;
for (NodeRef anExcludeBelow : excludeBelow) {
if (anExcludeBelow.getNumber() == child.getNumber()) {
include = false;
break;
}
}
if (include)
collectAllTimes(tree, child, excludeBelow, times, childs);
}
}
}
use of dr.util.ComparableDouble in project beast-mcmc by beast-dev.
the class VeryOldCoalescentLikelihood method collectAllTimes.
/**
* extract coalescent times and tip information into ArrayList times from tree.
*
* @param node the node to start from
* @param excludeBelow an optional array of nodes to exclude (corresponding subtrees) from density.
*/
private static void collectAllTimes(Tree tree, NodeRef node, NodeRef[] excludeBelow, ArrayList times, ArrayList<Integer> childs) {
times.add(new ComparableDouble(tree.getNodeHeight(node)));
childs.add(tree.getChildCount(node));
for (int i = 0; i < tree.getChildCount(node); i++) {
NodeRef child = tree.getChild(node, i);
if (excludeBelow == null) {
collectAllTimes(tree, child, excludeBelow, times, childs);
} else {
// check if this subtree is included in the coalescent density
boolean include = true;
for (NodeRef anExcludeBelow : excludeBelow) {
if (anExcludeBelow.getNumber() == child.getNumber()) {
include = false;
break;
}
}
if (include)
collectAllTimes(tree, child, excludeBelow, times, childs);
}
}
}
use of dr.util.ComparableDouble in project beast-mcmc by beast-dev.
the class VeryOldCoalescentLikelihood method setupIntervals.
/**
* Recalculates all the intervals from the tree model.
*/
protected final void setupIntervals() {
double MULTIFURCATION_LIMIT = 1e-9;
ArrayList times = new ArrayList();
ArrayList<Integer> childs = new ArrayList<Integer>();
collectAllTimes(tree, getMRCAOfCoalescent(tree), getExcludedMRCAs(tree), times, childs);
int[] indices = new int[times.size()];
HeapSort.sort(times, indices);
int maxIntervalCount = tree.getNodeCount();
if (intervals == null) {
intervals = new double[maxIntervalCount];
lineageCounts = new int[maxIntervalCount];
storedIntervals = new double[maxIntervalCount];
storedLineageCounts = new int[maxIntervalCount];
}
// start is the time of the first tip
double start = ((ComparableDouble) times.get(indices[0])).doubleValue();
int numLines = 0;
int i = 0;
intervalCount = 0;
while (i < times.size()) {
int lineagesRemoved = 0;
int lineagesAdded = 0;
double finish = ((ComparableDouble) times.get(indices[i])).doubleValue();
double next = finish;
while (Math.abs(next - finish) < MULTIFURCATION_LIMIT) {
int children = childs.get(indices[i]);
if (children == 0) {
lineagesAdded += 1;
} else {
lineagesRemoved += (children - 1);
}
i += 1;
if (i < times.size()) {
next = ((ComparableDouble) times.get(indices[i])).doubleValue();
} else
break;
}
//System.out.println("time = " + finish + " removed = " + lineagesRemoved + " added = " + lineagesAdded);
if (lineagesAdded > 0) {
if (intervalCount > 0 || ((finish - start) > MULTIFURCATION_LIMIT)) {
intervals[intervalCount] = finish - start;
lineageCounts[intervalCount] = numLines;
intervalCount += 1;
}
start = finish;
}
// add sample event
numLines += lineagesAdded;
if (lineagesRemoved > 0) {
intervals[intervalCount] = finish - start;
lineageCounts[intervalCount] = numLines;
intervalCount += 1;
start = finish;
}
// coalescent event
numLines -= lineagesRemoved;
}
intervalsKnown = true;
}
use of dr.util.ComparableDouble in project beast-mcmc by beast-dev.
the class OldAbstractCoalescentLikelihood method collectAllTimes.
/**
* Extract coalescent times and tip information into ArrayList times from tree.
* Upon return times contain the time of each node in the subtree below top, and at the corrosponding index
* of childs is the descendent count for that time.
*
* @param top the node to start from
* @param excludeBelow an optional array of nodes to exclude (corresponding subtrees) from density.
* @param tree given tree
* @param times array to fill with times
* @param childs array to fill with descendents count
*/
private static void collectAllTimes(Tree tree, NodeRef top, NodeRef[] excludeBelow, ArrayList<ComparableDouble> times, ArrayList<Integer> childs) {
times.add(new ComparableDouble(tree.getNodeHeight(top)));
childs.add(tree.getChildCount(top));
for (int i = 0; i < tree.getChildCount(top); i++) {
NodeRef child = tree.getChild(top, i);
if (excludeBelow == null) {
collectAllTimes(tree, child, excludeBelow, times, childs);
} else {
// check if this subtree is included in the coalescent density
boolean include = true;
for (NodeRef anExcludeBelow : excludeBelow) {
if (anExcludeBelow.getNumber() == child.getNumber()) {
include = false;
break;
}
}
if (include)
collectAllTimes(tree, child, excludeBelow, times, childs);
}
}
}
Aggregations