Search in sources :

Example 1 with MultiEpochExponential

use of dr.evolution.coalescent.MultiEpochExponential in project beast-mcmc by beast-dev.

the class MultiEpochExponentialTest method testThreeExponential.

public void testThreeExponential() {
    Units.Type units = Units.Type.YEARS;
    ExponentialGrowth e = new ExponentialGrowth(units);
    e.setN0(N0);
    e.setGrowthRate(rates3[0]);
    MultiEpochExponential mee = new MultiEpochExponential(units, 3);
    mee.setN0(N0);
    for (int i = 0; i < rates3.length; ++i) {
        mee.setGrowthRate(i, rates3[i]);
    }
    for (int i = 0; i < transitionTimes3.length; ++i) {
        mee.setTransitionTime(i, transitionTimes3[i]);
    }
    double start = 0.0;
    double finish = 1.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = e.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
    start = 0.5;
    finish = 1.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = e.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
    start = 11.0;
    finish = 11.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = e.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
}
Also used : ExponentialGrowth(dr.evolution.coalescent.ExponentialGrowth) MultiEpochExponential(dr.evolution.coalescent.MultiEpochExponential) Units(dr.evolution.util.Units)

Example 2 with MultiEpochExponential

use of dr.evolution.coalescent.MultiEpochExponential in project beast-mcmc by beast-dev.

the class MultiEpochExponentialTest method testExponentialExponential.

public void testExponentialExponential() {
    Units.Type units = Units.Type.YEARS;
    ExponentialExponential ee = new ExponentialExponential(units);
    ee.setN0(N0);
    ee.setGrowthRate(rates[0]);
    ee.setAncestralGrowthRate(rates[1]);
    ee.setTransitionTime(transitionTimes[0]);
    MultiEpochExponential mee = new MultiEpochExponential(units, 2);
    mee.setN0(N0);
    for (int i = 0; i < rates.length; ++i) {
        mee.setGrowthRate(i, rates[i]);
    }
    for (int i = 0; i < transitionTimes.length; ++i) {
        mee.setTransitionTime(i, transitionTimes[i]);
    }
    for (double time = 0; time < 20; time += 1.0) {
        double eeDemo = ee.getDemographic(time);
        double meeDemo = mee.getDemographic(time);
        assertEquals(eeDemo, meeDemo, tolerance1);
    }
    double start = 0.0;
    double finish = 1.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = ee.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
    start = 0.5;
    finish = 1.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = ee.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
    start = 11.0;
    finish = 11.0;
    for (; finish < 20.0; finish += 1.0) {
        double eeInt = ee.getIntegral(start, finish);
        double meeIntN = mee.getNumericalIntegral(start, finish);
        double meeIntA = mee.getAnalyticIntegral(start, finish);
        // System.err.println(finish + ": " + eeInt + " " + meeIntN + " " + meeIntA);
        assertEquals(eeInt, meeIntN, tolerance1);
        assertEquals(meeIntN, meeIntA, tolerance2);
    }
}
Also used : MultiEpochExponential(dr.evolution.coalescent.MultiEpochExponential) ExponentialExponential(dr.evolution.coalescent.ExponentialExponential) Units(dr.evolution.util.Units)

Aggregations

MultiEpochExponential (dr.evolution.coalescent.MultiEpochExponential)2 Units (dr.evolution.util.Units)2 ExponentialExponential (dr.evolution.coalescent.ExponentialExponential)1 ExponentialGrowth (dr.evolution.coalescent.ExponentialGrowth)1