Search in sources :

Example 6 with AncestralTaxonInTree

use of dr.evomodel.continuous.AncestralTaxonInTree in project beast-mcmc by beast-dev.

the class AncestralTraitTreeModel method recursiveSetupMrcaClamps.

private static void recursiveSetupMrcaClamps(Tree tree, NodeRef node, BitSet tips, Map<BitSet, AncestralTaxonInTree> clampList, Map<Integer, List<AncestralTaxonInTree>> nodeToClampMap) {
    if (tree.isExternal(node)) {
        tips.set(node.getNumber());
    } else {
        for (int i = 0; i < tree.getChildCount(node); i++) {
            NodeRef child = tree.getChild(node, i);
            BitSet childTips = new BitSet();
            recursiveSetupMrcaClamps(tree, child, childTips, clampList, nodeToClampMap);
            tips.or(childTips);
        }
        if (clampList.containsKey(tips)) {
            AncestralTaxonInTree partials = clampList.get(tips);
            partials.setNode(node);
            addAncestralTaxonToMap(nodeToClampMap, node.getNumber(), partials);
        }
    }
}
Also used : AncestralTaxonInTree(dr.evomodel.continuous.AncestralTaxonInTree)

Example 7 with AncestralTaxonInTree

use of dr.evomodel.continuous.AncestralTaxonInTree in project beast-mcmc by beast-dev.

the class AncestralTraitTreeModel method setupAncestralPathClamps.

// private void addAllAncestralNodeHeightParameterBelow(NodeRef node) {
// addAncestralNodeHeightParameter(node);
// for (int i = 0; i < treeModel.getChildCount(node); ++i) {
// addAllAncestralNodeHeightParameterBelow(treeModel.getChild(node, i));
// }
// }
private void setupAncestralPathClamps(Tree tree, Map<BitSet, AncestralTaxonInTree> clampList, Map<Integer, List<AncestralTaxonInTree>> nodeToClampMap) {
    hasAncestralPathTaxa = false;
    ancestralPathNodeHeightParameters.clear();
    for (int i = 0; i < tree.getExternalNodeCount(); ++i) {
        NodeRef node = tree.getExternalNode(i);
        BitSet tip = new BitSet();
        tip.set(node.getNumber());
        if (clampList.containsKey(tip)) {
            AncestralTaxonInTree partials = clampList.get(tip);
            partials.setTipNode(node);
            addAncestralNodeHeightParameter(node);
            double pathHeight = partials.getHeight();
            assert (pathHeight > 0.0);
            NodeRef parent = tree.getParent(node);
            double parentHeight = tree.getNodeHeight(parent);
            boolean isChild0 = tree.getChild(parent, 0) == node;
            while (parentHeight < pathHeight && parent != tree.getRoot()) {
                node = parent;
                addAncestralNodeHeightParameter(node);
                parent = tree.getParent(parent);
                parentHeight = tree.getNodeHeight(parent);
                isChild0 = tree.getChild(parent, 0) == node;
            }
            addAncestralNodeHeightParameter(parent);
            partials.setNode(parent, isChild0 ? 0 : 1);
            addAncestralTaxonToMap(nodeToClampMap, parent.getNumber(), partials);
            hasAncestralPathTaxa = true;
        }
    }
}
Also used : AncestralTaxonInTree(dr.evomodel.continuous.AncestralTaxonInTree)

Aggregations

AncestralTaxonInTree (dr.evomodel.continuous.AncestralTaxonInTree)7 NodeRef (dr.evolution.tree.NodeRef)2 FastMatrixParameter (dr.inference.model.FastMatrixParameter)2 Parameter (dr.inference.model.Parameter)2 MutableTreeModel (dr.evolution.tree.MutableTreeModel)1 TreeUtils (dr.evolution.tree.TreeUtils)1 Date (dr.evolution.util.Date)1 Taxa (dr.evolution.util.Taxa)1 Taxon (dr.evolution.util.Taxon)1 TaxonList (dr.evolution.util.TaxonList)1