当前位置: 首页>>代码示例>>Java>>正文


Java Node.isRoot方法代码示例

本文整理汇总了Java中beast.evolution.tree.Node.isRoot方法的典型用法代码示例。如果您正苦于以下问题:Java Node.isRoot方法的具体用法?Java Node.isRoot怎么用?Java Node.isRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beast.evolution.tree.Node的用法示例。


在下文中一共展示了Node.isRoot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: branchLogP

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public double branchLogP(int speciesTreeNodeNumber, Node speciesTreeNode, double ploidy, double[] branchCoalescentTimes, int branchLineageCount, int branchEventCount) {
    final RealParameter tipPopSizes = tipPopSizesInput.get();
    final RealParameter topPopSizes = topPopSizesInput.get();

    double branchTipPopSize;
    if (speciesTreeNode.isLeaf()) {
        branchTipPopSize = tipPopSizes.getValue(speciesTreeNodeNumber);
    } else {
        final int leftChildTopI = speciesTreeNode.getLeft().getNr();
        final int rightChildTopI = speciesTreeNode.getRight().getNr();
        branchTipPopSize = topPopSizes.getValue(leftChildTopI) + topPopSizes.getValue(rightChildTopI);
    }

    if (speciesTreeNode.isRoot()) {
        return ConstantPopulations.constantLogP(branchTipPopSize, ploidy, branchCoalescentTimes, branchLineageCount, branchEventCount);
    } else {
        final int speciesTopI = speciesTreeNodeNumber;
        final double branchTopPopSize = topPopSizes.getValue(speciesTopI);
        return linearLogP(branchTopPopSize, branchTipPopSize, ploidy, branchCoalescentTimes, branchLineageCount, branchEventCount);
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:23,代码来源:LinearWithConstantRoot.java

示例2: serialize

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public void serialize(Node speciesTreeNode, StringBuffer buf, DecimalFormat df) {
    final RealParameter tipPopSizes = tipPopSizesInput.get();
    final RealParameter topPopSizes = topPopSizesInput.get();
    final int speciesTreeNodeNumber = speciesTreeNode.getNr();

    double branchTipPopSize;
    if (speciesTreeNode.isLeaf()) {
        branchTipPopSize = tipPopSizes.getValue(speciesTreeNodeNumber);
    } else {
        final int leftChildTopI = speciesTreeNode.getLeft().getNr();
        final int rightChildTopI = speciesTreeNode.getRight().getNr();
        branchTipPopSize = topPopSizes.getValue(leftChildTopI) + topPopSizes.getValue(rightChildTopI);
    }

    final double branchTopPopSize = (speciesTreeNode.isRoot()) ? branchTipPopSize : topPopSizes.getValue(speciesTreeNode.getNr());

    if (df == null) buf.append("dmv={" + branchTopPopSize + "," + branchTipPopSize + "}");
    else buf.append("dmv={" + df.format(branchTopPopSize) + "," + df.format(branchTipPopSize) + "}");
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:21,代码来源:LinearWithConstantRoot.java

示例3: calculateUnscaledBranchRates

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 calculateUnscaledBranchRates(Node node, double rate, BooleanParameter indicators, RealParameter rates) {

    int nodeNumber = getNr(node);

    if (!node.isRoot()) {
        if (indicators.getValue(nodeNumber)) {
            if (ratesAreMultipliers) {
                rate *= rates.getValue(nodeNumber);
            } else {
                rate = rates.getValue(nodeNumber);
            }
        }
    }
    unscaledBranchRates[nodeNumber] = rate;

    if (!node.isLeaf()) {
        calculateUnscaledBranchRates(node.getLeft(), rate, indicators, rates);
        calculateUnscaledBranchRates(node.getRight(), rate, indicators, rates);
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:29,代码来源:RandomLocalClockModel.java

示例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);

    // 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;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:29,代码来源:Uniform.java

示例5: 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;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:18,代码来源:CalibratedYuleModel.java

示例6: 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;

}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:31,代码来源:YuleModel.java

示例7: 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;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:17,代码来源:CalibratedBirthDeathModel.java

示例8: 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;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:30,代码来源:UniformForZeroBranchSATrees.java

示例9: 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;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:30,代码来源:SAUniform.java

示例10: calculateNodeDepth

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private int calculateNodeDepth(Node node) {
    if (node.isRoot()) {
        return 0;
    }

    return calculateNodeDepth(node.getParent()) - 1;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:8,代码来源:NodeHeightComparator.java

示例11: getRateForBranch

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public double getRateForBranch(Node node) {
       if (node.isRoot()) {
           // root has no rate
           return 1;
       }

  		if (recompute) {
  	        // this must be synchronized to avoid being called simultaneously by
  	        // two different likelihood threads
  	    	synchronized (this) {
   			prepare();
   			recompute = false;
   		}
   	}

       if (renormalize) {
           if (normalize) {
           	synchronized (this) {
           		computeFactor();
           	}
           }
           renormalize = false;
       }

       return getRawRate(node) * scaleFactor * meanRate.getValue();
   }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:28,代码来源:UCRelaxedClockModel.java

示例12: calculateBDLikelihood

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private double calculateBDLikelihood(final TreeInterface tree, final double r, final double a, final double rho) {
    if( a == 0 && rho == 1.0 ) {
        return calculateYuleLikelihood(tree, r);
    }

    final int taxonCount = tree.getLeafNodeCount();

    // add all lambda multipliers here
    double logL = lfactorials[taxonCount] + (taxonCount - 1) * Math.log(r * rho);
    final Node[] nodes = tree.getNodesAsArray();

    logL += taxonCount * Math.log(1 - a);

    for (int i = taxonCount; i < nodes.length; i++) {
        final Node node = nodes[i];                   assert (!node.isLeaf());
        final double height = node.getHeight();
        final double mrh = -r * height;
        final double z = Math.log(rho + ((1-rho) - a) * Math.exp(mrh));
        double l = -2 * z + mrh;
        if( node.isRoot() ) {
            l += mrh - z;
        }
        logL += l;
    }

    return logL;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:28,代码来源:CalibratedBirthDeathModel.java

示例13: getRateForBranch

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public double getRateForBranch(Node node) {
    synchronized (this){
        if (node.isRoot()) {
            // root has no rate
            return 1;
        }
        if (recompute) {
            prepare();
            recompute = false;
        }
        if (renormalize) {
            if (normalize) {
                computeFactor();
            }
            renormalize = false;
        }
    }

    int nodeNumber = node.getNr();

    if (nodeNumber == categories.getDimension()) {
        // root node has nr less than #categories, so use that nr
        nodeNumber = node.getTree().getRoot().getNr();
    }

    int rateCategory = categories.getValue(nodeNumber);

    return rates[rateCategory] * scaleFactor * meanRate.getValue();
}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:30,代码来源:SynchronizableUCRelaxedClock.java

示例14: computeFactor

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void computeFactor() {

        //scale mean rate to 1.0 or separate parameter

        double treeRate = 0.0;
        double treeTime = 0.0;

        for (int i = 0; i < tree.getNodeCount(); i++) {
            Node node = tree.getNode(i);
            if (!node.isRoot()) {
                int nodeNumber = node.getNr();
                if (nodeNumber == categories.getDimension()) {
                    // root node has nr less than #categories, so use that nr
                    nodeNumber = node.getTree().getRoot().getNr();
                }
                int rateCategory = categories.getValue(nodeNumber);
                treeRate += rates[rateCategory] * node.getLength();
                treeTime += node.getLength();

                //System.out.println("rates and time\t" + rates[rateCategory] + "\t" + node.getLength());
            }
        }
        //treeRate /= treeTime;

        scaleFactor = 1.0 / (treeRate / treeTime);


        //System.out.println("scaleFactor\t\t\t\t\t" + scaleFactor);
    }
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:30,代码来源:SynchronizableUCRelaxedClock.java

示例15: convertToFakeSATree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public static void convertToFakeSATree(Node node, int[] nextNr) {
    if (!node.isLeaf()) {
        convertToFakeSATree(node.getLeft(), nextNr);
        if (node.getRight() != null) {
            convertToFakeSATree(node.getRight(), nextNr);
        }
    }
    if (node.getChildCount() == 1) {
        Node parent = new Node();
        parent.setHeight(node.getHeight());
        Node child = node.getLeft();
        parent.setLeft(child);
        child.setParent(parent);
        node.removeChild(child);
        parent.setRight(node);
        parent.setNr(nextNr[0]);
        nextNr[0]++;
        if (!node.isRoot()) {
            Node grandparent = node.getParent();

            if (grandparent.getLeft().getNr() == node.getNr()) {
                grandparent.setLeft(parent);
            }  else {
                grandparent.setRight(parent);
            }
            parent.setParent(grandparent);
        }  else {
            node.getTree().setRoot(parent);
        }
        node.setParent(parent);
    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:33,代码来源:SampledAncestorTreeComparator.java


注:本文中的beast.evolution.tree.Node.isRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。