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);
}
Aggregations