use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider in project beast-mcmc by beast-dev.
the class ApproximatePoissonTreeLikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
int sequenceLength = xo.getIntegerAttribute("sequenceLength");
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
BranchLengthProvider branchLengthProvider;
if (xo.getElementFirstChild(DATA) instanceof Tree) {
Tree dataTree = (Tree) xo.getElementFirstChild(DATA);
CladeNodeModel cladeNodeModel = null;
try {
cladeNodeModel = new CladeNodeModel(dataTree, treeModel);
} catch (TreeUtils.MissingTaxonException e) {
e.printStackTrace();
}
branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
} else if (xo.getElementFirstChild(DATA) instanceof CladeNodeModel) {
CladeNodeModel cladeNodeModel = (CladeNodeModel) xo.getElementFirstChild(DATA);
branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
} else {
DistanceMatrix dataMatrix = (DistanceMatrix) xo.getElementFirstChild(DATA);
branchLengthProvider = new RzhetskyNeiBranchLengthProvider(dataMatrix, treeModel);
}
BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
return new ApproximatePoissonTreeLikelihood(TREE_LIKELIHOOD, sequenceLength, treeModel, branchRateModel, branchLengthProvider);
}
use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider in project beast-mcmc by beast-dev.
the class ApproximatePoissonTreeLikelihoodTest method setUp.
public void setUp() throws Exception {
super.setUp();
branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
NewickImporter importer = new NewickImporter("((1:1.0,2:1.0,3:1.0):1.0,4:1.0);");
NewickImporter importer2 = new NewickImporter("(((1:1.0,2:1.0):0.1,3:1.1):1.0,4:1.0);");
tree = importer.importTree(null);
treeModel = new BigFastTreeModel(importer2.importTree(null));
cladeModel = new CladeNodeModel(tree, treeModel);
BranchLengthProvider constrainedBranchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeModel);
approximatePoissonTreeLikelihood = new ApproximatePoissonTreeLikelihood("approximateTreeLikelihood", 1, treeModel, branchRateModel, constrainedBranchLengthProvider);
expectedLL = 0;
double[] expectations = { 1d, 1d, 1.1, 2d, 0.1 };
// time
double[] mutations = { 1d, 1d, 1.0, 2d, 0 };
for (int i = 0; i < expectations.length; i++) {
PoissonDistribution p = new PoissonDistribution(expectations[i]);
expectedLL += p.logPdf(mutations[i]);
}
approximatePoissonTreeLikelihood.getLogLikelihood();
}
use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider in project beast-mcmc by beast-dev.
the class ApproximatePoissonTreeLikelihoodTest method testRootPolytomyHeightChange.
public void testRootPolytomyHeightChange() 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,5:1.0);");
NewickImporter importer2 = new NewickImporter("(((1:1.0,2:1.0):1.0,3:1.1):0.1,(4:1.0,5:1.0):0.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();
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();
treeModel.setNodeHeight(rootNode, 2.05);
double LL = approximatePoissonTreeLikelihood.getLogLikelihood();
approximatePoissonTreeLikelihood.makeDirty();
double newLL = approximatePoissonTreeLikelihood.getLogLikelihood();
assertEquals(LL, newLL);
}
use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider 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);
}
use of dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider 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);
}
Aggregations