Search in sources :

Example 1 with LogNormalDistributionModel

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

the class LogNormalDistributionModelTest method testPDF.

@Test
public void testPDF() throws Exception {
    System.out.println("Testing 10000 random pdf calls");
    LogNormalDistributionModel logNormal = new LogNormalDistributionModel();
    logNormal.init("1.0", "2.0");
    for (int i = 0; i < 10000; i++) {
        double M = Randomizer.nextDouble() * 10.0 - 5.0;
        double S = Randomizer.nextDouble() * 10;
        double x = -1;
        while (x < 0) {
            x = Math.log(Randomizer.nextDouble() * 10);
        }
        logNormal.MParameterInput.setValue(M + "", logNormal);
        logNormal.SParameterInput.setValue(S + "", logNormal);
        logNormal.initAndValidate();
        double pdf = 1.0 / (x * S * Math.sqrt(2 * Math.PI)) * Math.exp(-Math.pow(Math.log(x) - M, 2) / (2 * S * S));
        System.out.println("Testing logNormal[M=" + M + " S=" + S + "].pdf(" + x + ")");
        double f = logNormal.density(x);
        assertEquals(pdf, f, 1e-10);
    }
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel) Test(org.junit.Test)

Example 2 with LogNormalDistributionModel

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

the class MeanOfParametricDistributionTest method testMeanOfLogNormal.

@Test
public void testMeanOfLogNormal() throws Exception {
    LogNormalDistributionModel exp = new LogNormalDistributionModel();
    exp.initByName("M", "10", "S", "1", "meanInRealSpace", true);
    double mean = exp.getMean();
    assertEquals(mean, 10, 1e-10);
    exp = new LogNormalDistributionModel();
    exp.initByName("M", "1", "S", "1", "meanInRealSpace", true);
    mean = exp.getMean();
    assertEquals(mean, 1, 1e-10);
    exp = new LogNormalDistributionModel();
    exp.initByName("M", "1", "S", "1", "meanInRealSpace", true, "offset", "3");
    mean = exp.getMean();
    assertEquals(mean, 4, 1e-10);
    try {
        exp = new LogNormalDistributionModel();
        exp.initByName("M", "1", "S", "1", "meanInRealSpace", false, "offset", "3");
        mean = exp.getMean();
        assertEquals(mean, 4.4816890703380645, 1e-10);
    } catch (RuntimeException e) {
    // we are fine here
    }
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel) Test(org.junit.Test)

Example 3 with LogNormalDistributionModel

use of beast.math.distributions.LogNormalDistributionModel 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 4 with LogNormalDistributionModel

use of beast.math.distributions.LogNormalDistributionModel 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 5 with LogNormalDistributionModel

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

the class LogNormalDistributionModelTest method setUp.

public void setUp() {
    logNormal = new LogNormalDistributionModel();
    logNormal.initByName("M", "1.0", "S", "2.0");
    Randomizer.setSeed(123);
}
Also used : LogNormalDistributionModel(beast.math.distributions.LogNormalDistributionModel)

Aggregations

LogNormalDistributionModel (beast.math.distributions.LogNormalDistributionModel)6 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)3 XMLParser (beast.util.XMLParser)1