Debian Codegraph @

src/test/dr/evomodel/operators/NNITest.java

raw symbols SCIP
1 /**
2 *
3 */
4 package test.dr.evomodel.operators;
5
6
7 import java.io.IOException;
8
9 import dr.evolution.tree.TreeUtils;
10 import dr.inference.operators.*;
11 import junit.framework.Test;
12 import junit.framework.TestSuite;
13
14 import dr.evolution.io.Importer.ImportException;
15 import dr.evomodel.operators.NNI;
16 import dr.evomodel.tree.TreeModel;
17 import dr.inference.model.Parameter;
18
19 /**
20 * @author Sebastian Hoehna
21 *
22 */
23 public class NNITest extends OperatorAssert{
24
25 public static Test suite() {
26 return new TestSuite(NNITest.class);
27 }
28
29 /**
30 * Test method for {@link SimpleMCMCOperator#doOperation()}.
31 * @throws ImportException
32 * @throws IOException
33 */
34 public void testDoOperation() throws IOException, ImportException {
35 // probability of picking B node is 1/(2n-4) = 1/6
36 // probability of swapping it with C is 1/1
37 // total = 1/6
38
39 System.out.println("Test 1: Forward");
40
41 String treeMatch = "((((A,C),B),D),E);";
42
43 int count = 0;
44 int reps = 100000;
45
46 for (int i = 0; i < reps; i++) {
47
48 TreeModel treeModel = new TreeModel("treeModel", tree5);
49 NNI operator = new NNI(treeModel, 1);
50 operator.doOperation();
51
52 String tree = TreeUtils.newickNoLengths(treeModel);
53
54 if (tree.equals(treeMatch)) {
55 count += 1;
56 }
57
58 }
59 double p_1 = (double) count / (double) reps;
60
61 System.out.println("Number of proposals:\t" + count);
62 System.out.println("Number of tries:\t" + reps);
63 System.out.println("Number of ratio:\t" + p_1);
64 System.out.println("Number of expected ratio:\t" + 1.0/6.0);
65 assertExpectation(1.0/6.0, p_1, reps);
66
67 }
68
69 public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
70
71 Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
72 Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
73
74 NNI operator = new NNI(treeModel, 1.0);
75 ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, AdaptationMode.ADAPTATION_ON, 1.0);
76 UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
77
78 OperatorSchedule schedule = new SimpleOperatorSchedule();
79 schedule.addOperator(operator);
80 // schedule.addOperator(scaleOperator);
81 // schedule.addOperator(uniformOperator);
82
83 return schedule;
84 }
85 }