Debian Codegraph @

src/test/dr/evomodel/substmodel/TwoPhaseModelTest.java

raw symbols SCIP
1 package test.dr.evomodel.substmodel;
2
3 import dr.oldevomodel.substmodel.AsymmetricQuadraticModel;
4 import dr.oldevomodel.substmodel.OnePhaseModel;
5 import dr.oldevomodel.substmodel.TwoPhaseModel;
6 import junit.framework.TestCase;
7 import dr.evolution.datatype.Microsatellite;
8 import dr.evomodel.substmodel.*;
9 import dr.inference.model.Parameter;
10
11 /**
12 * @author Chieh-Hsi Wu
13 *
14 * JUnit test for TwoPhaseModel of microsatellites
15 *
16 */
17 public class TwoPhaseModelTest extends TestCase {
18 interface Instance {
19
20 public OnePhaseModel getSubModel();
21
22 double getPParam();
23
24 double getMParam();
25
26 double getDistance();
27
28 double[] getPi();
29
30 public double[] getExpectedResult();
31 }
32
33 Instance test0 = new Instance() {
34
35 public OnePhaseModel getSubModel(){
36 return new AsymmetricQuadraticModel(new Microsatellite(1,6), null);
37 }
38
39 public double getPParam(){
40 return 0.75;
41 }
42
43 public double getMParam(){
44 return 0.58;
45 }
46
47 public double getDistance(){
48 return 0.94;
49 }
50
51 public double[] getPi(){
52 return new double[]{0.18744637901040673, 0.1607567474109271, 0.15179687357866556, 0.15179687357866556, 0.16075674741092702, 0.18744637901040695};
53 }
54
55 public double[] getExpectedResult(){
56 return new double[]{
57 0.63398241451779758, 0.23675486586787650, 0.07330431013568975, 0.02919578818459456, 0.01589013386525921, 0.01087248742878196,
58 0.27524752392268953, 0.42098887984631489, 0.19147132450808460, 0.06606140653506744, 0.02837812583210070, 0.01785273935574281,
59 0.09233761983753200, 0.20121070458110243, 0.40820601172807069, 0.19248802732743994, 0.06994493808030816, 0.03581269844554699,
60 0.03581269844554700, 0.06994493808030799, 0.19248802732743994, 0.40820601172807053, 0.20121070458110252, 0.09233761983753204,
61 0.01785273935574278, 0.02837812583210064, 0.06606140653506756, 0.19147132450808424, 0.42098887984631500, 0.27524752392268970,
62 0.01087248742878200, 0.01589013386525917, 0.02919578818459453, 0.07330431013568960, 0.23675486586787683, 0.63398241451779769
63 };
64 }
65
66 };
67
68 Instance[] all = {test0};
69
70
71 public void testTwoPhaseModel() {
72
73 for (Instance test : all) {
74
75 OnePhaseModel subModel = test.getSubModel();
76 Microsatellite microsat = (Microsatellite)subModel.getDataType();
77 Parameter pParam = new Parameter.Default(test.getPParam());
78 Parameter mParam = new Parameter.Default(test.getMParam());
79
80
81
82 TwoPhaseModel tpm = new TwoPhaseModel(microsat, null, subModel, pParam, mParam, null,false);
83
84 int k;
85
86 tpm.computeStationaryDistribution();
87 double[] statDist = tpm.getStationaryDistribution();
88 final double[] expectedStatDist = test.getPi();
89 for (k = 0; k < statDist.length; ++k) {
90 assertEquals(statDist[k], expectedStatDist[k], 1e-10);
91 }
92
93 int stateCount = microsat.getStateCount();
94 double[] mat = new double[stateCount*stateCount];
95 tpm.getTransitionProbabilities(test.getDistance(), mat);
96 final double[] result = test.getExpectedResult();
97
98
99 for (k = 0; k < mat.length; ++k) {
100 assertEquals(result[k], mat[k], 5e-9);
101 //System.out.print(" " + (mat[k]));// - result[k]));
102 }
103
104 k = 0;
105 for(int i = 0; i < microsat.getStateCount(); i ++){
106 for(int j = 0; j < microsat.getStateCount(); j ++){
107 assertEquals(result[k++], tpm.getOneTransitionProbabilityEntry(test.getDistance(), i , j), 1e-10);
108
109 }
110 }
111
112 for(int j = 0; j < microsat.getStateCount();j ++){
113 double[] colTransitionProb = tpm.getColTransitionProbabilities(test.getDistance(), j);
114 for(int i =0 ; i < microsat.getStateCount(); i++){
115 assertEquals(result[i*microsat.getStateCount()+j], colTransitionProb[i], 1e-10);
116 }
117 }
118
119
120
121 for(int i = 0; i < microsat.getStateCount();i ++){
122 double[] rowTransitionProb = tpm.getRowTransitionProbabilities(test.getDistance(), i);
123 for(int j =0 ; j < microsat.getStateCount(); j++){
124 assertEquals(result[i*microsat.getStateCount()+j], rowTransitionProb[j], 1e-10);
125 }
126 }
127 }
128
129 }
130
131
132 }