Search in sources :

Example 1 with CladeNodeModel

use of dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel 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);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) Tree(dr.evolution.tree.Tree) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) DistanceMatrix(dr.evolution.distance.DistanceMatrix) TreeUtils(dr.evolution.tree.TreeUtils)

Example 2 with CladeNodeModel

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

the class CladeAwareSubtreeLeapOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    AdaptationMode mode = AdaptationMode.parseMode(xo);
    CladeNodeModel cladeModel = (CladeNodeModel) xo.getChild(CladeNodeModel.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final double size = xo.getAttribute(SIZE, Double.NaN);
    final double targetAcceptance = xo.getAttribute(TARGET_ACCEPTANCE, 0.234);
    CladeAwareSubtreeLeap.DistanceKernelType distanceKernel = CladeAwareSubtreeLeap.DistanceKernelType.NORMAL;
    if (size <= 0.0) {
        throw new XMLParseException("The SubTreeLeap size attribute must be positive and non-zero.");
    }
    if (targetAcceptance <= 0.0 || targetAcceptance >= 1.0) {
        throw new XMLParseException("Target acceptance probability has to lie in (0, 1)");
    }
    final boolean slideOnly = xo.getAttribute(SLIDE_ONLY, false);
    return new CladeAwareSubtreeLeap(cladeModel, weight, size, distanceKernel, mode, targetAcceptance, slideOnly);
}
Also used : CladeAwareSubtreeLeap(dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreeLeap) AdaptationMode(dr.inference.operators.AdaptationMode) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)

Example 3 with CladeNodeModel

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

the class CladeNodeModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Tree cladeTree = (Tree) xo.getElementFirstChild(CLADE_TREE);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    try {
        return new CladeNodeModel(CLADE_MODEL, cladeTree, treeModel);
    } catch (TreeUtils.MissingTaxonException e) {
        e.printStackTrace();
        throw new XMLParseException("tree and clade much match");
    }
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) Tree(dr.evolution.tree.Tree) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) TreeUtils(dr.evolution.tree.TreeUtils)

Example 4 with CladeNodeModel

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

the class CladeAwareSubtreeLeapTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    MathUtils.setSeed(112432);
    NewickImporter importer = new NewickImporter("(((0:1.0,(1:1.0,2:1.0)n6:1.0)n7:1.0,3:2.0)n8:1.0,(4:3.0,5:1.0)n9:1.0)n10;");
    NewickImporter constraintsImporter = new NewickImporter("((0:1.0,1:1.0,2:1.0,3:1.0):1.0,4:1.0,5:0.1);");
    Tree rawTree = importer.importTree(null);
    Tree constraintsTree = constraintsImporter.importTree(null);
    tree = new BigFastTreeModel(rawTree);
    cladeNodeModel = new CladeNodeModel(constraintsTree, tree);
    operator = new CladeAwareSubtreeLeap(cladeNodeModel, 100);
}
Also used : CladeAwareSubtreeLeap(dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreeLeap) NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)

Example 5 with CladeNodeModel

use of dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel 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();
}
Also used : PoissonDistribution(dr.math.distributions.PoissonDistribution) NewickImporter(dr.evolution.io.NewickImporter) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates)

Aggregations

CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)12 NewickImporter (dr.evolution.io.NewickImporter)8 ConstrainedTreeBranchLengthProvider (dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider)6 Tree (dr.evolution.tree.Tree)5 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)5 NodeRef (dr.evolution.tree.NodeRef)4 TreeModel (dr.evomodel.tree.TreeModel)4 CladeAwareSubtreeLeap (dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreeLeap)3 CladeRef (dr.evomodel.bigfasttree.constrainedtree.CladeRef)3 PoissonDistribution (dr.math.distributions.PoissonDistribution)3 TreeUtils (dr.evolution.tree.TreeUtils)2 DistanceMatrix (dr.evolution.distance.DistanceMatrix)1 BigFastTreeModel (dr.evomodel.bigfasttree.BigFastTreeModel)1 CladeAwareSubtreePruneRegraft (dr.evomodel.bigfasttree.constrainedtree.CladeAwareSubtreePruneRegraft)1 ConstraintsTreeLikelihood (dr.evomodel.bigfasttree.constrainedtree.ConstraintsTreeLikelihood)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 AdaptationMode (dr.inference.operators.AdaptationMode)1