Search in sources :

Example 1 with CladeRef

use of dr.evomodel.bigfasttree.constrainedtree.CladeRef in project beast-mcmc by beast-dev.

the class CladeAwareSubtreeLeapTest method testCladeRemoveRoot.

public void testCladeRemoveRoot() {
    NodeRef node = tree.getNode(3);
    NodeRef parent = tree.getParent(node);
    NodeRef grandparent = tree.getParent(parent);
    NodeRef sibling = tree.getNode(7);
    NodeRef j = tree.getNode(6);
    CladeRef clade = cladeNodeModel.getClade(node);
    operator.doOperation(node, parent, sibling, j, clade, 1.5);
    assertEquals(7, cladeNodeModel.getRootNode(clade).getNumber());
    assertTrue(noNodeLeftBehind(tree));
}
Also used : NodeRef(dr.evolution.tree.NodeRef) CladeRef(dr.evomodel.bigfasttree.constrainedtree.CladeRef)

Example 2 with CladeRef

use of dr.evomodel.bigfasttree.constrainedtree.CladeRef in project beast-mcmc by beast-dev.

the class CladeAwareSubtreeLeapTest method testCladeSuperSeedRoot.

public void testCladeSuperSeedRoot() {
    NodeRef node = tree.getNode(1);
    NodeRef parent = tree.getParent(node);
    NodeRef grandparent = tree.getParent(parent);
    NodeRef sibling = tree.getNode(2);
    NodeRef j = tree.getNode(8);
    CladeRef clade = cladeNodeModel.getClade(parent);
    operator.doOperation(node, parent, sibling, j, clade, 3.5);
    assertEquals(6, cladeNodeModel.getRootNode(clade).getNumber());
    assertTrue(noNodeLeftBehind(tree));
}
Also used : NodeRef(dr.evolution.tree.NodeRef) CladeRef(dr.evomodel.bigfasttree.constrainedtree.CladeRef)

Example 3 with CladeRef

use of dr.evomodel.bigfasttree.constrainedtree.CladeRef in project beast-mcmc by beast-dev.

the class ApproximatePoissonTreeLikelihoodTest method testOtherChildUpdates.

public void testOtherChildUpdates() throws IOException, Importer.ImportException, TreeUtils.MissingTaxonException {
    branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
    NewickImporter importer = new NewickImporter("((1:1.0,2:0.5,3:2.0):0.1,4:0.3,(7:0.2,8:0.1,9:0.3):0.2,6:0.01)");
    NewickImporter importer2 = new NewickImporter("((6:1,(4:1,((9:1,7:1):2,8:2):3.0):6):4,(1:1,(3:3,2:2):1):1);");
    tree = importer.importTree(null);
    treeModel = new BigFastTreeModel(importer2.importTree(null));
    CladeNodeModel cladeModel = new CladeNodeModel(tree, treeModel);
    BranchLengthProvider constrainedBranchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeModel);
    approximatePoissonTreeLikelihood = new ApproximatePoissonTreeLikelihood("approximateTreeLikelihood", 1, treeModel, branchRateModel, constrainedBranchLengthProvider);
    approximatePoissonTreeLikelihood.getLogLikelihood();
    NodeRef node = treeModel.getNode(1);
    NodeRef sibling = treeModel.getNode(9);
    NodeRef parent = treeModel.getParent(node);
    NodeRef grandparent = treeModel.getParent(parent);
    NodeRef root = treeModel.getRoot();
    CladeRef clade = cladeModel.getClade(parent);
    treeModel.beginTreeEdit();
    treeModel.removeChild(grandparent, parent);
    treeModel.removeChild(parent, sibling);
    treeModel.setNodeHeight(parent, treeModel.getNodeHeight(root) + 1);
    treeModel.setRoot(parent);
    // cladeModel.setRootNode(clade, parent);
    treeModel.addChild(parent, root);
    treeModel.addChild(grandparent, sibling);
    treeModel.endTreeEdit();
    double LL = approximatePoissonTreeLikelihood.getLogLikelihood();
    approximatePoissonTreeLikelihood.makeDirty();
    double newLL = approximatePoissonTreeLikelihood.getLogLikelihood();
    assertEquals(LL, newLL);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) NewickImporter(dr.evolution.io.NewickImporter) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeRef(dr.evomodel.bigfasttree.constrainedtree.CladeRef) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates)

Example 4 with CladeRef

use of dr.evomodel.bigfasttree.constrainedtree.CladeRef in project beast-mcmc by beast-dev.

the class ApproximatePoissonTreeLikelihoodTest method testRootAndRootChildUpdates.

// This tests updating when the root and rootchild2  change
// +- 6
// |
// +------| gp       +- 4 *
// |      |          |
// |      +----------| p       + 9
// |                 |     +---|
// |                 +-----|   + 7
// | r                     |
// |                       +--- 8
// |
// |+- 1
// +|
// | +----- 3
// +-|
// +--- 2
// To
// +-------------------- 4 *
// |
// |       +- 6
// |p      |
// |+------| gp                + 9
// ||      |               +---|
// ||      +---------------|   + 7
// +|                      |
// | r                    +--- 8
// |
// | +- 1
// +-|
// | +---- 3
// +-|
// +-- 2
// 
// 
public void testRootAndRootChildUpdates() throws IOException, Importer.ImportException, TreeUtils.MissingTaxonException {
    branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
    NewickImporter importer = new NewickImporter("((1:1.0,2:0.5,3:2.0):0.1,4:0.3,(7:0.2,8:0.1,9:0.3):0.2,6:0.01)");
    NewickImporter importer2 = new NewickImporter("((6:1,(4:1,((9:1,7:1):2,8:2):3.0):6):4,(1:1,(3:3,2:2):1):1);");
    tree = importer.importTree(null);
    treeModel = new BigFastTreeModel(importer2.importTree(null));
    CladeNodeModel cladeModel = new CladeNodeModel(tree, treeModel);
    BranchLengthProvider constrainedBranchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeModel);
    approximatePoissonTreeLikelihood = new ApproximatePoissonTreeLikelihood("approximateTreeLikelihood", 1, treeModel, branchRateModel, constrainedBranchLengthProvider);
    approximatePoissonTreeLikelihood.getLogLikelihood();
    NodeRef node = treeModel.getNode(9);
    NodeRef sibling = treeModel.getNode(1);
    NodeRef parent = treeModel.getParent(node);
    NodeRef grandparent = treeModel.getParent(parent);
    NodeRef root = treeModel.getRoot();
    CladeRef clade = cladeModel.getClade(node);
    treeModel.beginTreeEdit();
    treeModel.removeChild(grandparent, parent);
    treeModel.removeChild(parent, sibling);
    treeModel.setNodeHeight(parent, treeModel.getNodeHeight(root) + 1);
    treeModel.setRoot(parent);
    // cladeModel.setRootNode(clade, parent);
    treeModel.addChild(parent, root);
    treeModel.addChild(grandparent, sibling);
    treeModel.endTreeEdit();
    double LL = approximatePoissonTreeLikelihood.getLogLikelihood();
    approximatePoissonTreeLikelihood.makeDirty();
    double newLL = approximatePoissonTreeLikelihood.getLogLikelihood();
    assertEquals(LL, newLL);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) NewickImporter(dr.evolution.io.NewickImporter) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeRef(dr.evomodel.bigfasttree.constrainedtree.CladeRef) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates)

Example 5 with CladeRef

use of dr.evomodel.bigfasttree.constrainedtree.CladeRef in project beast-mcmc by beast-dev.

the class ApproximatePoissonTreeLikelihoodTest method testRootPolytomy.

public void testRootPolytomy() throws IOException, Importer.ImportException, TreeUtils.MissingTaxonException {
    branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
    NewickImporter importer = new NewickImporter("((1:1.0,2:1.0):1.0,3:1.0,4:1.0);");
    NewickImporter importer2 = new NewickImporter("(((1:1.0,2:1.0):1.0,3:1.1):0.1,4:1.0);");
    tree = importer.importTree(null);
    treeModel = new BigFastTreeModel(importer2.importTree(null));
    CladeNodeModel cladeModel = new CladeNodeModel(tree, treeModel);
    BranchLengthProvider constrainedBranchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeModel);
    approximatePoissonTreeLikelihood = new ApproximatePoissonTreeLikelihood("approximateTreeLikelihood", 1, treeModel, branchRateModel, constrainedBranchLengthProvider);
    approximatePoissonTreeLikelihood.getLogLikelihood();
    expectedLL = 0;
    double[] expectations = { 1d, 1d, 1d, 1.1, 1.1 };
    // time
    double[] mutations = { 1d, 1d, 1d, 1.0, 1 };
    for (int i = 0; i < expectations.length; i++) {
        PoissonDistribution p = new PoissonDistribution(expectations[i]);
        expectedLL += p.logPdf(mutations[i]);
    }
    NodeRef rootNode = treeModel.getRoot();
    NodeRef rootNode1 = treeModel.getNode(5);
    NodeRef tip3 = treeModel.getNode(2);
    CladeRef clade = cladeModel.getClade(rootNode);
    treeModel.beginTreeEdit();
    treeModel.removeChild(rootNode, rootNode1);
    treeModel.setRoot(rootNode1);
    treeModel.removeChild(rootNode1, tip3);
    treeModel.addChild(rootNode, tip3);
    treeModel.addChild(rootNode1, rootNode);
    treeModel.setNodeHeight(rootNode1, treeModel.getNodeHeight(rootNode) + 1);
    treeModel.endTreeEdit();
    // cladeModel.setRootNode(clade,rootNode1);
    double LL = approximatePoissonTreeLikelihood.getLogLikelihood();
    approximatePoissonTreeLikelihood.makeDirty();
    double newLL = approximatePoissonTreeLikelihood.getLogLikelihood();
    assertEquals(LL, newLL, 1E-13);
}
Also used : PoissonDistribution(dr.math.distributions.PoissonDistribution) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) NodeRef(dr.evolution.tree.NodeRef) NewickImporter(dr.evolution.io.NewickImporter) CladeRef(dr.evomodel.bigfasttree.constrainedtree.CladeRef)

Aggregations

NodeRef (dr.evolution.tree.NodeRef)7 CladeRef (dr.evomodel.bigfasttree.constrainedtree.CladeRef)7 NewickImporter (dr.evolution.io.NewickImporter)3 CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)3 ConstrainedTreeBranchLengthProvider (dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider)3 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)3 PoissonDistribution (dr.math.distributions.PoissonDistribution)1