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

📄 simplesetuppanel.java

📁 代码是一个分类器的实现,其中使用了部分weka的源代码。可以将项目导入eclipse运行
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      if (expFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {         XMLExperiment xml = new XMLExperiment();          exp = (Experiment) xml.read(expFile);      }      // binary      else {         FileInputStream fi = new FileInputStream(expFile);         ObjectInputStream oi = new ObjectInputStream(                                new BufferedInputStream(fi));         exp = (Experiment)oi.readObject();         oi.close();      }            if (!setExperiment(exp)) {	if (m_modePanel != null) m_modePanel.switchToAdvanced(exp);      }      System.err.println("Opened experiment:\n" + exp);    } catch (Exception ex) {      ex.printStackTrace();      JOptionPane.showMessageDialog(this, "Couldn't open experiment file:\n"				    + expFile				    + "\nReason:\n" + ex.getMessage(),				    "Open Experiment",				    JOptionPane.ERROR_MESSAGE);      // Pop up error dialog    }  }  /**   * Prompts the user for a filename to save the experiment to, then saves   * the experiment.   */  private void saveExperiment() {    int returnVal = m_FileChooser.showSaveDialog(this);    if (returnVal != JFileChooser.APPROVE_OPTION) {      return;    }    File expFile = m_FileChooser.getSelectedFile();        // add extension if necessary    if (m_FileChooser.getFileFilter() == m_ExpFilter) {      if (!expFile.getName().toLowerCase().endsWith(Experiment.FILE_EXTENSION))        expFile = new File(expFile.getParent(), expFile.getName() + Experiment.FILE_EXTENSION);    }    else if (m_FileChooser.getFileFilter() == m_KOMLFilter) {      if (!expFile.getName().toLowerCase().endsWith(KOML.FILE_EXTENSION))        expFile = new File(expFile.getParent(), expFile.getName() + KOML.FILE_EXTENSION);    }    else if (m_FileChooser.getFileFilter() == m_XMLFilter) {      if (!expFile.getName().toLowerCase().endsWith(".xml"))        expFile = new File(expFile.getParent(), expFile.getName() + ".xml");    }        try {       // KOML?       if ( (KOML.isPresent()) && (expFile.getAbsolutePath().toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) {          KOML.write(expFile.getAbsolutePath(), m_Exp);       }       else       // XML?       if (expFile.getAbsolutePath().toLowerCase().endsWith(".xml")) {          XMLExperiment xml = new XMLExperiment();           xml.write(expFile, m_Exp);       }       // binary       else {          FileOutputStream fo = new FileOutputStream(expFile);          ObjectOutputStream oo = new ObjectOutputStream(                                  new BufferedOutputStream(fo));          oo.writeObject(m_Exp);          oo.close();       }            System.err.println("Saved experiment:\n" + m_Exp);    } catch (Exception ex) {      ex.printStackTrace();      JOptionPane.showMessageDialog(this, "Couldn't save experiment file:\n"				    + expFile				    + "\nReason:\n" + ex.getMessage(),				    "Save Experiment",				    JOptionPane.ERROR_MESSAGE);    }  }  /**   * Adds a PropertyChangeListener who will be notified of value changes.   *   * @param l a value of type 'PropertyChangeListener'   */  public void addPropertyChangeListener(PropertyChangeListener l) {    m_Support.addPropertyChangeListener(l);  }  /**   * Removes a PropertyChangeListener.   *   * @param l a value of type 'PropertyChangeListener'   */  public void removePropertyChangeListener(PropertyChangeListener l) {    m_Support.removePropertyChangeListener(l);  }  /**   * Responds to a change in the destination type.   */  private void destinationTypeChanged() {    if (m_Exp == null) return;    String str = "";    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {      m_ResultsDestinationPathLabel.setText("URL:");      str = m_destinationDatabaseURL;      m_BrowseDestinationButton.setEnabled(true); //!!!      m_BrowseDestinationButton.setText("User...");    } else {      m_ResultsDestinationPathLabel.setText("Filename:");      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {	int ind = m_destinationFilename.lastIndexOf(".csv");	if (ind > -1) {	  m_destinationFilename = m_destinationFilename.substring(0, ind) + ".arff";	}      }      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {	int ind = m_destinationFilename.lastIndexOf(".arff");	if (ind > -1) {	  m_destinationFilename = m_destinationFilename.substring(0, ind) + ".csv";	}      }      str = m_destinationFilename;      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {	int ind = str.lastIndexOf(".csv");	if (ind > -1) {	  str = str.substring(0, ind) + ".arff";	}      }      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {	int ind = str.lastIndexOf(".arff");	if (ind > -1) {	  str = str.substring(0, ind) + ".csv";	}      }      m_BrowseDestinationButton.setEnabled(true);      m_BrowseDestinationButton.setText("Browse...");    }    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {      DatabaseResultListener drl = null;      try {	drl = new DatabaseResultListener();      } catch (Exception e) {	e.printStackTrace();      }      drl.setDatabaseURL(m_destinationDatabaseURL);      m_Exp.setResultListener(drl);    } else {      if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {	InstancesResultListener irl = new InstancesResultListener();	if (!m_destinationFilename.equals("")) {	  irl.setOutputFile(new File(m_destinationFilename));	}	m_Exp.setResultListener(irl);      } else if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {	CSVResultListener crl = new CSVResultListener();	if (!m_destinationFilename.equals("")) {	  crl.setOutputFile(new File(m_destinationFilename));	}	m_Exp.setResultListener(crl);      }    }    m_ResultsDestinationPathTField.setText(str);    m_Support.firePropertyChange("", null, null);  }  /**   * Responds to a change in the destination address.   */  private void destinationAddressChanged() {    if (m_Exp == null) return;    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_DATABASE_TEXT) {      m_destinationDatabaseURL = m_ResultsDestinationPathTField.getText();      if (m_Exp.getResultListener() instanceof DatabaseResultListener) {	((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(m_destinationDatabaseURL);      }    } else {      File resultsFile = null;      m_destinationFilename = m_ResultsDestinationPathTField.getText();      // Use temporary file if no file name is provided      if (m_destinationFilename.equals("")) {	try {	  if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {	    resultsFile = File.createTempFile("weka_experiment", ".arff");	  }	  if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {	    resultsFile = File.createTempFile("weka_experiment", ".csv");	  }	  resultsFile.deleteOnExit();	} catch (Exception e) {	  System.err.println("Cannot create temp file, writing to standard out.");	  resultsFile = new File("-");	}      } else {	if (m_ResultsDestinationCBox.getSelectedItem() == DEST_ARFF_TEXT) {	  if (!m_destinationFilename.endsWith(".arff")) {	    m_destinationFilename += ".arff";	  }	}	if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {	  if (!m_destinationFilename.endsWith(".csv")) {	    m_destinationFilename += ".csv";	  }	}	resultsFile = new File(m_destinationFilename);      }      ((CSVResultListener)m_Exp.getResultListener()).setOutputFile(resultsFile);      ((CSVResultListener)m_Exp.getResultListener()).setOutputFileName(m_destinationFilename);    }    m_Support.firePropertyChange("", null, null);  }  /**   * Responds to a change in the experiment type.   */  private void expTypeChanged() {    if (m_Exp == null) return;    // update parameter ui    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {      m_ExperimentParameterLabel.setText("Number of folds:");      m_ExperimentParameterTField.setText("" + m_numFolds);    } else {      m_ExperimentParameterLabel.setText("Train percentage:");      m_ExperimentParameterTField.setText("" + m_trainPercent);    }    // update iteration ui    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_FIXEDSPLIT_TEXT) {      m_NumberOfRepetitionsTField.setEnabled(false);      m_NumberOfRepetitionsTField.setText("1");      m_Exp.setRunLower(1);      m_Exp.setRunUpper(1);    } else {      m_NumberOfRepetitionsTField.setText("" + m_numRepetitions);      m_NumberOfRepetitionsTField.setEnabled(true);      m_Exp.setRunLower(1);      m_Exp.setRunUpper(m_numRepetitions);    }    SplitEvaluator se = null;    Classifier sec = null;    if (m_ExpClassificationRBut.isSelected()) {      se = new ClassifierSplitEvaluator();      sec = ((ClassifierSplitEvaluator)se).getClassifier();    } else {      se = new RegressionSplitEvaluator();      sec = ((RegressionSplitEvaluator)se).getClassifier();    }        // build new ResultProducer    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {      CrossValidationResultProducer cvrp = new CrossValidationResultProducer();      cvrp.setNumFolds(m_numFolds);      cvrp.setSplitEvaluator(se);            PropertyNode[] propertyPath = new PropertyNode[2];      try {	propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",								      CrossValidationResultProducer.class),					   CrossValidationResultProducer.class);	propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",								       se.getClass()),					   se.getClass());      } catch (IntrospectionException e) {	e.printStackTrace();      }            m_Exp.setResultProducer(cvrp);      m_Exp.setPropertyPath(propertyPath);    } else {      RandomSplitResultProducer rsrp = new RandomSplitResultProducer();      rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);      rsrp.setTrainPercent(m_trainPercent);      rsrp.setSplitEvaluator(se);      PropertyNode[] propertyPath = new PropertyNode[2];      try {	propertyPath[0] = new PropertyNode(se, new PropertyDescriptor("splitEvaluator",								      RandomSplitResultProducer.class),					   RandomSplitResultProducer.class);	propertyPath[1] = new PropertyNode(sec, new PropertyDescriptor("classifier",								       se.getClass()),					   se.getClass());      } catch (IntrospectionException e) {	e.printStackTrace();      }      m_Exp.setResultProducer(rsrp);      m_Exp.setPropertyPath(propertyPath);    }    m_Exp.setUsePropertyIterator(true);    m_Support.firePropertyChange("", null, null);  }  /**   * Responds to a change in the experiment parameter.   */  private void expParamChanged() {    if (m_Exp == null) return;    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {      try {	m_numFolds = Integer.parseInt(m_ExperimentParameterTField.getText());      } catch (NumberFormatException e) {	return;      }    } else {      try {	m_trainPercent = Double.parseDouble(m_ExperimentParameterTField.getText());      } catch (NumberFormatException e) {	return;      }    }    if (m_ExperimentTypeCBox.getSelectedItem() == TYPE_CROSSVALIDATION_TEXT) {      if (m_Exp.getResultProducer() instanceof CrossValidationResultProducer) {	CrossValidationResultProducer cvrp = (CrossValidationResultProducer) m_Exp.getResultProducer();	cvrp.setNumFolds(m_numFolds);      } else {	return;      }    } else {            if (m_Exp.getResultProducer() instanceof RandomSplitResultProducer) {	RandomSplitResultProducer rsrp = (RandomSplitResultProducer) m_Exp.getResultProducer();	rsrp.setRandomizeData(m_ExperimentTypeCBox.getSelectedItem() == TYPE_RANDOMSPLIT_TEXT);	rsrp.setTrainPercent(m_trainPercent);      } else {	//System.err.println("not rsrp");	return;      }    }    m_Support.firePropertyChange("", null, null);  }  /**   * Responds to a change in the number of repetitions.   */  private void numRepetitionsChanged() {    if (m_Exp == null || !m_NumberOfRepetitionsTField.isEnabled()) return;    try {      m_numRepetitions = Integer.parseInt(m_NumberOfRepetitionsTField.getText());    } catch (NumberFormatException e) {      return;    }    m_Exp.setRunLower(1);    m_Exp.setRunUpper(m_numRepetitions);    m_Support.firePropertyChange("", null, null);  }  /**   * Lets user enter username/password/URL.   */  private void chooseURLUsername() {    String dbaseURL=((DatabaseResultListener)m_Exp.getResultListener()).getDatabaseURL();    String username=((DatabaseResultListener)m_Exp.getResultListener()).getUsername();    DatabaseConnectionDialog dbd= new DatabaseConnectionDialog(null,dbaseURL,username);    dbd.setVisible(true);          //if (dbaseURL == null) {    if (dbd.getReturnValue()==JOptionPane.CLOSED_OPTION) {      return;    }    ((DatabaseResultListener)m_Exp.getResultListener()).setUsername(dbd.getUsername());    ((DatabaseResultListener)m_Exp.getResultListener()).setPassword(dbd.getPassword());    ((DatabaseResultListener)m_Exp.getResultListener()).setDatabaseURL(dbd.getURL());    ((DatabaseResultListener)m_Exp.getResultListener()).setDebug(dbd.getDebug());    m_ResultsDestinationPathTField.setText(dbd.getURL());  }  /**   * Lets user browse for a destination file..   */  private void chooseDestinationFile() {    FileFilter fileFilter = null;    if (m_ResultsDestinationCBox.getSelectedItem() == DEST_CSV_TEXT) {      fileFilter = m_csvFileFilter;    } else {      fileFilter = m_arffFileFilter;    }    m_DestFileChooser.setFileFilter(fileFilter);    int returnVal = m_DestFileChooser.showSaveDialog(this);    if (returnVal != JFileChooser.APPROVE_OPTION) {      return;    }    m_ResultsDestinationPathTField.setText(m_DestFileChooser.getSelectedFile().toString());  }}

⌨️ 快捷键说明

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