2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
* SimpleSetupPanel.java
19
* Copyright (C) 2002 University of Waikato, Hamilton, New Zealand
23
package weka.gui.experiment;
25
import weka.classifiers.Classifier;
26
import weka.core.xml.KOML;
27
import weka.experiment.CSVResultListener;
28
import weka.experiment.ClassifierSplitEvaluator;
29
import weka.experiment.CrossValidationResultProducer;
30
import weka.experiment.DatabaseResultListener;
31
import weka.experiment.Experiment;
32
import weka.experiment.InstancesResultListener;
33
import weka.experiment.PropertyNode;
34
import weka.experiment.RandomSplitResultProducer;
35
import weka.experiment.RegressionSplitEvaluator;
36
import weka.experiment.SplitEvaluator;
37
import weka.experiment.xml.XMLExperiment;
38
import weka.gui.DatabaseConnectionDialog;
39
import weka.gui.ExtensionFileFilter;
41
import java.awt.BorderLayout;
42
import java.awt.GridBagConstraints;
43
import java.awt.GridBagLayout;
44
import java.awt.GridLayout;
45
import java.awt.Insets;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import java.awt.event.FocusAdapter;
49
import java.awt.event.FocusEvent;
50
import java.awt.event.KeyAdapter;
51
import java.awt.event.KeyEvent;
52
import java.awt.event.WindowAdapter;
53
import java.awt.event.WindowEvent;
54
import java.beans.IntrospectionException;
55
import java.beans.PropertyChangeListener;
56
import java.beans.PropertyChangeSupport;
57
import java.beans.PropertyDescriptor;
58
import java.io.BufferedInputStream;
59
import java.io.BufferedOutputStream;
61
import java.io.FileInputStream;
62
import java.io.FileOutputStream;
63
import java.io.ObjectInputStream;
64
import java.io.ObjectOutputStream;
66
import javax.swing.BorderFactory;
67
import javax.swing.ButtonGroup;
68
import javax.swing.JButton;
69
import javax.swing.JComboBox;
70
import javax.swing.JFileChooser;
71
import javax.swing.JFrame;
72
import javax.swing.JLabel;
73
import javax.swing.JOptionPane;
74
import javax.swing.JPanel;
75
import javax.swing.JRadioButton;
76
import javax.swing.JScrollPane;
77
import javax.swing.JTextArea;
78
import javax.swing.JTextField;
79
import javax.swing.event.DocumentEvent;
80
import javax.swing.event.DocumentListener;
81
import javax.swing.filechooser.FileFilter;
84
* This panel controls the configuration of an experiment.
86
* If <a href="http://koala.ilog.fr/XML/serialization/" target="_blank">KOML</a>
87
* is in the classpath the experiments can also be serialized to XML instead of a
90
* @author Richard kirkby (rkirkby@cs.waikato.ac.nz)
91
* @author FracPete (fracpete at waikato dot ac dot nz)
92
* @version $Revision: 1.14 $
94
public class SimpleSetupPanel
97
/** for serialization */
98
private static final long serialVersionUID = 5257424515609176509L;
100
/** The experiment being configured */
101
protected Experiment m_Exp;
103
/** The panel which switched between simple and advanced setup modes */
104
protected SetupModePanel m_modePanel = null;
106
/** The database destination URL to store results into */
107
protected String m_destinationDatabaseURL;
109
/** The filename to store results into */
110
protected String m_destinationFilename = "";
112
/** The number of folds for a cross-validation experiment */
113
protected int m_numFolds = 10;
115
/** The training percentage for a train/test split experiment */
116
protected double m_trainPercent = 66;
118
/** The number of times to repeat the sub-experiment */
119
protected int m_numRepetitions = 10;
121
/** Whether or not the user has consented for the experiment to be simplified */
122
protected boolean m_userHasBeenAskedAboutConversion;
124
/** Filter for choosing CSV files */
125
protected ExtensionFileFilter m_csvFileFilter =
126
new ExtensionFileFilter(".csv", "Comma separated value files");
128
/** FIlter for choosing ARFF files */
129
protected ExtensionFileFilter m_arffFileFilter =
130
new ExtensionFileFilter(".arff", "ARFF files");
132
/** Click to load an experiment */
133
protected JButton m_OpenBut = new JButton("Open...");
135
/** Click to save an experiment */
136
protected JButton m_SaveBut = new JButton("Save...");
138
/** Click to create a new experiment with default settings */
139
protected JButton m_NewBut = new JButton("New");
141
/** A filter to ensure only experiment files get shown in the chooser */
142
protected FileFilter m_ExpFilter =
143
new ExtensionFileFilter(Experiment.FILE_EXTENSION,
144
"Experiment configuration files (*" + Experiment.FILE_EXTENSION + ")");
146
/** A filter to ensure only experiment (in KOML format) files get shown in the chooser */
147
protected FileFilter m_KOMLFilter =
148
new ExtensionFileFilter(KOML.FILE_EXTENSION,
149
"Experiment configuration files (*" + KOML.FILE_EXTENSION + ")");
151
/** A filter to ensure only experiment (in XML format) files get shown in the chooser */
152
protected FileFilter m_XMLFilter =
153
new ExtensionFileFilter(".xml",
154
"Experiment configuration files (*.xml)");
156
/** The file chooser for selecting experiments */
157
protected JFileChooser m_FileChooser =
158
new JFileChooser(new File(System.getProperty("user.dir")));
160
/** The file chooser for selecting result destinations */
161
protected JFileChooser m_DestFileChooser =
162
new JFileChooser(new File(System.getProperty("user.dir")));
164
/** Combo box for choosing experiment destination type */
165
protected JComboBox m_ResultsDestinationCBox = new JComboBox();
167
/** Label for destination field */
168
protected JLabel m_ResultsDestinationPathLabel = new JLabel("Filename:");
170
/** Input field for result destination path */
171
protected JTextField m_ResultsDestinationPathTField = new JTextField();
173
/** Button for browsing destination files */
174
protected JButton m_BrowseDestinationButton = new JButton("Browse...");
176
/** Combo box for choosing experiment type */
177
protected JComboBox m_ExperimentTypeCBox = new JComboBox();
179
/** Label for parameter field */
180
protected JLabel m_ExperimentParameterLabel = new JLabel("Number of folds:");
182
/** Input field for experiment parameter */
183
protected JTextField m_ExperimentParameterTField = new JTextField();
185
/** Radio button for choosing classification experiment */
186
protected JRadioButton m_ExpClassificationRBut =
187
new JRadioButton("Classification");
189
/** Radio button for choosing regression experiment */
190
protected JRadioButton m_ExpRegressionRBut =
191
new JRadioButton("Regression");
193
/** Input field for number of repetitions */
194
protected JTextField m_NumberOfRepetitionsTField = new JTextField();
196
/** Radio button for choosing datasets first in order of execution */
197
protected JRadioButton m_OrderDatasetsFirstRBut =
198
new JRadioButton("Data sets first");
200
/** Radio button for choosing algorithms first in order of execution */
201
protected JRadioButton m_OrderAlgorithmsFirstRBut =
202
new JRadioButton("Algorithms first");
204
/** The strings used to identify the combo box choices */
205
protected static String DEST_DATABASE_TEXT = ("JDBC database");
206
protected static String DEST_ARFF_TEXT = ("ARFF file");
207
protected static String DEST_CSV_TEXT = ("CSV file");
208
protected static String TYPE_CROSSVALIDATION_TEXT = ("Cross-validation");
209
protected static String TYPE_RANDOMSPLIT_TEXT = ("Train/Test Percentage Split (data randomized)");
210
protected static String TYPE_FIXEDSPLIT_TEXT = ("Train/Test Percentage Split (order preserved)");
212
/** The panel for configuring selected datasets */
213
protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel();
215
/** The panel for configuring selected algorithms */
216
protected AlgorithmListPanel m_AlgorithmListPanel = new AlgorithmListPanel();
218
/** A button for bringing up the notes */
219
protected JButton m_NotesButton = new JButton("Notes");
221
/** Frame for the notes */
222
protected JFrame m_NotesFrame = new JFrame("Notes");
224
/** Area for user notes Default of 10 rows */
225
protected JTextArea m_NotesText = new JTextArea(null, 10, 0);
228
* Manages sending notifications to people when we change the experiment,
229
* at this stage, only the resultlistener so the resultpanel can update.
231
protected PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
234
* Creates the setup panel with the supplied initial experiment.
236
* @param exp a value of type 'Experiment'
238
public SimpleSetupPanel(Experiment exp) {
245
* Creates the setup panel with no initial experiment.
247
public SimpleSetupPanel() {
249
// everything disabled on startup
250
m_ResultsDestinationCBox.setEnabled(false);
251
m_ResultsDestinationPathLabel.setEnabled(false);
252
m_ResultsDestinationPathTField.setEnabled(false);
253
m_BrowseDestinationButton.setEnabled(false);
254
m_ExperimentTypeCBox.setEnabled(false);
255
m_ExperimentParameterLabel.setEnabled(false);
256
m_ExperimentParameterTField.setEnabled(false);
257
m_ExpClassificationRBut.setEnabled(false);
258
m_ExpRegressionRBut.setEnabled(false);
259
m_NumberOfRepetitionsTField.setEnabled(false);
260
m_OrderDatasetsFirstRBut.setEnabled(false);
261
m_OrderAlgorithmsFirstRBut.setEnabled(false);
263
// get sensible default database address
265
m_destinationDatabaseURL = (new DatabaseResultListener()).getDatabaseURL();
266
} catch (Exception e) {}
268
// create action listeners
269
m_NewBut.setMnemonic('N');
270
m_NewBut.addActionListener(new ActionListener() {
271
public void actionPerformed(ActionEvent e) {
272
Experiment newExp = new Experiment();
273
CrossValidationResultProducer cvrp = new CrossValidationResultProducer();
274
cvrp.setNumFolds(10);
275
cvrp.setSplitEvaluator(new ClassifierSplitEvaluator());
276
newExp.setResultProducer(cvrp);
277
newExp.setPropertyArray(new Classifier[0]);
278
newExp.setUsePropertyIterator(true);
279
setExperiment(newExp);
282
if (ExperimenterDefaults.getUseClassification())
283
m_ExpClassificationRBut.setSelected(true);
285
m_ExpRegressionRBut.setSelected(true);
288
m_ResultsDestinationCBox, ExperimenterDefaults.getDestination());
289
destinationTypeChanged();
292
m_ExperimentTypeCBox, ExperimenterDefaults.getExperimentType());
294
m_numRepetitions = ExperimenterDefaults.getRepetitions();
295
m_NumberOfRepetitionsTField.setText(
296
"" + m_numRepetitions);
298
if (ExperimenterDefaults.getExperimentType().equals(
299
TYPE_CROSSVALIDATION_TEXT)) {
300
m_numFolds = ExperimenterDefaults.getFolds();
301
m_ExperimentParameterTField.setText(
305
m_trainPercent = ExperimenterDefaults.getTrainPercentage();
306
m_ExperimentParameterTField.setText(
307
"" + m_trainPercent);
310
if (ExperimenterDefaults.getDatasetsFirst())
311
m_OrderDatasetsFirstRBut.setSelected(true);
313
m_OrderAlgorithmsFirstRBut.setSelected(true);
318
m_SaveBut.setEnabled(false);
319
m_SaveBut.setMnemonic('S');
320
m_SaveBut.addActionListener(new ActionListener() {
321
public void actionPerformed(ActionEvent e) {
325
m_OpenBut.setMnemonic('O');
326
m_OpenBut.addActionListener(new ActionListener() {
327
public void actionPerformed(ActionEvent e) {
331
m_FileChooser.addChoosableFileFilter(m_ExpFilter);
332
if (KOML.isPresent())
333
m_FileChooser.addChoosableFileFilter(m_KOMLFilter);
334
m_FileChooser.addChoosableFileFilter(m_XMLFilter);
335
if (ExperimenterDefaults.getExtension().equals(".xml"))
336
m_FileChooser.setFileFilter(m_XMLFilter);
337
else if (KOML.isPresent() && ExperimenterDefaults.getExtension().equals(KOML.FILE_EXTENSION))
338
m_FileChooser.setFileFilter(m_KOMLFilter);
340
m_FileChooser.setFileFilter(m_ExpFilter);
341
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
342
m_DestFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
344
m_BrowseDestinationButton.addActionListener(new ActionListener() {
345
public void actionPerformed(ActionEvent e) {
346
//using this button for both browsing file & setting username/password
347
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT){
350
chooseDestinationFile();
355
m_ExpClassificationRBut.addActionListener(new ActionListener() {
356
public void actionPerformed(ActionEvent e) {
361
m_ExpRegressionRBut.addActionListener(new ActionListener() {
362
public void actionPerformed(ActionEvent e) {
367
m_OrderDatasetsFirstRBut.addActionListener(new ActionListener() {
368
public void actionPerformed(ActionEvent e) {
370
m_Exp.setAdvanceDataSetFirst(true);
371
m_Support.firePropertyChange("", null, null);
376
m_OrderAlgorithmsFirstRBut.addActionListener(new ActionListener() {
377
public void actionPerformed(ActionEvent e) {
379
m_Exp.setAdvanceDataSetFirst(false);
380
m_Support.firePropertyChange("", null, null);
385
m_ResultsDestinationPathTField.getDocument().addDocumentListener(new DocumentListener() {
386
public void insertUpdate(DocumentEvent e) {destinationAddressChanged();}
387
public void removeUpdate(DocumentEvent e) {destinationAddressChanged();}
388
public void changedUpdate(DocumentEvent e) {destinationAddressChanged();}
391
m_ExperimentParameterTField.getDocument().addDocumentListener(new DocumentListener() {
392
public void insertUpdate(DocumentEvent e) {expParamChanged();}
393
public void removeUpdate(DocumentEvent e) {expParamChanged();}
394
public void changedUpdate(DocumentEvent e) {expParamChanged();}
397
m_NumberOfRepetitionsTField.getDocument().addDocumentListener(new DocumentListener() {
398
public void insertUpdate(DocumentEvent e) {numRepetitionsChanged();}
399
public void removeUpdate(DocumentEvent e) {numRepetitionsChanged();}
400
public void changedUpdate(DocumentEvent e) {numRepetitionsChanged();}
403
m_NotesFrame.addWindowListener(new WindowAdapter() {
404
public void windowClosing(WindowEvent e) {
405
m_NotesButton.setEnabled(true);
408
m_NotesFrame.getContentPane().add(new JScrollPane(m_NotesText));
409
m_NotesFrame.setSize(600, 400);
411
m_NotesButton.addActionListener(new ActionListener() {
412
public void actionPerformed(ActionEvent e) {
413
m_NotesButton.setEnabled(false);
414
m_NotesFrame.setVisible(true);
417
m_NotesButton.setEnabled(false);
419
m_NotesText.setEditable(true);
420
//m_NotesText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
421
m_NotesText.addKeyListener(new KeyAdapter() {
422
public void keyReleased(KeyEvent e) {
423
m_Exp.setNotes(m_NotesText.getText());
426
m_NotesText.addFocusListener(new FocusAdapter() {
427
public void focusLost(FocusEvent e) {
428
m_Exp.setNotes(m_NotesText.getText());
432
// Set up the GUI layout
433
JPanel buttons = new JPanel();
434
GridBagLayout gb = new GridBagLayout();
435
GridBagConstraints constraints = new GridBagConstraints();
436
buttons.setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
437
buttons.setLayout(gb);
438
constraints.gridx=0;constraints.gridy=0;constraints.weightx=5;
439
constraints.fill = GridBagConstraints.HORIZONTAL;
440
constraints.gridwidth=1;constraints.gridheight=1;
441
constraints.insets = new Insets(0,2,0,2);
442
buttons.add(m_OpenBut,constraints);
443
constraints.gridx=1;constraints.gridy=0;constraints.weightx=5;
444
constraints.gridwidth=1;constraints.gridheight=1;
445
buttons.add(m_SaveBut,constraints);
446
constraints.gridx=2;constraints.gridy=0;constraints.weightx=5;
447
constraints.gridwidth=1;constraints.gridheight=1;
448
buttons.add(m_NewBut,constraints);
450
JPanel destName = new JPanel();
451
destName.setLayout(new BorderLayout(5, 5));
452
destName.add(m_ResultsDestinationPathLabel, BorderLayout.WEST);
453
destName.add(m_ResultsDestinationPathTField, BorderLayout.CENTER);
455
m_ResultsDestinationCBox.addItem(DEST_ARFF_TEXT);
456
m_ResultsDestinationCBox.addItem(DEST_CSV_TEXT);
457
m_ResultsDestinationCBox.addItem(DEST_DATABASE_TEXT);
459
m_ResultsDestinationCBox.addActionListener(new ActionListener() {
460
public void actionPerformed(ActionEvent e) {
461
destinationTypeChanged();
465
JPanel destInner = new JPanel();
466
destInner.setLayout(new BorderLayout(5, 5));
467
destInner.add(m_ResultsDestinationCBox, BorderLayout.WEST);
468
destInner.add(destName, BorderLayout.CENTER);
469
destInner.add(m_BrowseDestinationButton, BorderLayout.EAST);
471
JPanel dest = new JPanel();
472
dest.setLayout(new BorderLayout());
473
dest.setBorder(BorderFactory.createCompoundBorder(
474
BorderFactory.createTitledBorder("Results Destination"),
475
BorderFactory.createEmptyBorder(0, 5, 5, 5)
477
dest.add(destInner, BorderLayout.NORTH);
479
JPanel expParam = new JPanel();
480
expParam.setLayout(new BorderLayout(5, 5));
481
expParam.add(m_ExperimentParameterLabel, BorderLayout.WEST);
482
expParam.add(m_ExperimentParameterTField, BorderLayout.CENTER);
484
ButtonGroup typeBG = new ButtonGroup();
485
typeBG.add(m_ExpClassificationRBut);
486
typeBG.add(m_ExpRegressionRBut);
487
m_ExpClassificationRBut.setSelected(true);
489
JPanel typeRButtons = new JPanel();
490
typeRButtons.setLayout(new GridLayout(1,0));
491
typeRButtons.add(m_ExpClassificationRBut);
492
typeRButtons.add(m_ExpRegressionRBut);
494
m_ExperimentTypeCBox.addItem(TYPE_CROSSVALIDATION_TEXT);
495
m_ExperimentTypeCBox.addItem(TYPE_RANDOMSPLIT_TEXT);
496
m_ExperimentTypeCBox.addItem(TYPE_FIXEDSPLIT_TEXT);
498
m_ExperimentTypeCBox.addActionListener(new ActionListener() {
499
public void actionPerformed(ActionEvent e) {
504
JPanel typeInner = new JPanel();
505
typeInner.setLayout(new GridLayout(0,1));
506
typeInner.add(m_ExperimentTypeCBox);
507
typeInner.add(expParam);
508
typeInner.add(typeRButtons);
510
JPanel type = new JPanel();
511
type.setLayout(new BorderLayout());
512
type.setBorder(BorderFactory.createCompoundBorder(
513
BorderFactory.createTitledBorder("Experiment Type"),
514
BorderFactory.createEmptyBorder(0, 5, 5, 5)
516
type.add(typeInner, BorderLayout.NORTH);
518
ButtonGroup iterBG = new ButtonGroup();
519
iterBG.add(m_OrderDatasetsFirstRBut);
520
iterBG.add(m_OrderAlgorithmsFirstRBut);
521
m_OrderDatasetsFirstRBut.setSelected(true);
523
JPanel numIter = new JPanel();
524
numIter.setLayout(new BorderLayout(5, 5));
525
numIter.add(new JLabel("Number of repetitions:"), BorderLayout.WEST);
526
numIter.add(m_NumberOfRepetitionsTField, BorderLayout.CENTER);
528
JPanel controlInner = new JPanel();
529
controlInner.setLayout(new GridLayout(0,1));
530
controlInner.add(numIter);
531
controlInner.add(m_OrderDatasetsFirstRBut);
532
controlInner.add(m_OrderAlgorithmsFirstRBut);
534
JPanel control = new JPanel();
535
control.setLayout(new BorderLayout());
536
control.setBorder(BorderFactory.createCompoundBorder(
537
BorderFactory.createTitledBorder("Iteration Control"),
538
BorderFactory.createEmptyBorder(0, 5, 5, 5)
540
control.add(controlInner, BorderLayout.NORTH);
542
JPanel type_control = new JPanel();
543
type_control.setLayout(new GridLayout(1,0));
544
type_control.add(type);
545
type_control.add(control);
547
JPanel notes = new JPanel();
548
notes.setLayout(new BorderLayout());
549
notes.add(m_NotesButton, BorderLayout.CENTER);
551
JPanel top1 = new JPanel();
552
top1.setLayout(new BorderLayout());
553
top1.add(dest, BorderLayout.NORTH);
554
top1.add(type_control, BorderLayout.CENTER);
556
JPanel top = new JPanel();
557
top.setLayout(new BorderLayout());
558
top.add(buttons, BorderLayout.NORTH);
559
top.add(top1, BorderLayout.CENTER);
561
JPanel datasets = new JPanel();
562
datasets.setLayout(new BorderLayout());
563
datasets.add(m_DatasetListPanel, BorderLayout.CENTER);
565
JPanel algorithms = new JPanel();
566
algorithms.setLayout(new BorderLayout());
567
algorithms.add(m_AlgorithmListPanel, BorderLayout.CENTER);
569
JPanel schemes = new JPanel();
570
schemes.setLayout(new GridLayout(1,0));
571
schemes.add(datasets);
572
schemes.add(algorithms);
574
setLayout(new BorderLayout());
575
add(top, BorderLayout.NORTH);
576
add(schemes, BorderLayout.CENTER);
577
add(notes, BorderLayout.SOUTH);
581
* Sets the selected item of an combobox, since using setSelectedItem(...)
582
* doesn't work, if one checks object references!
584
* @param cb the combobox to set the item for
585
* @param item the item to set active
587
protected void setSelectedItem(JComboBox cb, String item) {
590
for (i = 0; i < cb.getItemCount(); i++) {
591
if (cb.getItemAt(i).toString().equals(item)) {
592
cb.setSelectedIndex(i);
599
* Deletes the notes frame.
601
protected void removeNotesFrame() {
602
m_NotesFrame.setVisible(false);
606
* Gets te users consent for converting the experiment to a simpler form.
608
* @return true if the user has given consent, false otherwise
610
private boolean userWantsToConvert() {
612
if (m_userHasBeenAskedAboutConversion) return true;
613
m_userHasBeenAskedAboutConversion = true;
614
return (JOptionPane.showConfirmDialog(this,
615
"This experiment has settings that are too advanced\n" +
616
"to be represented in the simple setup mode.\n" +
617
"Do you want the experiment to be converted,\n" +
618
"losing some of the advanced settings?\n",
619
"Confirm conversion",
620
JOptionPane.YES_NO_OPTION,
621
JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION);
625
* Sets the panel used to switch between simple and advanced modes.
627
* @param modePanel the panel
629
public void setModePanel(SetupModePanel modePanel) {
631
m_modePanel = modePanel;
635
* Sets the experiment to configure.
637
* @param exp a value of type 'Experiment'
638
* @return true if experiment could be configured, false otherwise
640
public boolean setExperiment(Experiment exp) {
642
m_userHasBeenAskedAboutConversion = false;
643
m_Exp = null; // hold off until we are sure we want conversion
644
m_SaveBut.setEnabled(true);
646
if (exp.getResultListener() instanceof DatabaseResultListener) {
647
m_ResultsDestinationCBox.setSelectedItem(DEST_DATABASE_TEXT);
648
m_ResultsDestinationPathLabel.setText("URL:");
649
m_destinationDatabaseURL = ((DatabaseResultListener)exp.getResultListener()).getDatabaseURL();
650
m_ResultsDestinationPathTField.setText(m_destinationDatabaseURL);
651
m_BrowseDestinationButton.setEnabled(true);
652
} else if (exp.getResultListener() instanceof InstancesResultListener) {
653
m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT);
654
m_ResultsDestinationPathLabel.setText("Filename:");
655
m_destinationFilename = ((InstancesResultListener)exp.getResultListener()).outputFileName();
656
m_ResultsDestinationPathTField.setText(m_destinationFilename);
657
m_BrowseDestinationButton.setEnabled(true);
658
} else if (exp.getResultListener() instanceof CSVResultListener) {
659
m_ResultsDestinationCBox.setSelectedItem(DEST_CSV_TEXT);
660
m_ResultsDestinationPathLabel.setText("Filename:");
661
m_destinationFilename = ((CSVResultListener)exp.getResultListener()).outputFileName();
662
m_ResultsDestinationPathTField.setText(m_destinationFilename);
663
m_BrowseDestinationButton.setEnabled(true);
665
// unrecognised result listener
666
System.out.println("SimpleSetup incompatibility: unrecognised result destination");
667
if (userWantsToConvert()) {
668
m_ResultsDestinationCBox.setSelectedItem(DEST_ARFF_TEXT);
669
m_ResultsDestinationPathLabel.setText("Filename:");
670
m_destinationFilename = "";
671
m_ResultsDestinationPathTField.setText(m_destinationFilename);
672
m_BrowseDestinationButton.setEnabled(true);
677
m_ResultsDestinationCBox.setEnabled(true);
678
m_ResultsDestinationPathLabel.setEnabled(true);
679
m_ResultsDestinationPathTField.setEnabled(true);
681
if (exp.getResultProducer() instanceof CrossValidationResultProducer) {
682
CrossValidationResultProducer cvrp = (CrossValidationResultProducer) exp.getResultProducer();
683
m_numFolds = cvrp.getNumFolds();
684
m_ExperimentParameterTField.setText("" + m_numFolds);
686
if (cvrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) {
687
m_ExpClassificationRBut.setSelected(true);
688
m_ExpRegressionRBut.setSelected(false);
689
} else if (cvrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) {
690
m_ExpClassificationRBut.setSelected(false);
691
m_ExpRegressionRBut.setSelected(true);
693
// unknown split evaluator
694
System.out.println("SimpleSetup incompatibility: unrecognised split evaluator");
695
if (userWantsToConvert()) {
696
m_ExpClassificationRBut.setSelected(true);
697
m_ExpRegressionRBut.setSelected(false);
702
m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT);
703
} else if (exp.getResultProducer() instanceof RandomSplitResultProducer) {
704
RandomSplitResultProducer rsrp = (RandomSplitResultProducer) exp.getResultProducer();
705
if (rsrp.getRandomizeData()) {
706
m_ExperimentTypeCBox.setSelectedItem(TYPE_RANDOMSPLIT_TEXT);
708
m_ExperimentTypeCBox.setSelectedItem(TYPE_FIXEDSPLIT_TEXT);
710
if (rsrp.getSplitEvaluator() instanceof ClassifierSplitEvaluator) {
711
m_ExpClassificationRBut.setSelected(true);
712
m_ExpRegressionRBut.setSelected(false);
713
} else if (rsrp.getSplitEvaluator() instanceof RegressionSplitEvaluator) {
714
m_ExpClassificationRBut.setSelected(false);
715
m_ExpRegressionRBut.setSelected(true);
717
// unknown split evaluator
718
System.out.println("SimpleSetup incompatibility: unrecognised split evaluator");
719
if (userWantsToConvert()) {
720
m_ExpClassificationRBut.setSelected(true);
721
m_ExpRegressionRBut.setSelected(false);
726
m_trainPercent = rsrp.getTrainPercent();
727
m_ExperimentParameterTField.setText("" + m_trainPercent);
730
// unknown experiment type
731
System.out.println("SimpleSetup incompatibility: unrecognised resultProducer");
732
if (userWantsToConvert()) {
733
m_ExperimentTypeCBox.setSelectedItem(TYPE_CROSSVALIDATION_TEXT);
734
m_ExpClassificationRBut.setSelected(true);
735
m_ExpRegressionRBut.setSelected(false);
741
m_ExperimentTypeCBox.setEnabled(true);
742
m_ExperimentParameterLabel.setEnabled(true);
743
m_ExperimentParameterTField.setEnabled(true);
744
m_ExpClassificationRBut.setEnabled(true);
745
m_ExpRegressionRBut.setEnabled(true);
747
if (exp.getRunLower() == 1) {
748
m_numRepetitions = exp.getRunUpper();
749
m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
751
// unsupported iterations
752
System.out.println("SimpleSetup incompatibility: runLower is not 1");
753
if (userWantsToConvert()) {
755
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) {
757
m_NumberOfRepetitionsTField.setEnabled(false);
758
m_NumberOfRepetitionsTField.setText("1");
761
m_numRepetitions = 10;
762
m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
769
m_NumberOfRepetitionsTField.setEnabled(true);
771
m_OrderDatasetsFirstRBut.setSelected(exp.getAdvanceDataSetFirst());
772
m_OrderAlgorithmsFirstRBut.setSelected(!exp.getAdvanceDataSetFirst());
773
m_OrderDatasetsFirstRBut.setEnabled(true);
774
m_OrderAlgorithmsFirstRBut.setEnabled(true);
776
m_NotesText.setText(exp.getNotes());
777
m_NotesButton.setEnabled(true);
779
if (!exp.getUsePropertyIterator() || !(exp.getPropertyArray() instanceof Classifier[])) {
780
// unknown property iteration
781
System.out.println("SimpleSetup incompatibility: unrecognised property iteration");
782
if (userWantsToConvert()) {
783
exp.setPropertyArray(new Classifier[0]);
784
exp.setUsePropertyIterator(true);
790
m_DatasetListPanel.setExperiment(exp);
791
m_AlgorithmListPanel.setExperiment(exp);
794
expTypeChanged(); // recreate experiment
796
m_Support.firePropertyChange("", null, null);
802
* Gets the currently configured experiment.
804
* @return the currently configured experiment.
806
public Experiment getExperiment() {
812
* Prompts the user to select an experiment file and loads it.
814
private void openExperiment() {
816
int returnVal = m_FileChooser.showOpenDialog(this);
817
if (returnVal != JFileChooser.APPROVE_OPTION) {
820
File expFile = m_FileChooser.getSelectedFile();
822
// add extension if necessary
823
if (m_FileChooser.getFileFilter() == m_ExpFilter) {
824
if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION))
825
expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION);
827
else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {
828
if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION))
829
expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION);
831
else if (m_FileChooser.getFileFilter() == m_XMLFilter) {
832
if (!expFile.getName().toLowerCase().endsWith(".xml"))
833
expFile = new File(expFile.getParent(), expFile.getName() + ".xml");
840
if ( (KOML.isPresent()) && (expFile.getAbsolutePath().toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) {
841
exp = (Experiment) KOML.read(expFile.getAbsolutePath());
845
if (expFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {
846
XMLExperiment xml = new XMLExperiment();
847
exp = (Experiment) xml.read(expFile);
851
FileInputStream fi = new FileInputStream(expFile);
852
ObjectInputStream oi = new ObjectInputStream(
853
new BufferedInputStream(fi));
854
exp = (Experiment)oi.readObject();
858
if (!setExperiment(exp)) {
859
if (m_modePanel != null) m_modePanel.switchToAdvanced(exp);
861
System.err.println("Opened experiment:\n" + exp);
862
} catch (Exception ex) {
863
ex.printStackTrace();
864
JOptionPane.showMessageDialog(this, "Couldn't open experiment file:\n"
866
+ "\nReason:\n" + ex.getMessage(),
868
JOptionPane.ERROR_MESSAGE);
869
// Pop up error dialog
874
* Prompts the user for a filename to save the experiment to, then saves
877
private void saveExperiment() {
879
int returnVal = m_FileChooser.showSaveDialog(this);
880
if (returnVal != JFileChooser.APPROVE_OPTION) {
883
File expFile = m_FileChooser.getSelectedFile();
885
// add extension if necessary
886
if (m_FileChooser.getFileFilter() == m_ExpFilter) {
887
if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION))
888
expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION);
890
else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {
891
if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION))
892
expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION);
894
else if (m_FileChooser.getFileFilter() == m_XMLFilter) {
895
if (!expFile.getName().toLowerCase().endsWith(".xml"))
896
expFile = new File(expFile.getParent(), expFile.getName() + ".xml");
901
if ( (KOML.isPresent()) && (expFile.getAbsolutePath().toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) {
902
KOML.write(expFile.getAbsolutePath(), m_Exp);
906
if (expFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {
907
XMLExperiment xml = new XMLExperiment();
908
xml.write(expFile, m_Exp);
912
FileOutputStream fo = new FileOutputStream(expFile);
913
ObjectOutputStream oo = new ObjectOutputStream(
914
new BufferedOutputStream(fo));
915
oo.writeObject(m_Exp);
919
System.err.println("Saved experiment:\n" + m_Exp);
920
} catch (Exception ex) {
921
ex.printStackTrace();
922
JOptionPane.showMessageDialog(this, "Couldn't save experiment file:\n"
924
+ "\nReason:\n" + ex.getMessage(),
926
JOptionPane.ERROR_MESSAGE);
931
* Adds a PropertyChangeListener who will be notified of value changes.
933
* @param l a value of type 'PropertyChangeListener'
935
public void addPropertyChangeListener(PropertyChangeListener l) {
936
m_Support.addPropertyChangeListener(l);
940
* Removes a PropertyChangeListener.
942
* @param l a value of type 'PropertyChangeListener'
944
public void removePropertyChangeListener(PropertyChangeListener l) {
945
m_Support.removePropertyChangeListener(l);
949
* Responds to a change in the destination type.
951
private void destinationTypeChanged() {
953
if (m_Exp == null) return;
957
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
958
m_ResultsDestinationPathLabel.setText("URL:");
959
str = m_destinationDatabaseURL;
960
m_BrowseDestinationButton.setEnabled(true); //!!!
961
m_BrowseDestinationButton.setText("User...");
963
m_ResultsDestinationPathLabel.setText("Filename:");
964
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
965
int ind = m_destinationFilename.lastIndexOf(".csv");
967
m_destinationFilename = m_destinationFilename.substring(0, ind) + ".arff";
970
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
971
int ind = m_destinationFilename.lastIndexOf(".arff");
973
m_destinationFilename = m_destinationFilename.substring(0, ind) + ".csv";
976
str = m_destinationFilename;
977
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
978
int ind = str.lastIndexOf(".csv");
980
str = str.substring(0, ind) + ".arff";
983
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
984
int ind = str.lastIndexOf(".arff");
986
str = str.substring(0, ind) + ".csv";
989
m_BrowseDestinationButton.setEnabled(true);
990
m_BrowseDestinationButton.setText("Browse...");
993
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
994
DatabaseResultListener drl = null;
996
drl = new DatabaseResultListener();
997
} catch (Exception e) {
1000
drl.setDatabaseURL(m_destinationDatabaseURL);
1001
m_Exp.setResultListener(drl);
1003
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
1004
InstancesResultListener irl = new InstancesResultListener();
1005
if (!m_destinationFilename.equals("")) {
1006
irl.setOutputFile(new File(m_destinationFilename));
1008
m_Exp.setResultListener(irl);
1009
} else if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1010
CSVResultListener crl = new CSVResultListener();
1011
if (!m_destinationFilename.equals("")) {
1012
crl.setOutputFile(new File(m_destinationFilename));
1014
m_Exp.setResultListener(crl);
1018
m_ResultsDestinationPathTField.setText(str);
1020
m_Support.firePropertyChange("", null, null);
1024
* Responds to a change in the destination address.
1026
private void destinationAddressChanged() {
1028
if (m_Exp == null) return;
1030
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {
1031
m_destinationDatabaseURL = m_ResultsDestinationPathTField.getText();
1032
if (m_Exp.getResultListener() instanceof DatabaseResultListener) {
1033
((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(m_destinationDatabaseURL);
1036
File resultsFile = null;
1037
m_destinationFilename = m_ResultsDestinationPathTField.getText();
1039
// Use temporary file if no file name is provided
1040
if (m_destinationFilename.equals("")) {
1042
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
1043
resultsFile = File.createTempFile("weka_experiment", ".arff");
1045
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1046
resultsFile = File.createTempFile("weka_experiment", ".csv");
1048
resultsFile.deleteOnExit();
1049
} catch (Exception e) {
1050
System.err.println("Cannot create temp file, writing to standard out.");
1051
resultsFile = new File("-");
1054
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {
1055
if (!m_destinationFilename.endsWith(".arff")) {
1056
m_destinationFilename += ".arff";
1059
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1060
if (!m_destinationFilename.endsWith(".csv")) {
1061
m_destinationFilename += ".csv";
1064
resultsFile = new File(m_destinationFilename);
1066
((CSVResultListener)m_Exp.getResultListener()).setOutputFile(resultsFile);
1067
((CSVResultListener)m_Exp.getResultListener()).setOutputFileName(m_destinationFilename);
1070
m_Support.firePropertyChange("", null, null);
1074
* Responds to a change in the experiment type.
1076
private void expTypeChanged() {
1078
if (m_Exp == null) return;
1080
// update parameter ui
1081
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1082
m_ExperimentParameterLabel.setText("Number of folds:");
1083
m_ExperimentParameterTField.setText("" + m_numFolds);
1085
m_ExperimentParameterLabel.setText("Train percentage:");
1086
m_ExperimentParameterTField.setText("" + m_trainPercent);
1089
// update iteration ui
1090
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) {
1091
m_NumberOfRepetitionsTField.setEnabled(false);
1092
m_NumberOfRepetitionsTField.setText("1");
1093
m_Exp.setRunLower(1);
1094
m_Exp.setRunUpper(1);
1096
m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);
1097
m_NumberOfRepetitionsTField.setEnabled(true);
1098
m_Exp.setRunLower(1);
1099
m_Exp.setRunUpper(m_numRepetitions);
1102
SplitEvaluator se = null;
1103
Classifier sec = null;
1104
if (m_ExpClassificationRBut.isSelected()) {
1105
se = new ClassifierSplitEvaluator();
1106
sec = ((ClassifierSplitEvaluator)se).getClassifier();
1108
se = new RegressionSplitEvaluator();
1109
sec = ((RegressionSplitEvaluator)se).getClassifier();
1112
// build new ResultProducer
1113
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1114
CrossValidationResultProducer cvrp = new CrossValidationResultProducer();
1115
cvrp.setNumFolds(m_numFolds);
1116
cvrp.setSplitEvaluator(se);
1118
PropertyNode[] propertyPath = new PropertyNode[2];
1120
propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",
1121
CrossValidationResultProducer.class),
1122
CrossValidationResultProducer.class);
1123
propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",
1126
} catch (IntrospectionException e) {
1127
e.printStackTrace();
1130
m_Exp.setResultProducer(cvrp);
1131
m_Exp.setPropertyPath(propertyPath);
1134
RandomSplitResultProducer rsrp = new RandomSplitResultProducer();
1135
rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);
1136
rsrp.setTrainPercent(m_trainPercent);
1137
rsrp.setSplitEvaluator(se);
1139
PropertyNode[] propertyPath = new PropertyNode[2];
1141
propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",
1142
RandomSplitResultProducer.class),
1143
RandomSplitResultProducer.class);
1144
propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",
1147
} catch (IntrospectionException e) {
1148
e.printStackTrace();
1151
m_Exp.setResultProducer(rsrp);
1152
m_Exp.setPropertyPath(propertyPath);
1156
m_Exp.setUsePropertyIterator(true);
1157
m_Support.firePropertyChange("", null, null);
1161
* Responds to a change in the experiment parameter.
1163
private void expParamChanged() {
1165
if (m_Exp == null) return;
1167
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1169
m_numFolds = Integer.parseInt(m_ExperimentParameterTField.getText());
1170
} catch (NumberFormatException e) {
1175
m_trainPercent = Double.parseDouble(m_ExperimentParameterTField.getText());
1176
} catch (NumberFormatException e) {
1181
if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {
1183
if (m_Exp.getResultProducer() instanceof CrossValidationResultProducer) {
1184
CrossValidationResultProducer cvrp = (CrossValidationResultProducer) m_Exp.getResultProducer();
1185
cvrp.setNumFolds(m_numFolds);
1192
if (m_Exp.getResultProducer() instanceof RandomSplitResultProducer) {
1193
RandomSplitResultProducer rsrp = (RandomSplitResultProducer) m_Exp.getResultProducer();
1194
rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);
1195
rsrp.setTrainPercent(m_trainPercent);
1197
//System.err.println("not rsrp");
1202
m_Support.firePropertyChange("", null, null);
1206
* Responds to a change in the number of repetitions.
1208
private void numRepetitionsChanged() {
1210
if (m_Exp == null || !m_NumberOfRepetitionsTField.isEnabled()) return;
1213
m_numRepetitions = Integer.parseInt(m_NumberOfRepetitionsTField.getText());
1214
} catch (NumberFormatException e) {
1218
m_Exp.setRunLower(1);
1219
m_Exp.setRunUpper(m_numRepetitions);
1221
m_Support.firePropertyChange("", null, null);
1225
* Lets user enter username/password/URL.
1227
private void chooseURLUsername() {
1228
String dbaseURL=((DatabaseResultListener)m_Exp.getResultListener()).getDatabaseURL();
1229
String username=((DatabaseResultListener)m_Exp.getResultListener()).getUsername();
1230
DatabaseConnectionDialog dbd= new DatabaseConnectionDialog(null,dbaseURL,username);
1231
dbd.setVisible(true);
1233
//if (dbaseURL == null) {
1234
if (dbd.getReturnValue()==JOptionPane.CLOSED_OPTION) {
1238
((DatabaseResultListener)m_Exp.getResultListener()).setUsername(dbd.getUsername());
1239
((DatabaseResultListener)m_Exp.getResultListener()).setPassword(dbd.getPassword());
1240
((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(dbd.getURL());
1241
((DatabaseResultListener)m_Exp.getResultListener()).setDebug(dbd.getDebug());
1242
m_ResultsDestinationPathTField.setText(dbd.getURL());
1245
* Lets user browse for a destination file..
1247
private void chooseDestinationFile() {
1249
FileFilter fileFilter = null;
1250
if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {
1251
fileFilter = m_csvFileFilter;
1253
fileFilter = m_arffFileFilter;
1255
m_DestFileChooser.setFileFilter(fileFilter);
1256
int returnVal = m_DestFileChooser.showSaveDialog(this);
1257
if (returnVal != JFileChooser.APPROVE_OPTION) {
1260
m_ResultsDestinationPathTField.setText(m_DestFileChooser.getSelectedFile().toString());