Debian Codegraph @

src/dr/app/beauti/components/marginalLikelihoodEstimation/MLEDialog.java

raw symbols SCIP
1 /*
2 * MLEDialog.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti.components.marginalLikelihoodEstimation;
27
28 import dr.app.beauti.util.PanelUtils;
29 import dr.app.gui.components.WholeNumberField;
30 import jam.panels.OptionsPanel;
31
32 import javax.swing.*;
33 import javax.swing.border.EmptyBorder;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.KeyEvent;
36
37
38 /**
39 * @author Guy Baele
40 */
41 public class MLEDialog {
42
43 private JFrame frame;
44
45 private final OptionsPanel optionsPanel;
46
47 private JLabel labelPathSteps, labelChainLength, labelLogEvery, labelLogFileName, labelResultFileName, labelStepDistribution;
48
49 private WholeNumberField pathStepsField = new WholeNumberField(1, Integer.MAX_VALUE);
50 private WholeNumberField chainLengthField = new WholeNumberField(1, Integer.MAX_VALUE);
51 private WholeNumberField logEveryField = new WholeNumberField(1, Integer.MAX_VALUE);
52
53 private JTextArea logFileNameField = new JTextArea("mle.log");
54 private JTextArea resultFileNameField = new JTextArea("mle.result.log");
55
56 JCheckBox operatorAnalysis = new JCheckBox("Print operator analysis");
57
58 private JComboBox stepDistribution = new JComboBox();
59
60 private MarginalLikelihoodEstimationOptions options;
61
62 private String description = "Settings for marginal likelihood estimation using PS/SS";
63
64 public MLEDialog(final JFrame frame, final MarginalLikelihoodEstimationOptions options) {
65 this.frame = frame;
66 this.options = options;
67
68 optionsPanel = new OptionsPanel(12, 12);
69
70 optionsPanel.setOpaque(false);
71
72 JTextArea mleInfo = new JTextArea("Set the options to perform marginal likelihood " +
73 "estimation (MLE) using path sampling (PS) / stepping-stone sampling (SS).");
74 mleInfo.setColumns(56);
75 PanelUtils.setupComponent(mleInfo);
76 optionsPanel.addSpanningComponent(mleInfo);
77
78 pathStepsField.setValue(options.pathSteps);
79 pathStepsField.setColumns(16);
80 pathStepsField.setMinimumSize(pathStepsField.getPreferredSize());
81 labelPathSteps = optionsPanel.addComponentWithLabel("Number of path steps:", pathStepsField);
82 pathStepsField.addKeyListener(new java.awt.event.KeyListener() {
83 public void keyTyped(KeyEvent e) {
84 }
85
86 public void keyPressed(KeyEvent e) {
87 }
88
89 public void keyReleased(KeyEvent e) {
90 options.pathSteps = pathStepsField.getValue();
91 }
92 });
93
94 chainLengthField.setValue(options.mleChainLength);
95 chainLengthField.setColumns(16);
96 chainLengthField.setMinimumSize(chainLengthField.getPreferredSize());
97 labelChainLength = optionsPanel.addComponentWithLabel("Length of chains:", chainLengthField);
98 chainLengthField.addKeyListener(new java.awt.event.KeyListener() {
99 public void keyTyped(KeyEvent e) {
100 }
101
102 public void keyPressed(KeyEvent e) {
103 }
104
105 public void keyReleased(KeyEvent e) {
106 options.mleChainLength = chainLengthField.getValue();
107 }
108 });
109
110 optionsPanel.addSeparator();
111
112 logEveryField.setValue(options.mleLogEvery);
113 logEveryField.setColumns(16);
114 logEveryField.setMinimumSize(logEveryField.getPreferredSize());
115 labelLogEvery = optionsPanel.addComponentWithLabel("Log likelihood every:", logEveryField);
116 logEveryField.addKeyListener(new java.awt.event.KeyListener() {
117 public void keyTyped(KeyEvent e) {
118 }
119
120 public void keyPressed(KeyEvent e) {
121 }
122
123 public void keyReleased(KeyEvent e) {
124 options.mleLogEvery = logEveryField.getValue();
125 }
126 });
127
128 optionsPanel.addSeparator();
129
130 logFileNameField.setColumns(32);
131 logFileNameField.setEditable(false);
132 logFileNameField.setMinimumSize(logFileNameField.getPreferredSize());
133 labelLogFileName = optionsPanel.addComponentWithLabel("Log file name:", logFileNameField);
134 logFileNameField.addKeyListener(new java.awt.event.KeyListener() {
135 public void keyTyped(KeyEvent e) {
136 }
137
138 public void keyPressed(KeyEvent e) {
139 }
140
141 public void keyReleased(KeyEvent e) {
142 options.mleFileName = logFileNameField.getText();
143 }
144 });
145
146 optionsPanel.addSeparator();
147
148 resultFileNameField.setColumns(32);
149 resultFileNameField.setEditable(false);
150 resultFileNameField.setMinimumSize(resultFileNameField.getPreferredSize());
151 labelResultFileName = optionsPanel.addComponentWithLabel("Results file name:", resultFileNameField);
152 resultFileNameField.addKeyListener(new java.awt.event.KeyListener() {
153 public void keyTyped(KeyEvent e) {
154 }
155
156 public void keyPressed(KeyEvent e) {
157 }
158
159 public void keyReleased(KeyEvent e) {
160 options.mleResultFileName = resultFileNameField.getText();
161 }
162 });
163
164 optionsPanel.addSeparator();
165
166 JTextArea betaInfo = new JTextArea("By default, the power posteriors are determined according to " +
167 "evenly spaced quantiles of a Beta(0.3, 1.0) distribution, thereby estimating " +
168 "more power posteriors close to the prior.");
169 betaInfo.setColumns(56);
170 PanelUtils.setupComponent(betaInfo);
171 optionsPanel.addSpanningComponent(betaInfo);
172
173 stepDistribution.addItem("Beta");
174 labelStepDistribution = optionsPanel.addComponentWithLabel("Path step distribution:", stepDistribution);
175
176 optionsPanel.addSeparator();
177
178 operatorAnalysis.setSelected(options.printOperatorAnalysis);
179 optionsPanel.addComponent(operatorAnalysis);
180
181 operatorAnalysis.addActionListener(new java.awt.event.ActionListener() {
182 public void actionPerformed(ActionEvent e) {
183 if (operatorAnalysis.isSelected()) {
184 options.printOperatorAnalysis = true;
185 } else {
186 options.printOperatorAnalysis = false;
187 }
188 }
189 });
190
191 optionsPanel.addSeparator();
192
193 JTextArea mleTutorial = new JTextArea("Additional information on marginal likelihood estimation in BEAST " +
194 "can be found on http://beast.community/model_selection");
195 mleTutorial.setColumns(56);
196 PanelUtils.setupComponent(mleTutorial);
197 optionsPanel.addSpanningComponent(mleTutorial);
198
199 JTextArea citationText = new JTextArea("Baele G, Lemey P, Bedford T, Rambaut A, Suchard MA, Alekseyenko AV (2012)\n" +
200 "Mol Biol Evol 29(9), 2157-2167 [Advantages of PS/SS].\n" +
201 "Baele G, Li WLS, Drummond AJ, Suchard MA, Lemey P (2013)\nMol Biol Evol 30(2), 239-243 " +
202 "[Importance of using proper priors].");
203 citationText.setColumns(45);
204 optionsPanel.addComponentWithLabel("Citation:", citationText);
205
206 optionsPanel.addSeparator();
207
208 /*JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
209 panel.add(optionsPanel, BorderLayout.CENTER);
210 panel.setOpaque(false);
211
212 JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
213 scrollPane.setOpaque(false);
214 scrollPane.setBorder(null);
215 scrollPane.getViewport().setOpaque(false);
216
217 add(scrollPane, BorderLayout.CENTER);*/
218
219 }
220
221 public int showDialog() {
222
223 JOptionPane optionPane = new JOptionPane(optionsPanel,
224 JOptionPane.QUESTION_MESSAGE,
225 JOptionPane.OK_CANCEL_OPTION,
226 null,
227 null,
228 null);
229 optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
230
231 final JDialog dialog = optionPane.createDialog(frame, description);
232 dialog.pack();
233
234 dialog.setVisible(true);
235
236 int result = JOptionPane.CANCEL_OPTION;
237 Integer value = (Integer) optionPane.getValue();
238 if (value != null && value != -1) {
239 result = value;
240 }
241
242 return result;
243 }
244
245 /*public JComponent getExportableComponent() {
246 return optionsPanel;
247 }*/
248
249 public void setFilenameStem(String fileNameStem, boolean addTxt) {
250 logFileNameField.setText(fileNameStem + ".mle.log" + (addTxt ? ".txt" : ""));
251 resultFileNameField.setText(fileNameStem + ".mle.result.log" + (addTxt ? ".txt" : ""));
252 options.mleFileName = logFileNameField.getText();
253 options.mleResultFileName = resultFileNameField.getText();
254 }
255
256 public void setOptions(MarginalLikelihoodEstimationOptions options) {
257 //this.options = options;
258
259 /*System.err.println("setOptions: " + options);
260 System.err.println("options.pathSteps: " + options.pathSteps);
261 System.err.println("options.mleChainLength: " + options.mleChainLength);
262 System.err.println("options.mleLogEvery: " + options.mleLogEvery);*/
263
264 pathStepsField.setValue(options.pathSteps);
265 chainLengthField.setValue(options.mleChainLength);
266 logEveryField.setValue(options.mleLogEvery);
267
268 logFileNameField.setText(options.mleFileName);
269 resultFileNameField.setText(options.mleResultFileName);
270
271 operatorAnalysis.setSelected(options.printOperatorAnalysis);
272
273 optionsPanel.validate();
274 optionsPanel.repaint();
275 }
276
277 public void getOptions(MarginalLikelihoodEstimationOptions options) {
278 //this.options = options;
279
280 options.pathSteps = pathStepsField.getValue();
281 options.mleChainLength = chainLengthField.getValue();
282 options.mleLogEvery = logEveryField.getValue();
283
284 options.printOperatorAnalysis = operatorAnalysis.isSelected();
285
286 options.mleFileName = logFileNameField.getText();
287 options.mleResultFileName = resultFileNameField.getText();
288
289 /*System.err.println("getOptions: " + options);
290 System.err.println("options.pathSteps: " + options.pathSteps);
291 System.err.println("options.mleChainLength: " + options.mleChainLength);
292 System.err.println("options.mleLogEvery: " + options.mleLogEvery);*/
293
294 }
295
296 }