📄 simplesetuppanel.java
字号:
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());
}
/**
* 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());
}
/**
* Tests out the experiment setup from the command line.
*
* @param args arguments to the program.
*/
public static void main(String [] args) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -