Search in sources :

Example 6 with DeltaExchangeOperator

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

the class DeltaExchangeOperatorTest method testCanOperate.

@Test
public void testCanOperate() {
    // Test whether a validly initialised operator may make proposals
    State state = new State();
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    state.initByName("stateNode", parameter);
    state.initialise();
    DeltaExchangeOperator d = new DeltaExchangeOperator();
    // proposals
    try {
        d.initByName("parameter", parameter);
    } catch (RuntimeException e) {
        return;
    }
    d.proposal();
}
Also used : State(beast.core.State) RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Example 7 with DeltaExchangeOperator

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

the class DeltaExchangeOperatorTest method testKeepsWeightedSum.

@Test
public void testKeepsWeightedSum() {
    RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
    register(new DeltaExchangeOperator(), "weightvector", new IntegerParameter(new Integer[] { 0, 1, 2, 1 }), "parameter", parameter);
    Double[] p = parameter.getValues();
    assertEquals("The DeltaExchangeOperator should not change the sum of a parameter", 0 * p[1] + 1 * p[1] + 2 * p[2] + 1 * p[3], 4, 0.00001);
}
Also used : IntegerParameter(beast.core.parameter.IntegerParameter) RealParameter(beast.core.parameter.RealParameter) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) Test(org.junit.Test)

Example 8 with DeltaExchangeOperator

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

the class ClockModelListInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    fixMeanRatesCheckBox = new JCheckBox("Fix mean rate of clock models");
    m_buttonStatus = ButtonStatus.NONE;
    super.init(input, beastObject, itemNr, isExpandOption, addButtons);
    List<Operator> operators = ((MCMC) doc.mcmc.get()).operatorsInput.get();
    fixMeanRatesCheckBox.addActionListener(e -> {
        JCheckBox averageRatesBox = (JCheckBox) e.getSource();
        boolean averageRates = averageRatesBox.isSelected();
        List<Operator> operators2 = ((MCMC) doc.mcmc.get()).operatorsInput.get();
        if (averageRates) {
            // connect DeltaExchangeOperator
            if (!operators2.contains(operator)) {
                operators2.add(operator);
            }
            // set up relative weights
            setUpOperator();
        } else {
            operators2.remove(operator);
            fixMeanRatesValidateLabel.setVisible(false);
            repaint();
        }
    });
    operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanRatesOperator");
    if (operator == null) {
        operator = new DeltaExchangeOperator();
        try {
            operator.setID("FixMeanRatesOperator");
            operator.initByName("weight", 2.0, "delta", 0.75);
        } catch (Exception e1) {
        // ignore initAndValidate exception
        }
        doc.addPlugin(operator);
    }
    fixMeanRatesCheckBox.setSelected(operators.contains(operator));
    Box box = Box.createHorizontalBox();
    box.add(fixMeanRatesCheckBox);
    box.add(Box.createHorizontalGlue());
    fixMeanRatesValidateLabel = new SmallLabel("x", Color.GREEN);
    fixMeanRatesValidateLabel.setVisible(false);
    box.add(fixMeanRatesValidateLabel);
    if (((List<?>) input.get()).size() > 1 && operator != null) {
        add(box);
    }
    setUpOperator();
}
Also used : JCheckBox(javax.swing.JCheckBox) Operator(beast.core.Operator) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) SmallLabel(beast.app.draw.SmallLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) ArrayList(java.util.ArrayList) List(java.util.List) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator)

Example 9 with DeltaExchangeOperator

use of beast.evolution.operators.DeltaExchangeOperator 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)

Aggregations

DeltaExchangeOperator (beast.evolution.operators.DeltaExchangeOperator)9 Test (org.junit.Test)5 RealParameter (beast.core.parameter.RealParameter)4 IntegerParameter (beast.core.parameter.IntegerParameter)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JTabbedPaneFixture (org.fest.swing.fixture.JTabbedPaneFixture)2 SmallLabel (beast.app.draw.SmallLabel)1 Operator (beast.core.Operator)1 OperatorSchedule (beast.core.OperatorSchedule)1 State (beast.core.State)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 Alignment (beast.evolution.alignment.Alignment)1 GenericTreeLikelihood (beast.evolution.likelihood.GenericTreeLikelihood)1 ScaleOperator (beast.evolution.operators.ScaleOperator)1 SiteModel (beast.evolution.sitemodel.SiteModel)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Box (javax.swing.Box)1 JCheckBox (javax.swing.JCheckBox)1