Search in sources :

Example 91 with RealParameter

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

the class LogNormalDistributionModelTest method testCalcLogP.

@Test
public void testCalcLogP() throws Exception {
    LogNormalDistributionModel logNormal = new LogNormalDistributionModel();
    logNormal.hasMeanInRealSpaceInput.setValue("true", logNormal);
    logNormal.offsetInput.setValue("1200", logNormal);
    logNormal.MParameterInput.setValue("2000", logNormal);
    logNormal.SParameterInput.setValue("0.6", logNormal);
    logNormal.initAndValidate();
    RealParameter p = new RealParameter(new Double[] { 2952.6747000000014 });
    double f0 = logNormal.calcLogP(p);
    assertEquals(-7.880210654973873, f0, 1e-10);
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel) RealParameter(beast.core.parameter.RealParameter) Test(org.junit.Test)

Example 92 with RealParameter

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

the class LogNormalDistributionModelTest method testCalcLogP3.

@Test
public void testCalcLogP3() throws Exception {
    // does the same as testCalcLogP(), but with by constructing object through init
    LogNormalDistributionModel logNormal = new LogNormalDistributionModel();
    logNormal.init("2000", "0.6", true, "1200");
    RealParameter p = new RealParameter(new Double[] { 2952.6747000000014 });
    double f0 = logNormal.calcLogP(p);
    assertEquals(-7.880210654973873, f0, 1e-10);
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel) RealParameter(beast.core.parameter.RealParameter) Test(org.junit.Test)

Example 93 with RealParameter

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

the class LogNormalDistributionModelTest method testCalcLogP2.

@Test
public void testCalcLogP2() throws Exception {
    // does the same as testCalcLogP(), but with by constructing object through XML
    String xml = "<input spec='beast.math.distributions.LogNormalDistributionModel' " + "offset='1200' " + "M='2000' " + "S='0.6' " + "meanInRealSpace='true'/>";
    RealParameter p = new RealParameter(new Double[] { 2952.6747000000014 });
    XMLParser parser = new XMLParser();
    LogNormalDistributionModel logNormal = (LogNormalDistributionModel) parser.parseBareFragment(xml, true);
    double f0 = logNormal.calcLogP(p);
    assertEquals(-7.880210654973873, f0, 1e-10);
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel) RealParameter(beast.core.parameter.RealParameter) XMLParser(beast.util.XMLParser) Test(org.junit.Test)

Example 94 with RealParameter

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

the class JSONTest method testJSONFragmentParsing.

@Test
public void testJSONFragmentParsing() throws Exception {
    JSONParser parser = new JSONParser();
    String json = "{version: \"2.5\",\n" + "\n" + "beast: [\n" + "{spec:\"beast.core.parameter.RealParameter\",\n" + " value:\"2.345\"\n" + "}\n" + "]\n" + "}\n";
    ;
    List<Object> objects = parser.parseFragment(json, true);
    assertEquals(1, objects.size());
    RealParameter p = (RealParameter) objects.get(0);
    assertEquals(2.345, p.getValue(), 1e-13);
}
Also used : RealParameter(beast.core.parameter.RealParameter) JSONParser(beast.util.JSONParser) BEASTObject(beast.core.BEASTObject) Test(org.junit.Test)

Example 95 with RealParameter

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

the class UniformIntegerOperatorTest method testParameterBound.

public void testParameterBound() {
    try {
        // 4 vaules {0, 1, 2, 3}
        count = new int[dimension][4];
        RealParameter parameter = new RealParameter(new Double[] { 1.0, 0.0, 2.0 });
        parameter.setLower(0.0);
        parameter.setUpper(3.0);
        State state = new State();
        state.initByName("stateNode", parameter);
        state.initialise();
        UniformOperator uniformOperator = new UniformOperator();
        uniformOperator.initByName("parameter", parameter, "howMany", 3, "weight", 1.0);
        for (int i = 0; i < 400; i++) {
            uniformOperator.proposal();
            Double[] values = parameter.getValues();
            for (int k = 0; k < values.length; k++) {
                int j = (int) (double) values[k];
                count[k][j] += 1;
            }
        }
        System.out.println("Discretized real distributions lower = 0.0, upper = 3.0");
        for (int j = 0; j < count.length; j++) {
            System.out.println("x[" + j + "] = " + Arrays.toString(count[j]));
        }
        assertTrue("Expected count[0][0-2] > 0 && count[0][3] == 0", (count[0][0] > 0) && (count[0][1] > 0) && (count[0][2] > 0) && (count[0][3] == 0));
        assertTrue("Expected count[1][0-2] > 0 && count[1][3] == 0", (count[1][0] > 0) && (count[1][1] > 0) && (count[1][2] > 0) && (count[1][3] == 0));
        assertTrue("Expected count[2][0-2] > 0 && count[2][3] == 0", (count[2][0] > 0) && (count[2][1] > 0) && (count[2][2] > 0) && (count[2][3] == 0));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : State(beast.core.State) RealParameter(beast.core.parameter.RealParameter) UniformOperator(beast.evolution.operators.UniformOperator)

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