Debian Codegraph @

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

raw symbols SCIP
1 /**
2 *
3 */
4 package test.dr.evomodel.operators;
5
6 import java.io.IOException;
7 import java.util.HashMap;
8 import java.util.Set;
9
10 import dr.evolution.tree.TreeUtils;
11 import dr.inference.operators.*;
12 import junit.framework.TestSuite;
13 import junit.framework.Test;
14
15 import dr.evolution.io.Importer.ImportException;
16 import dr.evomodel.operators.FNPR;
17 import dr.evomodel.tree.TreeModel;
18 import dr.inference.model.Parameter;
19
20 /**
21 * @author shhn001
22 *
23 */
24 public class FNPRTest extends OperatorAssert{
25
26 public static Test suite() {
27 return new TestSuite(FNPRTest.class);
28 }
29
30 /**
31 * Test method for {@link SimpleMCMCOperator#doOperation()}.
32 * @throws ImportException
33 * @throws IOException
34 */
35 public void testDoOperation() throws IOException, ImportException {
36 // if you pick A you can reattach it to 3 new branches
37 // if you pick B you can reattach it to 3 new branches
38 // if you pick {A,B} you can reattach it to 2 new branches
39 // if you pick C you can reattach it to 2 new branches
40 // if you pick {A,B,C} you can reattach it to 1 new branch
41 // if you pick D you can reattach it to 1 new branch
42 // total: 1/12 for every new tree
43
44 System.out.println("Test 1: Forward");
45
46 // String treeMatch = "(((A,C),D),(B,E));";
47 String treeMatch = "(((A,C),D),(E,B));";
48
49 int count = 0;
50 int reps = 100000;
51
52 HashMap<String, Boolean> trees = new HashMap<String, Boolean>();
53
54 for (int i = 0; i < reps; i++) {
55
56 TreeModel treeModel = new TreeModel("treeModel", tree5);
57 FNPR operator = new FNPR(treeModel, 1);
58 operator.doOperation();
59
60 String tree = TreeUtils.newickNoLengths(treeModel);
61 //System.out.println(tree);
62 if (!trees.containsKey(tree)){
63 trees.put(tree, true);
64 }
65 if (tree.equals(treeMatch)) {
66 count += 1;
67 }
68
69 }
70 System.out.println("Number of trees found:\t" + trees.size());
71 Set<String> keys = trees.keySet();
72 for (String s : keys){
73 System.out.println(s);
74 }
75
76 double p_1 = (double) count / (double) reps;
77
78 System.out.println("Number of proposals:\t" + count);
79 System.out.println("Number of tries:\t" + reps);
80 System.out.println("Number of ratio:\t" + p_1);
81 System.out.println("Number of expected ratio:\t" + 1.0/12.0);
82 assertExpectation(1.0/12.0, p_1, reps);
83
84 }
85
86 public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
87
88 Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
89 Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
90
91 FNPR operator = new FNPR(treeModel, 1.0);
92 ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, AdaptationMode.ADAPTATION_ON, 1.0);
93 UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
94
95 OperatorSchedule schedule = new SimpleOperatorSchedule();
96 schedule.addOperator(operator);
97 schedule.addOperator(scaleOperator);
98 schedule.addOperator(uniformOperator);
99
100 return schedule;
101 }
102
103 }