Search in sources :

Example 1 with Exponential

use of beast.math.distributions.Exponential in project beast2 by CompEvol.

the class MRCAPriorTest method testMRCATimePrior.

@Test
public void testMRCATimePrior() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    TreeParser tree = new TreeParser();
    tree.initByName("taxa", data, "newick", "((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035," + "(gorilla:0.024003,(orangutan:0.010772,siamang:0.010772):0.013231):0.012035);", "IsLabelledNewick", true);
    Taxon human = new Taxon();
    human.setID("human");
    Taxon bonobo = new Taxon();
    bonobo.setID("bonobo");
    Taxon chimp = new Taxon();
    chimp.setID("chimp");
    Taxon gorilla = new Taxon();
    gorilla.setID("gorilla");
    Taxon orangutan = new Taxon();
    orangutan.setID("orangutan");
    Taxon siamang = new Taxon();
    siamang.setID("siamang");
    MRCAPrior prior = new MRCAPrior();
    TaxonSet set = new TaxonSet();
    set.initByName("taxon", human, "taxon", bonobo, "taxon", chimp);
    Exponential exp = new Exponential();
    /* get distribution for set (human, bonobo, chimp) */
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true, "distr", exp);
    double logP = prior.calculateLogP();
    assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
    /* get distribution for set (human, chimp), do not require the set to by monophyletic */
    set = new TaxonSet();
    set.initByName("taxon", human, "taxon", chimp);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
    logP = prior.calculateLogP();
    assertEquals(-0.024003, logP, BEASTTestCase.PRECISION);
    /* get distribution for set (human, chimp), DO require the set to by monophyletic */
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", true);
    logP = prior.calculateLogP();
    assertEquals(Double.NEGATIVE_INFINITY, logP, 0);
    /* get distribution for set (human, gorilla) = root, not monophyletic */
    set = new TaxonSet();
    set.initByName("taxon", human, "taxon", gorilla);
    prior.initByName("tree", tree, "taxonset", set, "monophyletic", false);
    logP = prior.calculateLogP();
    assertEquals(-0.024003 - 0.012035, logP, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) Taxon(beast.evolution.alignment.Taxon) MRCAPrior(beast.math.distributions.MRCAPrior) Exponential(beast.math.distributions.Exponential) TaxonSet(beast.evolution.alignment.TaxonSet) Test(org.junit.Test)

Example 2 with Exponential

use of beast.math.distributions.Exponential in project beast2 by CompEvol.

the class MeanOfParametricDistributionTest method testMeanOfExponential.

@Test
public void testMeanOfExponential() throws Exception {
    Exponential exp = new Exponential();
    exp.initByName("mean", "10");
    double mean = exp.getMean();
    assertEquals(mean, 10, 1e-10);
    exp = new Exponential();
    exp.initByName("mean", "1");
    mean = exp.getMean();
    assertEquals(mean, 1, 1e-10);
    exp = new Exponential();
    exp.initByName("mean", "1", "offset", "3");
    mean = exp.getMean();
    assertEquals(mean, 4, 1e-10);
}
Also used : Exponential(beast.math.distributions.Exponential) Test(org.junit.Test)

Aggregations

Exponential (beast.math.distributions.Exponential)2 Test (org.junit.Test)2 Alignment (beast.evolution.alignment.Alignment)1 Taxon (beast.evolution.alignment.Taxon)1 TaxonSet (beast.evolution.alignment.TaxonSet)1 MRCAPrior (beast.math.distributions.MRCAPrior)1 TreeParser (beast.util.TreeParser)1