Search in sources :

Example 11 with TreeLikelihood

use of beast.evolution.likelihood.TreeLikelihood in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRGILikelihood.

@Test
public void testGTRGILikelihood() throws Exception {
    // Set up GTR model: 4 gamma categories, gamma shape = 0.5, prop invariant = 0.5
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.5", "proportionInvariant", "0.5", "substModel", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1947.5829396144961, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1947.5829396144961, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 12 with TreeLikelihood

use of beast.evolution.likelihood.TreeLikelihood in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRGLikelihood.

@Test
public void testGTRGLikelihood() throws Exception {
    // Set up GTR model: 4 gamma categories, gamma shape = 0.5
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.5", "substModel", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 13 with TreeLikelihood

use of beast.evolution.likelihood.TreeLikelihood in project MultiTypeTree by tgvaughan.

the class InitMigrationModelConnector method customConnector.

public static boolean customConnector(BeautiDoc doc) {
    for (BEASTInterface p : doc.getPartitions("Tree")) {
        TreeLikelihood treeLikelihood = (TreeLikelihood) p;
        StructuredCoalescentMultiTypeTree tree = (StructuredCoalescentMultiTypeTree) treeLikelihood.treeInput.get();
        String pID = BeautiDoc.parsePartition(tree.getID());
        SCMigrationModel migModel = (SCMigrationModel) doc.pluginmap.get("migModel.t:" + pID);
        SCMigrationModel migModelInit = (SCMigrationModel) doc.pluginmap.get("migModelInit.t:" + pID);
        String rateMatrixStr = getParameterString((RealParameter) migModel.rateMatrixInput.get());
        String popSizesStr = getParameterString((RealParameter) migModel.popSizesInput.get());
        // Ensure model has appropriate number of demes
        int uniqueTraitCount = uniqueTraitsInData(tree).size();
        StringBuilder rateMatrixStrBuilder = new StringBuilder();
        StringBuilder popSizesStrBuilder = new StringBuilder();
        migModel.getTypeSet().initAndValidate();
        if (migModel.popSizesInput.get().getDimension() != migModel.getNTypes()) {
            for (int i = 0; i < migModel.getNTypes(); i++) {
                popSizesStrBuilder.append(" 1.0");
                for (int j = 0; j < migModel.getNTypes(); j++) {
                    if (j == i)
                        continue;
                    rateMatrixStrBuilder.append(" 1.0");
                }
            }
            popSizesStr = popSizesStrBuilder.toString();
            rateMatrixStr = rateMatrixStrBuilder.toString();
            ((RealParameter) migModel.popSizesInput.get()).setDimension(migModel.getNTypes());
            ((RealParameter) migModel.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModel.popSizesInput.get());
            ((RealParameter) migModel.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
            ((RealParameter) migModel.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModel.rateMatrixInput.get());
            ((RealParameter) migModel.popSizesInput.get()).initAndValidate();
            ((RealParameter) migModel.rateMatrixInput.get()).initAndValidate();
            migModel.initAndValidate();
        }
        ((RealParameter) migModelInit.popSizesInput.get()).setDimension(migModel.getNTypes());
        ((RealParameter) migModelInit.popSizesInput.get()).valuesInput.setValue(popSizesStr, (RealParameter) migModelInit.popSizesInput.get());
        ((RealParameter) migModelInit.rateMatrixInput.get()).setDimension(migModel.getNTypes() * (migModel.getNTypes() - 1));
        ((RealParameter) migModelInit.rateMatrixInput.get()).valuesInput.setValue(rateMatrixStr, (RealParameter) migModelInit.rateMatrixInput.get());
        try {
            ((RealParameter) migModelInit.popSizesInput.get()).initAndValidate();
            ((RealParameter) migModelInit.rateMatrixInput.get()).initAndValidate();
            migModelInit.initAndValidate();
        } catch (Exception ex) {
            System.err.println("Error configuring initial migration model.");
        }
    }
    return false;
}
Also used : TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) RealParameter(beast.core.parameter.RealParameter) BEASTInterface(beast.core.BEASTInterface) SCMigrationModel(beast.evolution.tree.SCMigrationModel) StructuredCoalescentMultiTypeTree(beast.evolution.tree.StructuredCoalescentMultiTypeTree)

Example 14 with TreeLikelihood

use of beast.evolution.likelihood.TreeLikelihood in project bacter by tgvaughan.

the class ACGLikelihoodSlow method calculateLogP.

@Override
public double calculateLogP() {
    logP = 0.0;
    for (Region region : acg.getRegions(locus)) {
        Alignment margAlign = createMarginalAlignment(alignment, acg, region);
        Tree margTree = new Tree(new MarginalTree(acg, region).getRoot());
        TreeLikelihood treeLikelihood = new TreeLikelihood();
        treeLikelihood.initByName("data", margAlign, "tree", margTree, "siteModel", siteModel, "useAmbiguities", useAmbiguitiesInput.get());
        logP += treeLikelihood.calculateLogP();
    }
    return logP;
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) GenericTreeLikelihood(beast.evolution.likelihood.GenericTreeLikelihood) Region(bacter.Region) Tree(beast.evolution.tree.Tree) MarginalTree(bacter.MarginalTree) MarginalTree(bacter.MarginalTree)

Example 15 with TreeLikelihood

use of beast.evolution.likelihood.TreeLikelihood in project beast2 by CompEvol.

the class UnorderedAlignmentsTest method testUnorderedAlignment.

@Test
public void testUnorderedAlignment() throws Exception {
    TaxonSet taxa = getTaxa();
    Tree tree = getTree(taxa);
    SiteModel siteModel = getSiteModel();
    double logP = 0.0;
    double shuffledLogP = 0.0;
    for (int i = 0; i < 3; ++i) {
        Alignment data = getAlignment(taxa, tree, siteModel);
        // First calculate in order
        TreeLikelihood likelihood = new TreeLikelihood();
        likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
        logP += likelihood.calculateLogP();
        // Now calculate again, with shuffled taxon order
        Collections.shuffle(data.sequenceInput.get());
        likelihood = new TreeLikelihood();
        likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
        shuffledLogP += likelihood.calculateLogP();
    }
    assertEquals(logP, shuffledLogP, 1E-9);
}
Also used : Alignment(beast.evolution.alignment.Alignment) SimulatedAlignment(beast.app.seqgen.SimulatedAlignment) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) RandomTree(beast.evolution.tree.RandomTree) SiteModel(beast.evolution.sitemodel.SiteModel) TaxonSet(beast.evolution.alignment.TaxonSet) Test(org.junit.Test)

Aggregations

TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)24 Alignment (beast.evolution.alignment.Alignment)22 SiteModel (beast.evolution.sitemodel.SiteModel)22 Tree (beast.evolution.tree.Tree)22 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)20 Test (org.junit.Test)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)16 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 HKY (beast.evolution.substitutionmodel.HKY)6 RealParameter (beast.core.parameter.RealParameter)5 GeneralSubstitutionModel (beast.evolution.substitutionmodel.GeneralSubstitutionModel)5 Sequence (beast.evolution.alignment.Sequence)4 JukesCantor (beast.evolution.substitutionmodel.JukesCantor)3 BEASTInterface (beast.core.BEASTInterface)2 MarginalTree (bacter.MarginalTree)1 Region (bacter.Region)1 SimulatedAlignment (beast.app.seqgen.SimulatedAlignment)1 Input (beast.core.Input)1 TaxonSet (beast.evolution.alignment.TaxonSet)1 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)1