Search in sources :

Example 1 with ScaleOperator

use of beast.evolution.operators.ScaleOperator in project beast2 by CompEvol.

the class OperatorScheduleTest method testOperatorScheduleNestedByPercentage2.

/**
 * as testOperatorScheduleNestedByPercentage() but with 2 nested operators *
 */
@Test
public void testOperatorScheduleNestedByPercentage2() {
    double[] probs;
    OperatorSchedule schedule = setUpSchedule();
    ScaleOperator operator3 = new ScaleOperator();
    operator3.setID("scaleOperator.Species");
    operator3.initByName("parameter", parameter, "weight", 20.0);
    OperatorSchedule subSchedule = new OperatorSchedule();
    subSchedule = new OperatorSchedule();
    ScaleOperator operator4 = new ScaleOperator();
    operator4.setID("scaleOperator2.Species");
    operator4.initByName("parameter", parameter, "weight", 20.0);
    subSchedule.initByName("operator", operator3, "operator", operator4, "weight", 20.0, "weightIsPercentage", true, "operatorPattern", "^.*\\.Species$");
    schedule.subschedulesInput.get().clear();
    schedule.subschedulesInput.setValue(subSchedule, schedule);
    schedule.initAndValidate();
    schedule.addOperator(operator3);
    schedule.addOperator(operator4);
    // selectOperator() causes reweighting
    schedule.selectOperator();
    probs = schedule.getCummulativeProbs();
    assertEquals(4, probs.length);
    assertEquals(4, schedule.operators.size());
    assertEquals(1.0 / 5.0, probs[0], 1e-15);
    assertEquals(4.0 / 5.0, probs[1], 1e-15);
    assertEquals(4.5 / 5.0, probs[2], 1e-15);
    assertEquals(5.0 / 5.0, probs[3], 1e-15);
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Example 2 with ScaleOperator

use of beast.evolution.operators.ScaleOperator in project beast2 by CompEvol.

the class OperatorScheduleTest method testOperatorScheduleNestedByRelativeWeight.

/**
 * as testOperatorSchedulePlain() but with 1 nested schedule weighted by relative weight
 * Also, make sure the operatorPattern matching works *
 */
@Test
public void testOperatorScheduleNestedByRelativeWeight() {
    double[] probs;
    OperatorSchedule schedule = setUpSchedule();
    ScaleOperator operator3 = new ScaleOperator();
    operator3.setID("scaleOperator.Species");
    operator3.initByName("parameter", parameter, "weight", 20.0);
    OperatorSchedule subSchedule = new OperatorSchedule();
    subSchedule.initByName(/*"operator", operator3,*/
    "weight", 4.0, "operatorPattern", "^.*\\.Species$");
    schedule.subschedulesInput.setValue(subSchedule, schedule);
    schedule.initAndValidate();
    schedule.addOperator(operator3);
    // selectOperator() causes reweighting
    schedule.selectOperator();
    probs = schedule.getCummulativeProbs();
    assertEquals(3, probs.length);
    assertEquals(3, schedule.operators.size());
    assertEquals(1.0 / 8.0, probs[0], 1e-15);
    assertEquals(4.0 / 8.0, probs[1], 1e-15);
    assertEquals(8.0 / 8.0, probs[2], 1e-15);
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Example 3 with ScaleOperator

use of beast.evolution.operators.ScaleOperator in project beast2 by CompEvol.

the class OperatorScheduleTest method testOperatorScheduleNestedByRelativeWeight2.

/**
 * as testOperatorScheduleNestedByRelativeWeight() but with 2 nested operators *
 */
@Test
public void testOperatorScheduleNestedByRelativeWeight2() {
    double[] probs;
    OperatorSchedule schedule = setUpSchedule();
    ScaleOperator operator3 = new ScaleOperator();
    operator3.setID("scaleOperator.Species");
    operator3.initByName("parameter", parameter, "weight", 20.0);
    OperatorSchedule subSchedule = new OperatorSchedule();
    subSchedule = new OperatorSchedule();
    ScaleOperator operator4 = new ScaleOperator();
    operator4.setID("scaleOperator2.Species");
    operator4.initByName("parameter", parameter, "weight", 20.0);
    subSchedule.initByName("operator", operator3, "operator", operator4, "weight", 4.0, "operatorPattern", "^.*\\.Species$");
    schedule.subschedulesInput.get().clear();
    schedule.subschedulesInput.setValue(subSchedule, schedule);
    schedule.initAndValidate();
    schedule.addOperator(operator3);
    schedule.addOperator(operator4);
    // selectOperator() causes reweighting
    schedule.selectOperator();
    probs = schedule.getCummulativeProbs();
    assertEquals(4, probs.length);
    assertEquals(4, schedule.operators.size());
    assertEquals(1.0 / 8.0, probs[0], 1e-15);
    assertEquals(4.0 / 8.0, probs[1], 1e-15);
    assertEquals(6.0 / 8.0, probs[2], 1e-15);
    assertEquals(8.0 / 8.0, probs[3], 1e-15);
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Example 4 with ScaleOperator

use of beast.evolution.operators.ScaleOperator in project beast2 by CompEvol.

the class OperatorScheduleTest method testOperatorScheduleMultiNestedByPercentageAndRelativeWeight.

/**
 * as testOperatorSchedulePlain() but with 2 nested schedules, one weighted by percentage, one weighted by relative weight
 * Also, reuse operator, so it is in 2 sub schedules
 */
@Test
public void testOperatorScheduleMultiNestedByPercentageAndRelativeWeight() {
    double[] probs;
    OperatorSchedule schedule = setUpSchedule();
    ScaleOperator operator3 = new ScaleOperator();
    operator3.setID("scaleOperator.Species");
    operator3.initByName("parameter", parameter, "weight", 20.0);
    OperatorSchedule subSchedule = new OperatorSchedule();
    subSchedule.initByName("operator", operator3, "weight", 4.0, "weightIsPercentage", false, "operatorPattern", "^.*\\.Species$");
    OperatorSchedule subSchedule2 = new OperatorSchedule();
    subSchedule2.initByName(/*"operator", operator3, */
    "weight", 20.0, "weightIsPercentage", true, "operatorPattern", "^.*\\.Species$");
    schedule.subschedulesInput.setValue(subSchedule, schedule);
    schedule.subschedulesInput.setValue(subSchedule2, schedule);
    schedule.initAndValidate();
    // schedule.addOperator(operator3);
    // selectOperator() causes reweighting
    schedule.selectOperator();
    probs = schedule.getCummulativeProbs();
    assertEquals(4, probs.length);
    assertEquals(4, schedule.operators.size());
    assertEquals(1.0 / 10.0, probs[0], 1e-15);
    assertEquals(4.0 / 10.0, probs[1], 1e-15);
    assertEquals(8.0 / 10.0, probs[2], 1e-15);
    assertEquals(10.0 / 10.0, probs[3], 1e-15);
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Example 5 with ScaleOperator

use of beast.evolution.operators.ScaleOperator in project beast2 by CompEvol.

the class ScaleOperatorTest method testTreeScaling.

@Test
public void testTreeScaling() {
    String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;";
    TreeParser tree = new TreeParser(newick, false, false, false, 0);
    Node[] node = tree.getNodesAsArray();
    ScaleOperator operator = new ScaleOperator();
    operator.initByName("tree", tree, "weight", 1.0);
    operator.proposal();
    // leaf node
    node = tree.getNodesAsArray();
    assertEquals(0.0, node[0].getHeight(), EPSILON);
    assertEquals(0.0, node[1].getHeight(), EPSILON);
    // leaf node, not scaled
    assertEquals(0.5, node[2].getHeight(), EPSILON);
    assertEquals(0.5, node[3].getHeight(), EPSILON);
    // internal nodes, all scaled
    // first determine scale factor
    double scale = node[4].getHeight() / 1.0;
    assertEquals(1.0 * scale, node[4].getHeight(), EPSILON);
    assertEquals(1.5 * scale, node[5].getHeight(), EPSILON);
    assertEquals(2.0 * scale, node[6].getHeight(), EPSILON);
}
Also used : TreeParser(beast.util.TreeParser) Node(beast.evolution.tree.Node) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Aggregations

ScaleOperator (beast.evolution.operators.ScaleOperator)9 OperatorSchedule (beast.core.OperatorSchedule)8 Test (org.junit.Test)8 DeltaExchangeOperator (beast.evolution.operators.DeltaExchangeOperator)1 Node (beast.evolution.tree.Node)1 TreeParser (beast.util.TreeParser)1