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();
}
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);
}
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();
}
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;
}
Aggregations