use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class HierarchicalPriorDialog method showDialog.
public int showDialog(final java.util.List<Parameter> parameterList) {
this.parameterList = parameterList;
this.parameter = parameterList.get(0);
PriorType priorType = parameter.priorType;
// Set-up combo box depending on parameters
priorCombo.removeAllItems();
if (parameter.isNonNegative) {
priorCombo.addItem(PriorType.LOGNORMAL_HPM_PRIOR);
}
priorCombo.addItem(PriorType.NORMAL_HPM_PRIOR);
priorCombo.setSelectedItem(priorType);
double lower = Double.NEGATIVE_INFINITY;
double upper = Double.POSITIVE_INFINITY;
if (parameter.isZeroOne) {
lower = 0.0;
upper = 1.0;
} else if (parameter.isNonNegative) {
lower = 0.0;
}
initialField.setRange(lower, upper);
initialField.setValue(parameter.getInitial());
panel = new JPanel(new GridBagLayout());
setupComponents();
JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(null);
scrollPane.getViewport().setOpaque(false);
JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
final JDialog dialog = optionPane.createDialog(frame, "Phylogenetic Hierarchical Model Setup");
priorCombo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setupComponents();
dialog.validate();
dialog.repaint();
dialog.pack();
}
});
for (PriorOptionsPanel optionsPanel : optionsPanels.values()) {
optionsPanel.addListener(new PriorOptionsPanel.Listener() {
public void optionsPanelChanged() {
setupChart();
dialog.validate();
dialog.repaint();
}
});
}
dialog.pack();
if (OSType.isMac()) {
dialog.setMinimumSize(new Dimension(dialog.getBounds().width, 300));
} else {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
if (d.height < 700 && panel.getHeight() > 450) {
dialog.setSize(new Dimension(panel.getWidth() + 100, 550));
} else {
// setSize because optionsPanel is shrunk in dialog
dialog.setSize(new Dimension(panel.getWidth() + 100, panel.getHeight() + 100));
}
// System.out.println("panel width = " + panel.getWidth());
// System.out.println("panel height = " + panel.getHeight());
}
dialog.setResizable(true);
dialog.setVisible(true);
int result = JOptionPane.CANCEL_OPTION;
Integer value = (Integer) optionPane.getValue();
if (value != null && value != -1) {
result = value;
}
return result;
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method setParameter.
/**
* Set the parameter to be controlled
* q
* @param parameter
*/
public void setParameter(final Parameter parameter) {
this.parameter = parameter;
priorCombo = new JComboBox();
for (PriorType priorType : PriorType.getPriorTypes(parameter)) {
priorCombo.addItem(priorType);
}
if (parameter.priorType != null) {
priorCombo.setSelectedItem(parameter.priorType);
}
// setArguments here
setupComponents();
priorCombo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setupComponents();
dialog.pack();
dialog.repaint();
}
});
for (PriorOptionsPanel optionsPanel : optionsPanels.values()) {
optionsPanel.removeAllListeners();
optionsPanel.addListener(new PriorOptionsPanel.Listener() {
public void optionsPanelChanged() {
setupChart();
dialog.pack();
dialog.repaint();
}
});
}
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method setupComponents.
private void setupComponents() {
removeAll();
OptionsPanel optionsPanel = new OptionsPanel(12, (OSType.isMac() ? 6 : 24));
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
panel1.add(optionsPanel);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.PAGE_START;
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(panel1, gbc);
PriorType priorType = (PriorType) priorCombo.getSelectedItem();
if (!parameter.isPriorFixed) {
optionsPanel.addComponentWithLabel("Prior Distribution: ", priorCombo);
} else {
optionsPanel.addComponentWithLabel("Prior Distribution: ", new JLabel(priorType.toString()));
}
PriorOptionsPanel panel3 = optionsPanels.get(priorType);
if (panel3 != null) {
// important to make init field appear during switch
panel3.setArguments(parameter, priorType);
optionsPanel.addSpanningComponent(panel3);
}
if (priorType == PriorType.CTMC_RATE_REFERENCE_PRIOR) {
optionsPanel.addSpanningComponent(citationText);
}
if (priorType == PriorType.ONE_OVER_X_PRIOR) {
optionsPanel.addSpanningComponent(oneOverXCaution);
}
if (priorType == PriorType.NONE_IMPROPER) {
optionsPanel.addSpanningComponent(improperCaution);
}
if (priorType.isPlottable()) {
optionsPanel.addSeparator();
setupChart();
chart.setMinimumSize(new Dimension(120, 120));
chart.setPreferredSize(new Dimension(300, 200));
chart.setFontSize(8);
gbc.gridy = 1;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(chart, gbc);
gbc.gridy = 2;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.PAGE_END;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(quantilePanel, gbc);
}
repaint();
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method hasInvalidInput.
public boolean hasInvalidInput(boolean showError) {
PriorType priorType = (PriorType) priorCombo.getSelectedItem();
PriorOptionsPanel panel = optionsPanels.get(priorType);
if (panel != null) {
if (panel.hasInvalidInput(priorType)) {
if (showError)
JOptionPane.showMessageDialog(frame, panel.error, "Invalid input", JOptionPane.ERROR_MESSAGE);
return true;
} else {
return false;
}
}
// if there is no panel for this prior type then assume it is valid
return false;
// throw new IllegalComponentStateException("Cannot get PriorOptionsPanel");
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method setupChart.
void setupChart() {
chart.removeAllPlots();
if (hasInvalidInput(false)) {
quantileText.setText("Invalid input");
return;
}
PriorType priorType = (PriorType) priorCombo.getSelectedItem();
if (priorType == null) {
priorType = parameter.priorType;
priorCombo.setSelectedItem(priorType);
}
// ExponentialDistribution(1.0 / mean)
// if (priorType == PriorType.EXPONENTIAL_PRIOR && parameter.mean == 0) parameter.mean = 1;
PriorOptionsPanel priorOptionsPanel = optionsPanels.get(priorType);
// TODO is this used or duplicated to OffsetPositiveDistribution?
double offset = 0.0;
// this does not refresh dist from parameter truncation lower/upper, it get them from GUI
Distribution distribution = priorOptionsPanel.getDistribution(parameter);
chart.addPlot(new PDFPlot(distribution, offset));
if (distribution != null) {
quantileText.setText(formatter.format(distribution.quantile(0.025)) + "\n" + formatter.format(distribution.quantile(0.05)) + "\n" + formatter.format(distribution.quantile(0.5)) + "\n" + formatter.format(distribution.quantile(0.95)) + "\n" + formatter.format(distribution.quantile(0.975)));
}
}
Aggregations