Search in sources :

Example 6 with ConstrainedTreeBranchLengthProvider

use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider 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

CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)6 ConstrainedTreeBranchLengthProvider (dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider)6 NewickImporter (dr.evolution.io.NewickImporter)5 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)5 NodeRef (dr.evolution.tree.NodeRef)4 CladeRef (dr.evomodel.bigfasttree.constrainedtree.CladeRef)3 PoissonDistribution (dr.math.distributions.PoissonDistribution)3 DistanceMatrix (dr.evolution.distance.DistanceMatrix)1 Tree (dr.evolution.tree.Tree)1 TreeUtils (dr.evolution.tree.TreeUtils)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 TreeModel (dr.evomodel.tree.TreeModel)1