Debian Codegraph @

src/test/dr/evomodel/coalescent/VDdemographicFunctionTest.java

raw symbols SCIP
1 package test.dr.evomodel.coalescent;
2
3 import junit.framework.TestCase;
4 import dr.evomodel.coalescent.VDdemographicFunction;
5 import dr.evomodel.coalescent.VariableDemographicModel;
6 import dr.evolution.util.Units;
7
8 /**
9 * @author Joseph Heled
10 * Date: 23/06/2009
11 */
12 public class VDdemographicFunctionTest extends TestCase {
13 public void testExp() {
14 // test that numerical and exact integration match (up to a point, numerical is not that good for those
15 // exponential gone to constant transitions.
16 {
17 double[] times = {1, 3};
18 double[] logPops = {0, 2, 3};
19 VariableDemographicModel.Type type = VariableDemographicModel.Type.EXPONENTIAL;
20 Units.Type units = Units.Type.SUBSTITUTIONS;
21 final VDdemographicFunction f = new VDdemographicFunction(times, logPops, units, type);
22
23 double[][] vals = {{0, 2, 1e-9}, {1, 2, 1e-9}, {0, 5, 1e-6}, {2, 6, 1e-6}};
24 for(double[] c : vals) {
25 double v1 = f.getIntegral(c[0], c[1]);
26 double v2 = f.getNumericalIntegral(c[0], c[1]);
27 assertEquals(Math.abs(1 - v1 / v2), 0, c[2]);
28 }
29 }
30
31 {
32 double[] times = {1, 3};
33 // try a const interval
34 double[] logPops = {0, 0, 3};
35 VariableDemographicModel.Type type = VariableDemographicModel.Type.EXPONENTIAL;
36 Units.Type units = Units.Type.SUBSTITUTIONS;
37 final VDdemographicFunction f = new VDdemographicFunction(times, logPops, units, type);
38
39 double[][] vals = {{0, .7, 1e-9}, {1, 2, 1e-9}, {0, 5, 1e-6}, {2, 6, 1e-6}};
40 for(double[] c : vals) {
41 double v1 = f.getIntegral(c[0], c[1]);
42 double v2 = f.getNumericalIntegral(c[0], c[1]);
43 assertEquals(Math.abs(1 - v1 / v2), 0, c[2]);
44 }
45 }
46 }
47 }