⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplesetuppanel.java

📁 Java 编写的多种数据挖掘算法 包括聚类、分类、预处理等
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/*
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 *    SimpleSetupPanel.java
 *    Copyright (C) 2002 Richard Kirkby
 *
 */

package weka.gui.experiment;

import javax.swing.JPanel;
import weka.experiment.Experiment;
import weka.gui.ExtensionFileFilter;
import weka.gui.DatabaseConnectionDialog;

import weka.classifiers.Classifier;
import weka.core.xml.KOML;
import weka.experiment.CrossValidationResultProducer;
import weka.experiment.SplitEvaluator;
import weka.experiment.ClassifierSplitEvaluator;
import weka.experiment.RegressionSplitEvaluator;
import weka.experiment.DatabaseResultListener;
import weka.experiment.InstancesResultListener;
import weka.experiment.CSVResultListener;
import weka.experiment.PropertyNode;
import weka.experiment.ResultProducer;
import weka.experiment.RandomSplitResultProducer;
import weka.experiment.xml.XMLExperiment;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeSupport;
import java.beans.PropertyDescriptor;
import java.beans.IntrospectionException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.BufferedInputStream;
import java.awt.Component;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Insets;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.Box;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileFilter;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;


/** 
 * This panel controls the configuration of an experiment.
  * <p>
 * If <a href="http://koala.ilog.fr/XML/serialization/" target="_blank">KOML</a>
 * is in the classpath the experiments can also be saved to XML instead of a
 * binary format.
*
 * @author Richard kirkby (rkirkby@cs.waikato.ac.nz)
 * @author FracPete (fracpete at waikato dot ac dot nz) 
 * @version $Revision: 1.11 $
 */
public class SimpleSetupPanel extends JPanel {

  /** The experiment being configured */
  protected Experiment m_Exp;

  /** The panel which switched between simple and advanced setup modes */
  protected SetupModePanel m_modePanel = null;

  /** The database destination URL to store results into */
  protected String m_destinationDatabaseURL;

  /** The filename to store results into */
  protected String m_destinationFilename = "";

  /** The number of folds for a cross-validation experiment */
  protected int m_numFolds = 10;

  /** The training percentage for a train/test split experiment */
  protected double m_trainPercent = 66;

  /** The number of times to repeat the sub-experiment */
  protected int m_numRepetitions = 10;

  /** Whether or not the user has consented for the experiment to be simplified */
  protected boolean m_userHasBeenAskedAboutConversion;

  /** Filter for choosing CSV files */
  protected ExtensionFileFilter m_csvFileFilter =
    new ExtensionFileFilter(".csv", "Comma separated value files");

  /** FIlter for choosing ARFF files */
  protected ExtensionFileFilter m_arffFileFilter =
    new ExtensionFileFilter(".arff", "ARFF files");

  /** Click to load an experiment */
  protected JButton m_OpenBut = new JButton("Open...");

  /** Click to save an experiment */
  protected JButton m_SaveBut = new JButton("Save...");

  /** Click to create a new experiment with default settings */
  protected JButton m_NewBut = new JButton("New");

  /** A filter to ensure only experiment files get shown in the chooser */
  protected FileFilter m_ExpFilter = 
    new ExtensionFileFilter(Experiment.FILE_EXTENSION, 
                            "Experiment configuration files (*" + Experiment.FILE_EXTENSION + ")");

  /** A filter to ensure only experiment (in KOML format) files get shown in the chooser */
  protected FileFilter m_KOMLFilter = 
    new ExtensionFileFilter(KOML.FILE_EXTENSION, 
                            "Experiment configuration files (*" + KOML.FILE_EXTENSION + ")");

  /** A filter to ensure only experiment (in XML format) files get shown in the chooser */
  protected FileFilter m_XMLFilter = 
    new ExtensionFileFilter(".xml", 
                            "Experiment configuration files (*.xml)");

  /** The file chooser for selecting experiments */
  protected JFileChooser m_FileChooser =
    new JFileChooser(new File(System.getProperty("user.dir")));

  /** The file chooser for selecting result destinations */
  protected JFileChooser m_DestFileChooser =
    new JFileChooser(new File(System.getProperty("user.dir")));

  /** Combo box for choosing experiment destination type */
  protected JComboBox m_ResultsDestinationCBox = new JComboBox();

  /** Label for destination field */
  protected JLabel m_ResultsDestinationPathLabel = new JLabel("Filename:");

  /** Input field for result destination path */ 
  protected JTextField m_ResultsDestinationPathTField = new JTextField();

  /** Button for browsing destination files */
  protected JButton m_BrowseDestinationButton = new JButton("Browse...");

  /** Combo box for choosing experiment type */
  protected JComboBox m_ExperimentTypeCBox = new JComboBox();

  /** Label for parameter field */
  protected JLabel m_ExperimentParameterLabel = new JLabel("Number of folds:");

  /** Input field for experiment parameter */
  protected JTextField m_ExperimentParameterTField = new JTextField(); 

  /** Radio button for choosing classification experiment */
  protected JRadioButton m_ExpClassificationRBut = 
    new JRadioButton("Classification");

  /** Radio button for choosing regression experiment */
  protected JRadioButton m_ExpRegressionRBut = 
    new JRadioButton("Regression");

  /** Input field for number of repetitions */
  protected JTextField m_NumberOfRepetitionsTField = new JTextField();  

  /** Radio button for choosing datasets first in order of execution */ 
  protected JRadioButton m_OrderDatasetsFirstRBut = 
    new JRadioButton("Data sets first");

  /** Radio button for choosing algorithms first in order of execution */ 
  protected JRadioButton m_OrderAlgorithmsFirstRBut = 
    new JRadioButton("Algorithms first");

  /** The strings used to identify the combo box choices */
  protected static String DEST_DATABASE_TEXT = ("JDBC database");
  protected static String DEST_ARFF_TEXT = ("ARFF file");
  protected static String DEST_CSV_TEXT = ("CSV file");
  protected static String TYPE_CROSSVALIDATION_TEXT = ("Cross-validation");
  protected static String TYPE_RANDOMSPLIT_TEXT = ("Train/Test Percentage Split (data randomized)");
  protected static String TYPE_FIXEDSPLIT_TEXT = ("Train/Test Percentage Split (order preserved)");

  /** The panel for configuring selected datasets */
  protected DatasetListPanel m_DatasetListPanel = new DatasetListPanel();

  /** The panel for configuring selected algorithms */
  protected AlgorithmListPanel m_AlgorithmListPanel = new AlgorithmListPanel();

  /** A button for bringing up the notes */
  protected JButton m_NotesButton =  new JButton("Notes");

  /** Frame for the notes */
  protected JFrame m_NotesFrame = new JFrame("Notes");

  /** Area for user notes Default of 10 rows */
  protected JTextArea m_NotesText = new JTextArea(null, 10, 0);

  /**
   * Manages sending notifications to people when we change the experiment,
   * at this stage, only the resultlistener so the resultpanel can update.
   */
  protected PropertyChangeSupport m_Support = new PropertyChangeSupport(this);
  
  /**
   * Creates the setup panel with the supplied initial experiment.
   *
   * @param exp a value of type 'Experiment'
   */
  public SimpleSetupPanel(Experiment exp) {

    this();
    setExperiment(exp);
  }
  
  /**
   * Creates the setup panel with no initial experiment.
   */
  public SimpleSetupPanel() {

    // everything disabled on startup
    m_ResultsDestinationCBox.setEnabled(false);
    m_ResultsDestinationPathLabel.setEnabled(false);
    m_ResultsDestinationPathTField.setEnabled(false);
    m_BrowseDestinationButton.setEnabled(false); 
    m_ExperimentTypeCBox.setEnabled(false);
    m_ExperimentParameterLabel.setEnabled(false);
    m_ExperimentParameterTField.setEnabled(false);
    m_ExpClassificationRBut.setEnabled(false);
    m_ExpRegressionRBut.setEnabled(false);
    m_NumberOfRepetitionsTField.setEnabled(false);
    m_OrderDatasetsFirstRBut.setEnabled(false);
    m_OrderAlgorithmsFirstRBut.setEnabled(false);

    // get sensible default database address
    try {
      m_destinationDatabaseURL = (new DatabaseResultListener()).getDatabaseURL();
    } catch (Exception e) {}

    // create action listeners
    m_NewBut.setMnemonic('N');
    m_NewBut.addActionListener(new ActionListener() {
	public void actionPerformed(ActionEvent e) {
	  Experiment newExp = new Experiment();
	  CrossValidationResultProducer cvrp = new CrossValidationResultProducer();
	  cvrp.setNumFolds(10);
	  cvrp.setSplitEvaluator(new ClassifierSplitEvaluator());
	  newExp.setResultProducer(cvrp);
	  newExp.setPropertyArray(new Classifier[0]);
	  newExp.setUsePropertyIterator(true);
	  setExperiment(newExp);

          // defaults
          if (ExperimenterDefaults.getUseClassification())
            m_ExpClassificationRBut.setSelected(true);
          else
            m_ExpRegressionRBut.setSelected(true);
          
          setSelectedItem(
              m_ResultsDestinationCBox, ExperimenterDefaults.getDestination());
          destinationTypeChanged();
          
          setSelectedItem(
              m_ExperimentTypeCBox, ExperimenterDefaults.getExperimentType());
          
          m_numRepetitions = ExperimenterDefaults.getRepetitions();
          m_NumberOfRepetitionsTField.setText(
              "" + m_numRepetitions);
          
          if (ExperimenterDefaults.getExperimentType().equals(
                TYPE_CROSSVALIDATION_TEXT)) {
            m_numFolds = ExperimenterDefaults.getFolds();
            m_ExperimentParameterTField.setText(
                "" + m_numFolds);
          }
          else {
            m_trainPercent = ExperimenterDefaults.getTrainPercentage();
            m_ExperimentParameterTField.setText(
                "" + m_trainPercent);
          }
          
          if (ExperimenterDefaults.getDatasetsFirst())
            m_OrderDatasetsFirstRBut.setSelected(true);
          else
            m_OrderAlgorithmsFirstRBut.setSelected(true);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -