Search in sources :

Example 1 with FNPR

use of dr.evomodel.operators.FNPR in project beast-mcmc by beast-dev.

the class FNPRTest method testDoOperation.

/**
	 * Test method for {@link SimpleMCMCOperator#doOperation()}.
	 * @throws ImportException 
	 * @throws IOException 
	 */
public void testDoOperation() throws IOException, ImportException {
    // if you pick A you can reattach it to 3 new branches
    // if you pick B you can reattach it to 3 new branches
    // if you pick {A,B} you can reattach it to 2 new branches
    // if you pick C you can reattach it to 2 new branches
    // if you pick {A,B,C} you can reattach it to 1 new branch
    // if you pick D you can reattach it to 1 new branch
    // total: 1/12 for every new tree
    System.out.println("Test 1: Forward");
    //        String treeMatch = "(((A,C),D),(B,E));";
    String treeMatch = "(((A,C),D),(E,B));";
    int count = 0;
    int reps = 100000;
    HashMap<String, Boolean> trees = new HashMap<String, Boolean>();
    for (int i = 0; i < reps; i++) {
        TreeModel treeModel = new TreeModel("treeModel", tree5);
        FNPR operator = new FNPR(treeModel, 1);
        operator.doOperation();
        String tree = TreeUtils.newickNoLengths(treeModel);
        //System.out.println(tree);
        if (!trees.containsKey(tree)) {
            trees.put(tree, true);
        }
        if (tree.equals(treeMatch)) {
            count += 1;
        }
    }
    System.out.println("Number of trees found:\t" + trees.size());
    Set<String> keys = trees.keySet();
    for (String s : keys) {
        System.out.println(s);
    }
    double p_1 = (double) count / (double) reps;
    System.out.println("Number of proposals:\t" + count);
    System.out.println("Number of tries:\t" + reps);
    System.out.println("Number of ratio:\t" + p_1);
    System.out.println("Number of expected ratio:\t" + 1.0 / 12.0);
    assertExpectation(1.0 / 12.0, p_1, reps);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) HashMap(java.util.HashMap) FNPR(dr.evomodel.operators.FNPR)

Example 2 with FNPR

use of dr.evomodel.operators.FNPR in project beast-mcmc by beast-dev.

the class FNPRTest method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    FNPR operator = new FNPR(treeModel, 1.0);
    ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, CoercionMode.COERCION_ON, 1.0);
    UniformOperator uniformOperator = new UniformOperator(internalHeights, 1.0);
    OperatorSchedule schedule = new SimpleOperatorSchedule();
    schedule.addOperator(operator);
    schedule.addOperator(scaleOperator);
    schedule.addOperator(uniformOperator);
    return schedule;
}
Also used : Parameter(dr.inference.model.Parameter) FNPR(dr.evomodel.operators.FNPR)

Example 3 with FNPR

use of dr.evomodel.operators.FNPR in project beast-mcmc by beast-dev.

the class FNPRParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    return new FNPR(treeModel, weight);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) FNPR(dr.evomodel.operators.FNPR)

Aggregations

FNPR (dr.evomodel.operators.FNPR)3 TreeModel (dr.evomodel.tree.TreeModel)2 Parameter (dr.inference.model.Parameter)1 HashMap (java.util.HashMap)1