use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.
the class FixedMeanRateTest method testFixedMeanRate.
@Test
public void testFixedMeanRate() throws Exception {
importAlignment("examples/nexus", new File("26.nex"), new File("29.nex"));
beautiFrame.menuItemWithPath("Mode", "Automatic set fix mean substitution rate flag").click();
warning("Setting fixed mean rates");
JTabbedPaneFixture f = beautiFrame.tabbedPane();
f = f.selectTab("Site Model");
beautiFrame.checkBox("mutationRate.isEstimated").check();
beautiFrame.checkBox("FixMeanMutationRate").check();
warning("link/unlink site models");
f.selectTab("Partitions");
beautiFrame.table().selectCells(TableCell.row(0).column(0), TableCell.row(1).column(0));
beautiFrame.button("Link Site Models").click();
beautiFrame.button("Unlink Site Models").click();
// saveFile("/Users/remcobouckaert/tmp", "x.xml");
makeSureXMLParses();
DeltaExchangeOperator operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
int nrOfParameters = operator.parameterInput.get().size();
if (nrOfParameters != 2) {
throw new IllegalArgumentException("Expected 2 parameters for deltaExchangeOperator, not " + nrOfParameters);
}
}
use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.
the class FixedMeanRateTest method testFixedMeanRateSharedSiteModel.
@Test
public void testFixedMeanRateSharedSiteModel() throws Exception {
importAlignment("examples/nexus", new File("26.nex"), new File("29.nex"), new File("47.nex"));
warning("Setting fixed mean rates");
JTabbedPaneFixture f = beautiFrame.tabbedPane();
f = f.selectTab("Site Model");
beautiFrame.checkBox("mutationRate.isEstimated").check();
// beautiFrame.checkBox("FixMeanMutationRate").check();
warning("link/unlink site models");
f.selectTab("Partitions");
beautiFrame.table().selectCells(TableCell.row(0).column(1), TableCell.row(1).column(1), TableCell.row(2).column(1));
beautiFrame.button("Link Site Models").click();
beautiFrame.button("Unlink Site Models").click();
DeltaExchangeOperator operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
int nrOfParameters = operator.parameterInput.get().size();
if (nrOfParameters != 3) {
throw new IllegalArgumentException("Expected 3 parameters for deltaExchangeOperator, not " + nrOfParameters);
}
List<Integer> weights = operator.parameterWeightsInput.get().valuesInput.get();
Assert.assertEquals(weights.size(), 3);
Assert.assertEquals(weights.get(0), (Integer) 614);
Assert.assertEquals(weights.get(1), (Integer) 601);
Assert.assertEquals(weights.get(2), (Integer) 819);
beautiFrame.table().selectCells(TableCell.row(0).column(1), TableCell.row(2).column(1));
beautiFrame.button("Link Site Models").click();
operator = (DeltaExchangeOperator) beauti.doc.pluginmap.get("FixMeanMutationRatesOperator");
nrOfParameters = operator.parameterInput.get().size();
if (nrOfParameters != 2) {
throw new IllegalArgumentException("Expected 2 parameters for deltaExchangeOperator, not " + nrOfParameters);
}
weights = operator.parameterWeightsInput.get().valuesInput.get();
Assert.assertEquals(weights.size(), 2);
Assert.assertEquals(weights.get(0), (Integer) (614 + 819));
Assert.assertEquals(weights.get(1), (Integer) 601);
makeSureXMLParses();
}
use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.
the class SiteModelInputEditor method customConnector.
public static boolean customConnector(BeautiDoc doc) {
try {
DeltaExchangeOperator operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
if (operator == null) {
return false;
}
List<RealParameter> parameters = operator.parameterInput.get();
parameters.clear();
// String weights = "";
CompoundDistribution likelihood = (CompoundDistribution) doc.pluginmap.get("likelihood");
boolean hasOneEstimatedRate = false;
List<String> rateIDs = new ArrayList<>();
List<Integer> weights = new ArrayList<>();
for (Distribution d : likelihood.pDistributions.get()) {
GenericTreeLikelihood treelikelihood = (GenericTreeLikelihood) d;
Alignment data = treelikelihood.dataInput.get();
int weight = data.getSiteCount();
if (data.isAscertained) {
weight -= data.getExcludedPatternCount();
}
if (treelikelihood.siteModelInput.get() instanceof SiteModel) {
SiteModel siteModel = (SiteModel) treelikelihood.siteModelInput.get();
RealParameter mutationRate = siteModel.muParameterInput.get();
// clockRate.m_bIsEstimated.setValue(true, clockRate);
if (mutationRate.isEstimatedInput.get()) {
hasOneEstimatedRate = true;
if (rateIDs.indexOf(mutationRate.getID()) == -1) {
parameters.add(mutationRate);
weights.add(weight);
rateIDs.add(mutationRate.getID());
} else {
int k = rateIDs.indexOf(mutationRate.getID());
weights.set(k, weights.get(k) + weight);
}
}
}
}
IntegerParameter weightParameter;
if (weights.size() == 0) {
weightParameter = new IntegerParameter();
} else {
String weightString = "";
for (int k : weights) {
weightString += k + " ";
}
weightParameter = new IntegerParameter(weightString);
weightParameter.setID("weightparameter");
}
weightParameter.isEstimatedInput.setValue(false, weightParameter);
operator.parameterWeightsInput.setValue(weightParameter, operator);
return hasOneEstimatedRate;
} catch (Exception e) {
}
return false;
}
use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.
the class SiteModelInputEditor method init.
@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
fixMeanRatesCheckBox = new JCheckBox("Fix mean substitution rate");
fixMeanRatesCheckBox.setName("FixMeanMutationRate");
fixMeanRatesCheckBox.setEnabled(!doc.autoUpdateFixMeanSubstRate);
super.init(input, beastObject, itemNr, isExpandOption, addButtons);
List<Operator> operators = ((MCMC) doc.mcmc.get()).operatorsInput.get();
fixMeanRatesCheckBox.addActionListener(e -> {
JCheckBox averageRatesBox = (JCheckBox) e.getSource();
doFixMeanRates(averageRatesBox.isSelected());
if (averageRatesBox.isSelected())
// set up relative weights
setUpOperator();
});
operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanMutationRatesOperator");
if (operator == null) {
operator = new DeltaExchangeOperator();
try {
operator.setID("FixMeanMutationRatesOperator");
operator.initByName("weight", 2.0, "delta", 0.75);
} catch (Throwable 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 (doc.alignments.size() >= 1 && operator != null) {
JComponent component = (JComponent) getComponents()[0];
component.add(box);
}
setUpOperator();
}
use of beast.evolution.operators.DeltaExchangeOperator in project beast2 by CompEvol.
the class DeltaExchangeOperatorTest method testKeepsSum.
@Test
public void testKeepsSum() {
DeltaExchangeOperator operator = new DeltaExchangeOperator();
RealParameter parameter = new RealParameter(new Double[] { 1., 1., 1., 1. });
register(operator, "parameter", parameter);
for (int i = 0; i < 100; ++i) {
operator.proposal();
}
double i = 0;
for (Double p : parameter.getValues()) {
i += p;
}
assertEquals("The DeltaExchangeOperator should not change the sum of a parameter", i, 4, 0.00001);
}
Aggregations