Search in sources :

Example 66 with RealParameter

use of beast.core.parameter.RealParameter in project beast2 by CompEvol.

the class UnorderedAlignmentsTest method getTree.

public static Tree getTree(TaxonSet taxa) throws Exception {
    Tree tree = new RandomTree();
    TraitSet dates = getDates(taxa);
    ConstantPopulation constant = new ConstantPopulation();
    constant.initByName("popSize", new RealParameter("5.0"));
    tree.initByName("taxonset", taxa, "populationModel", constant, "trait", dates);
    return tree;
}
Also used : ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) RandomTree(beast.evolution.tree.RandomTree) TraitSet(beast.evolution.tree.TraitSet) Tree(beast.evolution.tree.Tree) RandomTree(beast.evolution.tree.RandomTree) RealParameter(beast.core.parameter.RealParameter)

Example 67 with RealParameter

use of beast.core.parameter.RealParameter in project beast2 by CompEvol.

the class DeltaExchangeOperatorTest method testKeepsSum.

@Test
public void testKeepsSum() {
    DeltaExchangeOperator operator = new DeltaExchangeOperator();
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    register(operator, "parameter", parameter);
    for (int i = 0; i < 100; ++i) {
        operator.proposal();
    }
    double i = 0;
    for (Double p : parameter.getValues()) {
        i += p;
    }
    assertEquals("The DeltaExchangeOperator should not change the sum of a parameter", i, 4, 0.00001);
}
Also used : RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Example 68 with RealParameter

use of beast.core.parameter.RealParameter in project beast2 by CompEvol.

the class DeltaExchangeOperatorTest method testCanOperate.

@Test
public void testCanOperate() {
    // Test whether a validly initialised operator may make proposals
    State state = new State();
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    state.initByName("stateNode", parameter);
    state.initialise();
    DeltaExchangeOperator d = new DeltaExchangeOperator();
    // proposals
    try {
        d.initByName("parameter", parameter);
    } catch (RuntimeException e) {
        return;
    }
    d.proposal();
}
Also used : State(beast.core.State) RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Example 69 with RealParameter

use of beast.core.parameter.RealParameter in project beast2 by CompEvol.

the class DeltaExchangeOperatorTest method testKeepsWeightedSum.

@Test
public void testKeepsWeightedSum() {
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    register(new DeltaExchangeOperator(), "weightvector", new IntegerParameter(new Integer[] { 0, 1, 2, 1 }), "parameter", parameter);
    Double[] p = parameter.getValues();
    assertEquals("The DeltaExchangeOperator should not change the sum of a parameter", 0 * p[1] + 1 * p[1] + 2 * p[2] + 1 * p[3], 4, 0.00001);
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Example 70 with RealParameter

use of beast.core.parameter.RealParameter in project beast2 by CompEvol.

the class GTRTest method testGTR.

public void testGTR() throws Exception {
    for (Instance test : all) {
        RealParameter f = new RealParameter(test.getPi());
        Frequencies freqs = new Frequencies();
        freqs.initByName("frequencies", f, "estimate", false);
        GTR gtr = new GTR();
        Double[] rates = test.getRates();
        gtr.initByName("rateAC", new RealParameter(rates[0] + ""), "rateAG", new RealParameter(rates[1] + ""), "rateAT", new RealParameter(rates[2] + ""), "rateCG", new RealParameter(rates[3] + ""), "rateCT", new RealParameter(rates[4] + ""), "rateGT", new RealParameter(rates[5] + ""), "frequencies", freqs);
        double distance = test.getDistance();
        double[] mat = new double[4 * 4];
        gtr.getTransitionProbabilities(null, distance, 0, 1, mat);
        final double[] result = test.getExpectedResult();
        for (int k = 0; k < mat.length; ++k) {
            assertEquals(mat[k], result[k], 1e-10);
            System.out.println(k + " : " + (mat[k] - result[k]));
        }
    }
}
Also used : GTR(beast.evolution.substitutionmodel.GTR) RealParameter(beast.core.parameter.RealParameter) Frequencies(beast.evolution.substitutionmodel.Frequencies)

Aggregations

RealParameter (beast.core.parameter.RealParameter)97 Test (org.junit.Test)39 IntegerParameter (beast.core.parameter.IntegerParameter)23 Tree (beast.evolution.tree.Tree)16 State (beast.core.State)14 SCMigrationModel (beast.evolution.tree.SCMigrationModel)13 Alignment (beast.evolution.alignment.Alignment)11 TypeSet (beast.evolution.tree.TypeSet)11 MCMC (beast.core.MCMC)10 SiteModel (beast.evolution.sitemodel.SiteModel)10 Frequencies (beast.evolution.substitutionmodel.Frequencies)10 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)10 StructuredCoalescentTreeDensity (multitypetree.distributions.StructuredCoalescentTreeDensity)10 TaxonSet (beast.evolution.alignment.TaxonSet)9 MultiTypeTreeStatLogger (multitypetree.util.MultiTypeTreeStatLogger)9 MultiTypeTreeFromNewick (beast.evolution.tree.MultiTypeTreeFromNewick)8 Node (beast.evolution.tree.Node)8 Operator (beast.core.Operator)7 RandomTree (beast.evolution.tree.RandomTree)7 Locus (bacter.Locus)6