| 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 junit.framework.Test; |
| 11 |
import junit.framework.TestSuite; |
| 12 |
|
| 13 |
import dr.evolution.io.Importer.ImportException; |
| 14 |
import dr.evomodel.operators.ExchangeOperator; |
| 15 |
|
| 16 |
import dr.evomodel.tree.TreeModel; |
| 17 |
import dr.inference.model.Parameter; |
| 18 |
import dr.inference.operators.AdaptationMode; |
| 19 |
import dr.inference.operators.OperatorSchedule; |
| 20 |
import dr.inference.operators.ScaleOperator; |
| 21 |
import dr.inference.operators.SimpleOperatorSchedule; |
| 22 |
import dr.inference.operators.UniformOperator; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class NarrowExchangeTest extends OperatorAssert{ |
| 29 |
|
| 30 |
public static Test suite() { |
| 31 |
return new TestSuite(NarrowExchangeTest.class); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public void testNarrow() throws IOException, ImportException { |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
System.out.println("Test 1: Forward"); |
| 44 |
|
| 45 |
String treeMatch = "((((A,C),B),D),E);"; |
| 46 |
|
| 47 |
int count = 0; |
| 48 |
int reps = 100000; |
| 49 |
|
| 50 |
for (int i = 0; i < reps; i++) { |
| 51 |
|
| 52 |
TreeModel treeModel = new TreeModel("treeModel", tree5); |
| 53 |
ExchangeOperator operator = new ExchangeOperator(ExchangeOperator.NARROW, treeModel, 1); |
| 54 |
operator.doOperation(); |
| 55 |
|
| 56 |
String tree = TreeUtils.newickNoLengths(treeModel); |
| 57 |
|
| 58 |
if (tree.equals(treeMatch)) { |
| 59 |
count += 1; |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
double p_1 = (double) count / (double) reps; |
| 64 |
|
| 65 |
System.out.println("Number of proposals:\t" + count); |
| 66 |
System.out.println("Number of tries:\t" + reps); |
| 67 |
System.out.println("Number of ratio:\t" + p_1); |
| 68 |
System.out.println("Number of expected ratio:\t" + 1.0/6.0); |
| 69 |
assertExpectation(1.0/6.0, p_1, reps); |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
public OperatorSchedule getOperatorSchedule(TreeModel treeModel) { |
| 74 |
|
| 75 |
Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false); |
| 76 |
Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false); |
| 77 |
|
| 78 |
ExchangeOperator operator = new ExchangeOperator(ExchangeOperator.NARROW, treeModel, 1.0); |
| 79 |
ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, AdaptationMode.ADAPTATION_ON, 1.0); |
| 80 |
UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0); |
| 81 |
|
| 82 |
OperatorSchedule schedule = new SimpleOperatorSchedule(); |
| 83 |
schedule.addOperator(operator); |
| 84 |
schedule.addOperator(scaleOperator); |
| 85 |
schedule.addOperator(uniformOperator); |
| 86 |
|
| 87 |
return schedule; |
| 88 |
} |
| 89 |
} |