本文整理汇总了Java中beast.evolution.tree.coalescent.PopulationFunction类的典型用法代码示例。如果您正苦于以下问题:Java PopulationFunction类的具体用法?Java PopulationFunction怎么用?Java PopulationFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PopulationFunction类属于beast.evolution.tree.coalescent包,在下文中一共展示了PopulationFunction类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simulateCoalescent
import beast.evolution.tree.coalescent.PopulationFunction; //导入依赖的package包/类
/**
* @param nodes
* @param demographic
* @return the root node of the given array of nodes after simulation of the
* coalescent under the given demographic model.
* @throws beast.evolution.tree.RandomTree.ConstraintViolatedException
*/
public Node simulateCoalescent(boolean isStronglyMonophyletic, final List<Node> nodes, final PopulationFunction demographic) throws ConstraintViolatedException {
// sanity check - disjoint trees
// if( ! Tree.Utils.allDisjoint(nodes) ) {
// throw new RuntimeException("non disjoint trees");
// }
if (nodes.size() == 0) {
throw new IllegalArgumentException("empty nodes set");
}
for (int attempts = 0; attempts < 1000; ++attempts) {
final List<Node> rootNode = simulateCoalescent(isStronglyMonophyletic, nodes, demographic, 0.0, Double.POSITIVE_INFINITY);
if (rootNode.size() == 1) {
return rootNode.get(0);
}
}
throw new RuntimeException("failed to merge trees after 1000 tries!");
}
示例2: simulateCoalescentWithMax
import beast.evolution.tree.coalescent.PopulationFunction; //导入依赖的package包/类
@Override
public Node simulateCoalescentWithMax(List<Node> nodes, PopulationFunction demographic, final double maxHeight) {
// sanity check - disjoint trees
// if( ! Tree.Utils.allDisjoint(nodes) ) {
// throw new RuntimeException("non disjoint trees");
// }
if (nodes.size() == 0) {
throw new IllegalArgumentException("empty nodes set");
}
final double lowestHeight = speciesTreeInput.get().getRoot().getHeight();
for (int attempts = 0; attempts < 1000; ++attempts) {
try {
final List<Node> rootNode = simulateCoalescent(nodes, demographic, lowestHeight, maxHeight);
if (rootNode.size() == 1) {
return rootNode.get(0);
}
} catch (ConstraintViolatedException e) {
// TODO: handle exception
}
}
throw new RuntimeException("failed to merge trees after 1000 tries!");
}
示例3: simulateCoalescentWithMax
import beast.evolution.tree.coalescent.PopulationFunction; //导入依赖的package包/类
/**
* @param nodes
* @param demographic
* @return the root node of the given array of nodes after simulation of the
* coalescent under the given demographic model.
* @throws beast.evolution.tree.RandomTree.ConstraintViolatedException
*/
public Node simulateCoalescentWithMax(final List<Node> nodes, final PopulationFunction demographic,
final double maxHeight) throws ConstraintViolatedException {
// sanity check - disjoint trees
// if( ! Tree.Utils.allDisjoint(nodes) ) {
// throw new RuntimeException("non disjoint trees");
// }
if (nodes.size() == 0) {
throw new IllegalArgumentException("empty nodes set");
}
for (int attempts = 0; attempts < 1000; ++attempts) {
final List<Node> rootNode = simulateCoalescent(nodes, demographic, 0.0, maxHeight);
if (rootNode.size() == 1) {
return rootNode.get(0);
}
}
if( Double.isFinite(maxHeight) ){
double h = -1;
for( Node n : nodeList ) {
h = Math.max(h, n.getHeight());
}
assert h < maxHeight;
double dt = (maxHeight - h)/ (nodeList.size() + 1);
while (nodeList.size() > 1) {
int k = nodeList.size() - 1;
final Node left = nodeList.remove(k);
final Node right = nodeList.get(k-1);
final Node newNode = newNode();
newNode.setNr(nextNodeNr++); // multiple tries may generate an excess of nodes assert(nextNodeNr <= nrOfTaxa*2-1);
newNode.setHeight(h + dt);
newNode.setLeft(left);
left.setParent(newNode);
newNode.setRight(right);
right.setParent(newNode);
nodeList.set(k-1, newNode);
}
assert (nodeList.size() == 1);
return nodeList.get(0);
}
throw new RuntimeException("failed to merge trees after 1000 tries!");
}
示例4: simulateCoalescent
import beast.evolution.tree.coalescent.PopulationFunction; //导入依赖的package包/类
public List<Node> simulateCoalescent(final List<Node> nodes, final PopulationFunction demographic, double currentHeight,
final double maxHeight) throws ConstraintViolatedException {
// If only one node, return it
// continuing results in an infinite loop
if (nodes.size() == 1)
return nodes;
final double[] heights = new double[nodes.size()];
for (int i = 0; i < nodes.size(); i++) {
heights[i] = nodes.get(i).getHeight();
}
final int[] indices = new int[nodes.size()];
HeapSort.sort(heights, indices);
// node list
nodeList.clear();
activeNodeCount = 0;
for (int i = 0; i < nodes.size(); i++) {
nodeList.add(nodes.get(indices[i]));
}
setCurrentHeight(currentHeight);
// get at least two tips
while (getActiveNodeCount() < 2) {
currentHeight = getMinimumInactiveHeight();
setCurrentHeight(currentHeight);
}
// simulate coalescent events
double nextCoalescentHeight = currentHeight
+ PopulationFunction.Utils.getSimulatedInterval(demographic, getActiveNodeCount(), currentHeight);
// while (nextCoalescentHeight < maxHeight && (getNodeCount() > 1)) {
while (nextCoalescentHeight < maxHeight && (nodeList.size() > 1)) {
if (nextCoalescentHeight >= getMinimumInactiveHeight()) {
currentHeight = getMinimumInactiveHeight();
setCurrentHeight(currentHeight);
} else {
currentHeight = coalesceTwoActiveNodes(currentHeight, nextCoalescentHeight);
}
// if (getNodeCount() > 1) {
if (nodeList.size() > 1) {
// get at least two tips
while (getActiveNodeCount() < 2) {
currentHeight = getMinimumInactiveHeight();
setCurrentHeight(currentHeight);
}
// nextCoalescentHeight = currentHeight +
// DemographicFunction.Utils.getMedianInterval(demographic,
// getActiveNodeCount(), currentHeight);
nextCoalescentHeight = currentHeight
+ PopulationFunction.Utils.getSimulatedInterval(demographic, getActiveNodeCount(),
currentHeight);
}
}
return nodeList;
}