use of beast.core.Operator in project beast2 by CompEvol.
the class BeautiBase method operatorsAsString.
String operatorsAsString() {
MCMC mcmc = (MCMC) doc.mcmc.get();
List<Operator> operators = mcmc.operatorsInput.get();
return "assertOperatorsEqual" + pluginListAsString(operators);
}
use of beast.core.Operator in project beast2 by CompEvol.
the class OperatorListInputEditor method addPluginItem.
@Override
protected InputEditor addPluginItem(Box itemBox, BEASTInterface beastObject) {
Operator operator = (Operator) beastObject;
JTextField entry = new JTextField(" " + getLabel(operator));
entry.setMinimumSize(new Dimension(200, 16));
// entry.setMaximumSize(new Dimension(200, 20));
m_entries.add(entry);
entry.setBackground(getBackground());
entry.setBorder(null);
itemBox.add(Box.createRigidArea(new Dimension(5, 1)));
itemBox.add(entry);
entry.setEditable(false);
// JLabel label = new JLabel(getLabel(operator));
// label.setBackground(Color.WHITE);
// m_labels.add(label);
// m_entries.add(null);
// itemBox.add(label);
itemBox.add(Box.createHorizontalGlue());
JTextField weightEntry = new JTextField();
weightEntry.setToolTipText(operator.m_pWeight.getHTMLTipText());
weightEntry.setText(operator.m_pWeight.get() + "");
weightEntry.getDocument().addDocumentListener(new OperatorDocumentListener(operator, weightEntry));
Dimension size = new Dimension(50, 25);
weightEntry.setMinimumSize(size);
weightEntry.setPreferredSize(size);
int fontsize = weightEntry.getFont().getSize();
weightEntry.setMaximumSize(new Dimension(50 * fontsize / 13, 50 * fontsize / 13));
itemBox.add(weightEntry);
return this;
}
use of beast.core.Operator in project beast2 by CompEvol.
the class MRCAPriorInputEditor method disableTipSampling.
// remove TipDatesRandomWalker from list of operators
private static void disableTipSampling(BEASTInterface m_beastObject, BeautiDoc doc) {
// First, find the operator
TipDatesRandomWalker operator = null;
MRCAPrior prior = (MRCAPrior) m_beastObject;
TaxonSet taxonset = prior.taxonsetInput.get();
// However, if there is an TipDatesRandomWalker with taxonset as input, we want to remove it.
for (BEASTInterface o : taxonset.getOutputs()) {
if (o instanceof TipDatesRandomWalker) {
operator = (TipDatesRandomWalker) o;
}
}
if (operator == null) {
// should never happen
return;
}
// remove from list of operators
Object o = doc.mcmc.get().getInput("operator");
if (o instanceof Input<?>) {
Input<List<Operator>> operatorInput = (Input<List<Operator>>) o;
List<Operator> operators = operatorInput.get();
operators.remove(operator);
}
}
use of beast.core.Operator in project beast2 by CompEvol.
the class ParameterInputEditor method addComboBox.
@Override
protected void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
Box paramBox = Box.createHorizontalBox();
Parameter.Base<?> parameter = null;
if (itemNr >= 0) {
parameter = (Parameter.Base<?>) ((List<?>) input.get()).get(itemNr);
} else {
parameter = (Parameter.Base<?>) input.get();
}
if (parameter == null) {
super.addComboBox(box, input, beastObject);
} else {
setUpEntry();
paramBox.add(m_entry);
if (doc.allowLinking) {
boolean isLinked = doc.isLinked(m_input);
if (isLinked || doc.suggestedLinks((BEASTInterface) m_input.get()).size() > 0) {
JButton linkbutton = new JButton(Utils.getIcon(BeautiPanel.ICONPATH + (isLinked ? "link.png" : "unlink.png")));
linkbutton.setBorder(BorderFactory.createEmptyBorder());
linkbutton.setToolTipText("link/unlink this parameter with another compatible parameter");
linkbutton.addActionListener(e -> {
if (doc.isLinked(m_input)) {
// unlink
try {
BEASTInterface candidate = doc.getUnlinkCandidate(m_input, m_beastObject);
m_input.setValue(candidate, m_beastObject);
doc.deLink(m_input);
} catch (RuntimeException e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(this, "Could not unlink: " + e2.getMessage());
}
} else {
// create a link
List<BEASTInterface> candidates = doc.suggestedLinks((BEASTInterface) m_input.get());
JComboBox<BEASTInterface> jcb = new JComboBox<>(candidates.toArray(new BEASTInterface[] {}));
JOptionPane.showMessageDialog(null, jcb, "select parameter to link with", JOptionPane.QUESTION_MESSAGE);
BEASTInterface candidate = (BEASTInterface) jcb.getSelectedItem();
if (candidate != null) {
try {
m_input.setValue(candidate, m_beastObject);
doc.addLink(m_input);
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
refreshPanel();
});
paramBox.add(linkbutton);
}
}
paramBox.add(Box.createHorizontalGlue());
m_isEstimatedBox = new JCheckBox(doc.beautiConfig.getInputLabel(parameter, parameter.isEstimatedInput.getName()));
m_isEstimatedBox.setName(input.getName() + ".isEstimated");
if (input.get() != null) {
m_isEstimatedBox.setSelected(parameter.isEstimatedInput.get());
}
m_isEstimatedBox.setToolTipText(parameter.isEstimatedInput.getHTMLTipText());
boolean isClockRate = false;
for (Object output : parameter.getOutputs()) {
if (output instanceof BranchRateModel.Base) {
isClockRate |= ((BranchRateModel.Base) output).meanRateInput.get() == parameter;
}
}
m_isEstimatedBox.setEnabled(!isClockRate || !getDoc().autoSetClockRate);
m_isEstimatedBox.addActionListener(e -> {
try {
Parameter.Base<?> parameter2 = (Parameter.Base<?>) m_input.get();
parameter2.isEstimatedInput.setValue(m_isEstimatedBox.isSelected(), parameter2);
if (isParametricDistributionParameter) {
String id = parameter2.getID();
if (id.startsWith("RealParameter")) {
ParametricDistribution parent = null;
for (Object beastObject2 : parameter2.getOutputs()) {
if (beastObject2 instanceof ParametricDistribution) {
parent = (ParametricDistribution) beastObject2;
break;
}
}
Distribution grandparent = null;
for (Object beastObject2 : parent.getOutputs()) {
if (beastObject2 instanceof Distribution) {
grandparent = (Distribution) beastObject2;
break;
}
}
id = "parameter.hyper" + parent.getClass().getSimpleName() + "-" + m_input.getName() + "-" + grandparent.getID();
doc.pluginmap.remove(parameter2.getID());
parameter2.setID(id);
doc.addPlugin(parameter2);
}
PartitionContext context = new PartitionContext(id.substring("parameter.".length()));
Log.warning.println(context + " " + id);
doc.beautiConfig.hyperPriorTemplate.createSubNet(context, true);
}
refreshPanel();
} catch (Exception ex) {
Log.err.println("ParameterInputEditor " + ex.getMessage());
}
});
paramBox.add(m_isEstimatedBox);
// only show the estimate flag if there is an operator that works on this parameter
m_isEstimatedBox.setVisible(doc.isExpertMode());
m_isEstimatedBox.setToolTipText("Estimate value of this parameter in the MCMC chain");
// m_bAddButtons = false;
if (itemNr < 0) {
for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
if (beastObject2 instanceof ParametricDistribution) {
m_isEstimatedBox.setVisible(true);
isParametricDistributionParameter = true;
break;
}
}
for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
if (beastObject2 instanceof Operator) {
m_isEstimatedBox.setVisible(true);
// m_editPluginButton.setVisible(true);
break;
}
}
} else {
for (Object beastObject2 : ((BEASTInterface) ((List<?>) m_input.get()).get(itemNr)).getOutputs()) {
if (beastObject2 instanceof Operator) {
m_isEstimatedBox.setVisible(true);
// m_editPluginButton.setVisible(true);
break;
}
}
}
box.add(paramBox);
}
}
use of beast.core.Operator in project MultiTypeTree by tgvaughan.
the class NSR_Test method test.
@Test
public void test() throws Exception {
System.out.println("NSR test");
// Fix seed.
Randomizer.setSeed(42);
// Assemble migration model:
RealParameter rateMatrix = new RealParameter("0.1 0.1");
RealParameter popSizes = new RealParameter("7.0 7.0");
SCMigrationModel migModel = new SCMigrationModel();
migModel.initByName("rateMatrix", rateMatrix, "popSizes", popSizes, "typeSet", new TypeSet("A", "B"));
// Assemble initial MultiTypeTree
MultiTypeTree mtTree = new StructuredCoalescentMultiTypeTree();
mtTree.initByName("typeLabel", "deme", "migrationModel", migModel, "leafTypes", "1 0");
// Set up state:
State state = new State();
state.initByName("stateNode", mtTree);
// Assemble distribution:
StructuredCoalescentTreeDensity distribution = new StructuredCoalescentTreeDensity();
distribution.initByName("migrationModel", migModel, "multiTypeTree", mtTree);
// Set up operators:
Operator operatorNSR = new NodeShiftRetype();
operatorNSR.initByName("weight", 1.0, "multiTypeTree", mtTree, "migrationModel", migModel);
// Set up stat analysis logger:
MultiTypeTreeStatLogger logger = new MultiTypeTreeStatLogger();
logger.initByName("multiTypeTree", mtTree, "burninFrac", 0.1, "logEvery", 100);
// Set up MCMC:
MCMC mcmc = new MCMC();
mcmc.initByName("chainLength", "1000000", "state", state, "distribution", distribution, "operator", operatorNSR, "logger", logger);
// Run MCMC:
mcmc.run();
System.out.format("height mean = %s\n", logger.getHeightMean());
System.out.format("height var = %s\n", logger.getHeightVar());
System.out.format("height ESS = %s\n", logger.getHeightESS());
// Compare analysis results with truth:
boolean withinTol = (logger.getHeightESS() > 2000) && (Math.abs(logger.getHeightMean() - 19.0) < 0.5) && (Math.abs(logger.getHeightVar() - 291) < 30);
Assert.assertTrue(withinTol);
}
Aggregations