本文整理汇总了Java中beast.evolution.tree.Node.setHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Node.setHeight方法的具体用法?Java Node.setHeight怎么用?Java Node.setHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类beast.evolution.tree.Node
的用法示例。
在下文中一共展示了Node.setHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
// randomly select internal node
final int nodeCount = tree.getNodeCount();
// Abort if no non-root internal nodes
if (tree.getInternalNodeCount()==1)
return Double.NEGATIVE_INFINITY;
Node node;
do {
final int nodeNr = nodeCount / 2 + 1 + Randomizer.nextInt(nodeCount / 2);
node = tree.getNode(nodeNr);
} while (node.isRoot() || node.isLeaf());
final double upper = node.getParent().getHeight();
final double lower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (upper - lower)) + lower;
node.setHeight(newValue);
return 0.0;
}
示例2: lengthToHeight
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/** convert length to height
* and set ID of leafs
*/
private double lengthToHeight(Node node, double offSet) {
if (node.isLeaf()) {
node.setHeight(-offSet - node.getHeight());
node.setID(m_sLabels.get(node.getNr()));
return -node.getHeight();
} else {
double posY = offSet + node.getHeight();
double yMax = 0;
yMax = Math.max(yMax, lengthToHeight(node.getLeft(), posY));
if (node.getRight() != null) {
yMax = Math.max(yMax, lengthToHeight(node.getRight(), posY));
}
node.setHeight(-posY);
return yMax;
}
}
示例3: binarizeMultifurcation
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* Use zero-length edges to replace multifurcations with a sequence of bifurcations.
*
* @param node node representing multifurcation
*/
private void binarizeMultifurcation(Node node) {
if (node.getChildCount()>2) {
List<Node> children = new ArrayList<>(node.getChildren());
Node prevDummy = node;
for (int i=1; i<children.size()-1; i++) {
Node child = children.get(i);
Node dummyNode = newNode();
dummyNode.setNr(-1);
dummyNode.setHeight(0);
prevDummy.addChild(dummyNode);
node.removeChild(child);
dummyNode.addChild(child);
prevDummy = dummyNode;
}
node.removeChild(children.get(children.size()-1));
prevDummy.addChild(children.get(children.size()-1));
}
}
示例4: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
final int nNodeCount = tree.getNodeCount();
int leafNodeCount = tree.getLeafNodeCount();
//make sure that there is at least one non-fake and non-root internal node
int fakeNodeCount = ((ZeroBranchSATree)tree).getDirectAncestorNodeCount();
if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !((ZeroBranchSANode)tree.getRoot()).isFake())) {
return Double.NEGATIVE_INFINITY;
}
// randomly select internal node
Node node;
do {
node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
} while (node.isRoot() || ((ZeroBranchSANode)node).isFake());
final double fUpper = node.getParent().getHeight();
final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
node.setHeight(newValue);
return 0.0;
}
示例5: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* change the parameter and return the hastings ratio.
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
final Tree tree = treeInput.get(this);
final int nNodeCount = tree.getNodeCount();
int leafNodeCount = tree.getLeafNodeCount();
//make sure that there is at least one non-fake and non-root internal node
int fakeNodeCount = tree.getDirectAncestorNodeCount();
if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !tree.getRoot().isFake())) {
return Double.NEGATIVE_INFINITY;
}
// randomly select internal node
Node node;
do {
node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
} while (node.isRoot() || node.isFake());
final double fUpper = node.getParent().getHeight();
final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
node.setHeight(newValue);
return 0.0;
}
示例6: randomYuleTree
import beast.evolution.tree.Node; //导入方法依赖的package包/类
static Tree randomYuleTree (int nodes, double l) throws Exception {
Tree tr = new Tree();
ArrayList<Node> nodeList = new ArrayList<Node>();
double t = 0.0;
int label = 1;
for (int i = 0; i < nodes; i++) {
Node n = new Node();
n.setHeight(t);
n.setNr(label);
label++;
nodeList.add(n);
}
while (nodeList.size() > 1) {
t += Randomizer.nextExponential(nodeList.size()*l);
int p_1_index = Randomizer.nextInt(nodeList.size());
Node p1 = nodeList.remove(p_1_index);
int p_2_index = Randomizer.nextInt(nodeList.size());
Node p2 = nodeList.remove(p_2_index);
Node parent = new Node();
parent.setHeight(t);
parent.setNr(label);
label++;
p1.setParent(parent);
parent.addChild(p1);
p2.setParent(parent);
parent.addChild(p2);
nodeList.add(parent);
}
tr.setRoot(nodeList.get(0));
return new Tree(tr.toString());
}
示例7: randomYuleTree
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static Tree randomYuleTree (int nodes, double l) throws Exception {
Tree tr = new Tree();
ArrayList<Node> nodeList = new ArrayList<Node>();
double t = 0.0;
int label = 1;
for (int i = 0; i < nodes; i++) {
Node n = new Node();
n.setHeight(t);
n.setNr(label);
label++;
nodeList.add(n);
}
while (nodeList.size() > 1) {
t += Randomizer.nextExponential(nodeList.size()*l);
int p_1_index = Randomizer.nextInt(nodeList.size());
Node p1 = nodeList.remove(p_1_index);
int p_2_index = Randomizer.nextInt(nodeList.size());
Node p2 = nodeList.remove(p_2_index);
Node parent = new Node();
parent.setHeight(t);
parent.setNr(label);
label++;
p1.setParent(parent);
parent.addChild(p1);
p2.setParent(parent);
parent.addChild(p2);
nodeList.add(parent);
}
tr.setRoot(nodeList.get(0));
return new Tree(tr.toString());
}
示例8: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* override this for proposals,
*
* @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
*/
@Override
public double proposal() {
// always operate on the root node
final Node speciesTreeRoot = speciesTree.getRoot();
// don't bother if root node is a sampled ancestor
// TODO make it work
if (speciesTreeRoot.isFake()) return Double.NEGATIVE_INFINITY;
final double currentRootHeight = speciesTreeRoot.getHeight();
final double leftChildHeight = speciesTreeRoot.getLeft().getHeight();
final double rightChildHeight = speciesTreeRoot.getRight().getHeight();
final MinimumDouble tipwardFreedom = new MinimumDouble();
final SetMultimap<Integer, Node> connectingNodes = getConnectingNodes(speciesTreeRoot, tipwardFreedom);
tipwardFreedom.set(currentRootHeight - leftChildHeight);
tipwardFreedom.set(currentRootHeight - rightChildHeight);
waitingTime = tipwardFreedom.get() * waitingTimeScale;
// the youngest age the species tree root node can be (preserving topologies)
final double uniformShift = Randomizer.nextExponential(lambda) - tipwardFreedom.get();
speciesTreeRoot.setHeight(currentRootHeight + uniformShift);
for (Node geneTreeNode: connectingNodes.values()) {
geneTreeNode.setHeight(geneTreeNode.getHeight() + uniformShift);
}
// the log ratio of the density of the proposed over the current species tree root heights
final double fLogHastingsRatio = lambda * uniformShift;
return fLogHastingsRatio;
}
示例9: resetGeneTreeTipHeights
import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void resetGeneTreeTipHeights() {
final SpeciesTreeInterface speciesTree = speciesTreeInput.get();
final Map<String, Integer> tipNames = speciesTree.getTipNumberMap();
final List<Tree> geneTrees = genes.get();
for (final Tree gtree : geneTrees) {
final int leafNodeCount = gtree.getLeafNodeCount();
for (int geneLeafNr = 0; geneLeafNr < leafNodeCount; geneLeafNr++) {
final Node geneLeaf = gtree.getNode(geneLeafNr);
final int speciesLeafNr = tipNames.get(geneLeaf.getID());
final Node speciesLeaf = speciesTree.getNode(speciesLeafNr);
geneLeaf.setHeight(speciesLeaf.getHeight());
}
}
}
示例10: toNode
import beast.evolution.tree.Node; //导入方法依赖的package包/类
Node toNode() {
final Node node = newNode();
node.setHeight(m_fHeight);
if (m_left == null) {
node.setLeft(newNode());
node.getLeft().setNr(m_iLeftInstance);
node.getLeft().setID(taxaNames.get(m_iLeftInstance));
node.getLeft().setHeight(m_fHeight - m_fLeftLength);
if (m_right == null) {
node.setRight(newNode());
node.getRight().setNr(m_iRightInstance);
node.getRight().setID(taxaNames.get(m_iRightInstance));
node.getRight().setHeight(m_fHeight - m_fRightLength);
} else {
node.setRight(m_right.toNode());
}
} else {
node.setLeft(m_left.toNode());
if (m_right == null) {
node.setRight(newNode());
node.getRight().setNr(m_iRightInstance);
node.getRight().setID(taxaNames.get(m_iRightInstance));
node.getRight().setHeight(m_fHeight - m_fRightLength);
} else {
node.setRight(m_right.toNode());
}
}
if (node.getHeight() < node.getLeft().getHeight() + EPSILON) {
node.setHeight(node.getLeft().getHeight() + EPSILON);
}
if (node.getHeight() < node.getRight().getHeight() + EPSILON) {
node.setHeight(node.getRight().getHeight() + EPSILON);
}
node.getRight().setParent(node);
node.getLeft().setParent(node);
return node;
}
示例11: proposal
import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public double proposal() {
// randomly select leaf node
int i = Randomizer.nextInt(taxonIndices.length);
Node node = treeInput.get().getNode(taxonIndices[i]);
double value = node.getHeight();
double newValue = value;
if (useGaussian) {
newValue += Randomizer.nextGaussian() * windowSize;
} else {
newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
}
if (newValue > node.getParent().getHeight()) { // || newValue < 0.0) {
if (reflectValue) {
newValue = reflectValue(newValue, 0.0, node.getParent().getHeight());
} else {
return Double.NEGATIVE_INFINITY;
}
}
if (newValue == value) {
// this saves calculating the posterior
return Double.NEGATIVE_INFINITY;
}
node.setHeight(newValue);
return 0.0;
}
示例12: offsetHeight
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/** move y-position of a tree with offset f **/
public void offsetHeight(Node node, double f) {
if (!node.isLeaf()) {
offsetHeight(node.getLeft(), f);
if (node.getRight() != null) {
offsetHeight(node.getRight(), f);
}
}
node.setHeight(node.getHeight() + f);
}
示例13: convertLengthToHeight
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* Recursive method used to convert lengths to heights. Applied to the root,
* results in heights from 0 to -total_height_of_tree.
*
* @param node node of a clade to convert
* @param height Parent height.
* @return total height of clade
*/
private double convertLengthToHeight(final Node node, final double height) {
final double length = node.getHeight();
node.setHeight((height - length) * scaleInput.get());
if (node.isLeaf()) {
return node.getHeight();
} else {
double minChildHeight = Double.POSITIVE_INFINITY;
for (Node child : node.getChildren())
minChildHeight = Math.min(minChildHeight, convertLengthToHeight(child, height - length));
return minChildHeight;
}
}
示例14: offset
import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
* Method used by convertLengthToHeight(node) to remove negative offset from
* node heights that is produced by convertLengthToHeight(node, height).
*
* @param node node of clade to offset
* @param delta offset
*/
private void offset(final Node node, final double delta) {
node.setHeight(node.getHeight() + delta);
if (node.isLeaf()) {
if (node.getHeight() < thresholdInput.get()) {
node.setHeight(0);
}
}
for (Node child : node.getChildren())
offset(child, delta);
}
示例15: buildClusterer
import beast.evolution.tree.Node; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Node buildClusterer() {
final int taxonCount = taxaNames.size();
if (taxonCount == 1) {
// pathological case
final Node node = newNode();
node.setHeight(1);
node.setNr(0);
return node;
}
// use array of integer vectors to store cluster indices,
// starting with one cluster per instance
final List<Integer>[] clusterID = new ArrayList[taxonCount];
for (int i = 0; i < taxonCount; i++) {
clusterID[i] = new ArrayList<>();
clusterID[i].add(i);
}
// calculate distance matrix
final int clusters = taxonCount;
// used for keeping track of hierarchy
final NodeX[] clusterNodes = new NodeX[taxonCount];
if (linkType == Type.neighborjoining || linkType == Type.neighborjoining2) {
neighborJoining(clusters, clusterID, clusterNodes);
} else {
doLinkClustering(clusters, clusterID, clusterNodes);
}
// move all clusters in m_nClusterID array
// & collect hierarchy
for (int i = 0; i < taxonCount; i++) {
if (clusterID[i].size() > 0) {
return clusterNodes[i].toNode();
}
}
return null;
}