Search in sources :

Example 6 with ScaleOperator

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

the class OperatorScheduleTest method testOperatorScheduleMultiNestedByPercentage.

/**
 * as testOperatorSchedulePlain() but with 2 nested schedules weighted by percentage
 * Also, reuse operator, so it is in 2 sub schedules
 */
@Test
public void testOperatorScheduleMultiNestedByPercentage() {
    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", 20.0, "weightIsPercentage", true, "operatorPattern", "^.*\\.Species$");
    OperatorSchedule subSchedule2 = new OperatorSchedule();
    subSchedule2.initByName("operator", operator3, "weight", 30.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.25 / 10.0, probs[0], 1e-15);
    assertEquals(5.0 / 10.0, probs[1], 1e-15);
    assertEquals(7.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 7 with ScaleOperator

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

the class OperatorScheduleTest method setUpSchedule.

OperatorSchedule setUpSchedule() {
    DeltaExchangeOperator operator1 = new DeltaExchangeOperator();
    operator1.setID("deltaOperator");
    operator1.initByName("parameter", parameter, "weight", 1.0);
    ScaleOperator operator2 = new ScaleOperator();
    operator2.setID("scaleOperator");
    operator2.initByName("parameter", parameter, "weight", 3.0);
    OperatorSchedule schedule = new OperatorSchedule();
    schedule.initAndValidate();
    schedule.addOperator(operator1);
    schedule.addOperator(operator2);
    return schedule;
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator)

Example 8 with ScaleOperator

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

the class OperatorScheduleTest method testOperatorScheduleNestedByPercentage.

/**
 * as testOperatorSchedulePlain() but with 1 nested schedule *
 */
@Test
public void testOperatorScheduleNestedByPercentage() {
    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", 20.0, "weightIsPercentage", true, "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 / 5.0, probs[0], 1e-15);
    assertEquals(4.0 / 5.0, probs[1], 1e-15);
    assertEquals(5.0 / 5.0, probs[2], 1e-15);
}
Also used : OperatorSchedule(beast.core.OperatorSchedule) ScaleOperator(beast.evolution.operators.ScaleOperator) Test(org.junit.Test)

Example 9 with ScaleOperator

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

the class OperatorScheduleTest method testOperatorScheduleMultiNestedByRelativeWeight.

/**
 * as testOperatorSchedulePlain() but with 2 nested schedules weighted by relative weight *
 */
@Test
public void testOperatorScheduleMultiNestedByRelativeWeight() {
    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$");
    ScaleOperator operator4 = new ScaleOperator();
    operator4.setID("scaleOperator.Species2");
    operator4.initByName("parameter", parameter, "weight", 20.0);
    OperatorSchedule subSchedule2 = new OperatorSchedule();
    subSchedule2.initByName("operator", operator4, "weight", 2.0, "operatorPattern", "^.*\\.Species2$");
    schedule.subschedulesInput.setValue(subSchedule, schedule);
    schedule.subschedulesInput.setValue(subSchedule2, 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 / 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)

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