本文整理汇总了Java中beast.evolution.tree.Node.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getHeight方法的具体用法?Java Node.getHeight怎么用?Java Node.getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.evolution.tree.Node
的用法示例。
在下文中一共展示了Node.getHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConstraintNodes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static List<Node> getConstraintNodes (Tree tree, double minConstraintHeight) {
List<Node> constraintNodes = new ArrayList<Node>();
List<Node> possibleConstraintNodes = new ArrayList<Node>();
for (Node n : tree.getNodesAsArray()) {
if (n.getHeight() < minConstraintHeight) {
continue;
}
List<Node> c2Children = n.getAllChildNodes();
for (Node c1 : possibleConstraintNodes) {
List<Node> c1Children = c1.getAllChildNodes();
if (Collections.disjoint(c1Children, c2Children)) {
constraintNodes.add(n);
constraintNodes.add(c1);
break;
}
}
if (!constraintNodes.isEmpty()) {
break;
}
possibleConstraintNodes.add(n);
}
return constraintNodes;
}
示例2: fillNodes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void fillNodes() {
// must be done before any changes are made to the gene or species trees
Node childNode = cNode;
movedNodes = new ArrayList<>();
graftNodes = new ArrayList<>();
czBranchCount = 0;
while (childNode != zNode) {
czBranchCount++;
final Node parentNode = childNode.getParent();
final double childNodeHeight = childNode.getHeight();
final double parentNodeHeight = parentNode.getHeight();
final List<SortedMap<Node, Node>> perBranchMovedNodes = getMovedPairs(childNodeHeight, parentNodeHeight);
final SetMultimap<Integer, Node> perBranchGraftNodes = getGraftBranches(childNode);
movedNodes.add(0, perBranchMovedNodes); // needs to be added in reverse order
graftNodes.add(0, perBranchGraftNodes); // because nodes must be grafted oldest to youngest
childNode = parentNode;
}
}
示例3: compare
import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public int compare(Node nodeA, Node nodeB) {
final double heightA = nodeA.getHeight();
final double heightB = nodeB.getHeight();
if (heightA == heightB) {
final int depthA = calculateNodeDepth(nodeA);
final int depthB = calculateNodeDepth(nodeB);
if (depthA == depthB) {
final int nodeNumberA = nodeA.getNr();
final int nodeNumberB = nodeB.getNr();
if (nodeNumberA == nodeNumberB) {
return 0;
}
return nodeNumberA > nodeNumberB ? greaterThan : lessThan;
}
return depthA > depthB ? greaterThan : lessThan;
}
return heightA > heightB ? greaterThan : lessThan;
}
示例4: getCoalescentTimes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
public double[] getCoalescentTimes(int nodeI) {
if (needsUpdate) update();
final Node speciesNode = spTree.getNode(nodeI);
final Node parentNode = speciesNode.getParent();
final double speciesEndTime = speciesNode.getHeight();
final double speciesStartTime = (parentNode == null) ? Double.POSITIVE_INFINITY : parentNode.getHeight();
final int branchEventCount = coalescentCounts[nodeI];
final double[] branchCoalescentTimes = new double[branchEventCount + 2];
branchCoalescentTimes[0] = speciesEndTime;
branchCoalescentTimes[branchEventCount + 1] = speciesStartTime;
System.arraycopy(coalescentTimes, nodeI * blocksize, branchCoalescentTimes, 1, branchEventCount);
Arrays.sort(branchCoalescentTimes);
return branchCoalescentTimes;
}
示例5: recurseLength
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static double recurseLength(final Node treeNode, final double parentHeight) {
if (treeNode.isLeaf()) {
return parentHeight;
} else {
double subtreeLength = 0.0;
final double nodeHeight = treeNode.getHeight();
subtreeLength += parentHeight - nodeHeight;
final double leftChildLength = recurseLength(treeNode.getLeft(), nodeHeight);
final double rightChildLength = recurseLength(treeNode.getRight(), nodeHeight);
subtreeLength += leftChildLength;
subtreeLength += rightChildLength;
return subtreeLength;
}
}
示例6: recurseBranchRates
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* This is a recursive function that does the work of
* calculating the unscaled branch rates across the tree
* taking into account the indicator variables.
*
* @param node the node
* @param rate the rate of the parent node
*/
private void recurseBranchRates(Node node, double parentHeight, double rate, Boolean[] indicators, Double[] branchRates) {
final int nodeNumber = node.getNr();
final double nodeHeight = node.getHeight();
// not the root, and indicator is "on"
if (nodeNumber < rootNodeNumber && indicators[nodeNumber]) {
rate = branchRates[nodeNumber];
}
double branchLength = parentHeight - nodeHeight;
strictRatesTotal += branchLength;
relaxedRatesTotal += branchLength * rate;
ratesArray[nodeNumber] = rate;
if (!node.isLeaf()) {
recurseBranchRates(node.getLeft(), nodeHeight, rate, indicators, branchRates);
recurseBranchRates(node.getRight(), nodeHeight, rate, indicators, branchRates);
}
}
示例7: update
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void update() {
final Boolean[] indicators = indicatorsInput.get().getValues();
final Double[] rates = branchRatesInput.get().getValues();
final Node treeRoot = treeInput.get().getRoot();
final double treeHeight = treeRoot.getHeight();
double estimatedMean;
final RealParameter estimatedMeanParameter = meanRateInput.get();
if (estimatedMeanParameter == null) {
estimatedMean = 1.0;
} else {
estimatedMean = estimatedMeanParameter.getValue();
}
ratesArray[rootNodeNumber] = estimatedMean;
strictRatesTotal = 0.0;
relaxedRatesTotal = 0.0;
recurseBranchRates(treeRoot, treeHeight, 1.0, indicators, rates);
// normalize the weighted average of branch rates to equal the mean rate parameter
double scaleFactor = estimatedMean * strictRatesTotal / relaxedRatesTotal;
for (int i = 0; i < rootNodeNumber; i++) {
ratesArray[i] = ratesArray[i] * scaleFactor;
}
}
示例8: intersectingEdges
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private int intersectingEdges(Node node, double height, List<Node> directChildren) {
final Node parent = node.getParent();
if (parent.getHeight() < height) return 0;
if (node.getHeight() < height) {
if (directChildren != null) directChildren.add(node);
return 1;
}
if (node.isLeaf()) {
// TODO: verify that this makes sense
return 0;
} else {
final int count = intersectingEdges(node.getLeft(), height, directChildren) +
intersectingEdges(node.getRight(), height, directChildren);
return count;
}
}
示例9: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public double proposal() {
Tree tree = treeInput.get(this);
// randomly select leaf node
int i = Randomizer.nextInt(taxonIndices.length);
Node node = tree.getNode(taxonIndices[i]);
double upper = node.getParent().getHeight();
//double lower = 0.0;
//final double newValue = (Randomizer.nextDouble() * (upper -lower)) + lower;
// scale node
double scale = (scaleFactor + (Randomizer.nextDouble() * ((1.0 / scaleFactor) - scaleFactor)));
final double newValue = node.getHeight() * scale;
// check the tree does not get negative branch lengths
if (newValue > upper) {
return Double.NEGATIVE_INFINITY;
}
node.setHeight(newValue);
return -Math.log(scale);
}
示例10: calculateYuleLikelihood
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static double calculateYuleLikelihood(final TreeInterface tree, final double lam) {
final int taxonCount = tree.getLeafNodeCount();
// add all lambda multipliers here
// No normalization at the moment. for n! use logGamma(taxonCount + 1);
double logL = (taxonCount - 1) * Math.log(lam);
final Node[] nodes = tree.getNodesAsArray();
for (int i = taxonCount; i < nodes.length; i++) {
final Node node = nodes[i];
assert (!node.isLeaf());
final double height = node.getHeight();
final double mrh = -lam * height;
logL += mrh + (node.isRoot() ? mrh : 0);
}
return logL;
}
示例11: log
import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public void log(final int sample, final PrintStream out) {
out.print(getCurrentLogP() + "\t");
if (calcCalibrations) {
final TreeInterface tree = treeInput.get();
for (int k = 0; k < orderedCalibrations.length; ++k) {
final CalibrationPoint cal = orderedCalibrations[k];
Node c;
final int[] taxk = xclades[k];
if (taxk.length > 1) {
// find MRCA of taxa
c = getCommonAncestor(tree, taxk);
} else {
c = tree.getNode(taxk[0]);
}
if (cal.forParent()) {
c = c.getParent();
}
final double h = c.getHeight();
out.print(h + "\t");
}
}
}
示例12: calcLogNodeProbability
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* contribution of a single node to the log likelihood
* r = relative birth rate (birth rate - death rate)
* rho = rho parameter in Gernhard 2008 birth death model
* a = death rate relative to birth rate
*
* @param node
* @param r
* @param rho
* @param a
* @param taxonCount
* @return
*/
protected double calcLogNodeProbability(Node node, double r, double rho, double a, int taxonCount) {
final double height = node.getHeight();
if (conditionalOnRoot && node.isRoot()) {
return (taxonCount - 2) * calcLogConditioningTerm(height, r, rho, a);
}
final double mrh = -r * height;
final double z = Math.log(rho + ((1 - rho) - a) * Math.exp(mrh));
double l = -2 * z + mrh;
if (!conditionalOnOrigin && !conditionalOnRoot && node.isRoot())
l += mrh - z;
return l;
}
示例13: collectTimes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* extract coalescent times and tip information into array times from beast.tree.
*
* @param tree the beast.tree
* @param times the times of the nodes in the beast.tree
* @param childCounts the number of children of each node
*/
protected static void collectTimes(Tree tree, double[] times, int[] childCounts) {
Node[] nodes = tree.getNodesAsArray();
for (int i = 0; i < nodes.length; i++) {
Node node = nodes[i];
times[i] = node.getHeight();
childCounts[i] = node.isLeaf() ? 0 : 2;
}
}
示例14: getAliveNodes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
public ArrayList<Node> getAliveNodes(Tree base, Double t) {
ArrayList<Node> aliveNodes = new ArrayList<Node>();
Node root = base.getRoot();
for (Node child : root.getChildren()) {
if (child.getHeight() <= t) {
aliveNodes.add(child);
} else {
aliveNodes.addAll(aliveNodes(child, t));
}
}
return aliveNodes;
}
示例15: aliveNodes
import beast.evolution.tree.Node; //导入方法依赖的package包/类
protected ArrayList<Node> aliveNodes(Node curr, Double t) {
ArrayList<Node> aN = new ArrayList<Node>();
for (Node child : curr.getChildren()) {
if (child.getHeight() <= t) {
aN.add(child);
} else {
aN.addAll(aliveNodes(child, t));
}
}
return aN;
}