Search in sources :

Example 1 with GibbsSubtreeSwap

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

the class GibbsSubtreeSwapTestProblem method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(TreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    GibbsSubtreeSwap operator = new GibbsSubtreeSwap(treeModel, false, 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 : SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) GibbsSubtreeSwap(dr.evomodel.operators.GibbsSubtreeSwap) Parameter(dr.inference.model.Parameter) UniformOperator(dr.inference.operators.UniformOperator) ScaleOperator(dr.inference.operators.ScaleOperator)

Example 2 with GibbsSubtreeSwap

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

the class GibbsSubtreeSwapParser method parseXMLObject.

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

Example 3 with GibbsSubtreeSwap

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

the class GibbsSubtreeSwapTestProblem method getOperatorSchedule.

public OperatorSchedule getOperatorSchedule(DefaultTreeModel treeModel) {
    Parameter rootParameter = treeModel.createNodeHeightsParameter(true, false, false);
    Parameter internalHeights = treeModel.createNodeHeightsParameter(false, true, false);
    GibbsSubtreeSwap operator = new GibbsSubtreeSwap(treeModel, false, 1.0);
    ScaleOperator scaleOperator = new ScaleOperator(rootParameter, 0.75, AdaptationMode.ADAPTATION_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 : GibbsSubtreeSwap(dr.evomodel.operators.GibbsSubtreeSwap) Parameter(dr.inference.model.Parameter)

Example 4 with GibbsSubtreeSwap

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

the class GibbsSubtreeSwapTestProblem method testDoOperation.

/**
 * Test method for {@link dr.evomodel.operators.GibbsSubtreeSwap}.
 * @throws ImportException
 * @throws IOException
 */
public void testDoOperation() throws IOException, ImportException {
    // assumes that the posterior is equal for all trees!!!
    // probability of picking (A,B) node is 1/(2n-3) = 1/7
    // probability of swapping with D is 1/2
    // total = 1/14
    // probability of picking {D} node is 1/(2n-3) = 1/7
    // probability of picking {A,B} is 1/5
    // total = 1/35
    // total = 1/14 + 1/35 = 7/70 = 0.1
    // now we calculate the same for the backward proposal
    // this is needed for the Hastings ratio
    // probability of picking (A,B) node is 1/(2n-3) = 1/7
    // probability of swapping with D is 1/3
    // total = 1/21
    // probability of picking {D} node is 1/(2n-3) = 1/7
    // probability of picking {A,B} is 1/4
    // total = 1/28
    // total = 1/21 + 1/28 = 4/84 + 3/84 = 7/84 = 1/12
    System.out.println("Test 1: Forward");
    String treeMatch = "(((D,C),(A,B)),E);";
    int count = 0;
    int reps = 100000;
    for (int i = 0; i < reps; i++) {
        DefaultTreeModel treeModel = new DefaultTreeModel("treeModel", tree5);
        GibbsSubtreeSwap operator = new GibbsSubtreeSwap(treeModel, false, 1.0);
        double hr = operator.operate(null);
        String tree = TreeUtils.newickNoLengths(treeModel);
        if (tree.equals(treeMatch)) {
            // System.out.println("Expected Hastings ratio = " + 5.0/6.0 + " in log = " + Math.log(5.0/6.0));
            // System.out.println("Obtained Hastings ratio = " + Math.exp(hr) + " in log = " + hr);
            TestCase.assertEquals(Math.log(5.0 / 6.0), hr, 0.00000001);
            count += 1;
        }
    }
    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" + 0.1);
    assertExpectation(0.1, p_1, reps);
}
Also used : GibbsSubtreeSwap(dr.evomodel.operators.GibbsSubtreeSwap) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel)

Aggregations

GibbsSubtreeSwap (dr.evomodel.operators.GibbsSubtreeSwap)4 Parameter (dr.inference.model.Parameter)2 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)1 TreeModel (dr.evomodel.tree.TreeModel)1 OperatorSchedule (dr.inference.operators.OperatorSchedule)1 ScaleOperator (dr.inference.operators.ScaleOperator)1 SimpleOperatorSchedule (dr.inference.operators.SimpleOperatorSchedule)1 UniformOperator (dr.inference.operators.UniformOperator)1