weka.experiment
Class Experiment

java.lang.Object
  extended byweka.experiment.Experiment
All Implemented Interfaces:
OptionHandler, java.io.Serializable
Direct Known Subclasses:
RemoteExperiment

public class Experiment
extends java.lang.Object
implements java.io.Serializable, OptionHandler

Holds all the necessary configuration information for a standard type experiment. This object is able to be serialized for storage on disk.

Version:
$Revision: 1.19 $
Author:
Len Trigg (trigg@cs.waikato.ac.nz)
See Also:
Serialized Form

Field Summary
static java.lang.String FILE_EXTENSION
          The filename extension that should be used for experiment files
protected  java.lang.String[] m_AdditionalMeasures
          Method names of additional measures of objects contained in the custom property iterator.
protected  boolean m_AdvanceDataSetFirst
          If true an experiment will advance the current data set befor any custom itererator
protected  boolean m_ClassFirst
          True if the class attribute is the first attribute for all datasets involved in this experiment.
protected  Instances m_CurrentInstances
          The dataset currently being used
protected  int m_CurrentProperty
          The custom property value that has actually been set
protected  int m_DatasetNumber
          The current dataset number when the experiment is running
protected  javax.swing.DefaultListModel m_Datasets
          An array of dataset files
protected  boolean m_Finished
          True if the experiment has finished running
(package private)  boolean m_m_AdvanceRunFirst
           
protected  java.lang.String m_Notes
          User notes about the experiment
protected  java.lang.Object m_PropertyArray
          The array of values to set the property to
protected  int m_PropertyNumber
          The current custom property value index when the experiment is running
protected  PropertyNode[] m_PropertyPath
          The path to the iterator property
protected  ResultListener m_ResultListener
          Where results will be sent
protected  ResultProducer m_ResultProducer
          The result producer
protected  int m_RunLower
          Lower run number
protected  int m_RunNumber
          The current run number when the experiment is running
protected  int m_RunUpper
          Upper run number
protected  boolean m_UsePropertyIterator
          True if the exp should also iterate over a property of the RP
 
Constructor Summary
Experiment()
           
 
Method Summary
 void advanceCounters()
          Increments iteration counters appropriately.
 void classFirst(boolean flag)
          Sets whether the first attribute is treated as the class for all datasets involved in the experiment.
private  void determineAdditionalResultMeasures()
          Iterate over the objects in the property array to determine what (if any) additional measures they support
 boolean getAdvanceDataSetFirst()
          Get the value of m_DataSetFirstFirst.
 int getCurrentDatasetNumber()
          When an experiment is running, this returns the current dataset number.
 int getCurrentPropertyNumber()
          When an experiment is running, this returns the index of the current custom property value.
 int getCurrentRunNumber()
          When an experiment is running, this returns the current run number.
 javax.swing.DefaultListModel getDatasets()
          Gets the datasets in the experiment.
 java.lang.String getNotes()
          Get the user notes.
 java.lang.String[] getOptions()
          Gets the current settings of the experiment iterator.
 java.lang.Object getPropertyArray()
          Gets the array of values to set the custom property to.
 int getPropertyArrayLength()
          Gets the number of custom iterator values that have been defined for the experiment.
 java.lang.Object getPropertyArrayValue(int index)
          Gets a specified value from the custom property iterator array.
 PropertyNode[] getPropertyPath()
          Gets the path of properties taken to get to the custom property to iterate over.
 ResultListener getResultListener()
          Gets the result listener where results will be sent.
 ResultProducer getResultProducer()
          Get the result producer used for the current experiment.
 int getRunLower()
          Get the lower run number for the experiment.
 int getRunUpper()
          Get the upper run number for the experiment.
 boolean getUsePropertyIterator()
          Gets whether the custom property iterator should be used.
 boolean hasMoreIterations()
          Returns true if there are more iterations to carry out in the experiment.
 void initialize()
          Prepares an experiment for running, initializing current iterator settings.
 java.util.Enumeration listOptions()
          Returns an enumeration describing the available options..
static void main(java.lang.String[] args)
          Configures/Runs the Experiment from the command line.
 void nextIteration()
          Carries out the next iteration of the experiment.
 void postProcess()
          Signals that the experiment is finished running, so that cleanup can be done.
 void runExperiment()
          Runs all iterations of the experiment, continuing past errors.
 void setAdvanceDataSetFirst(boolean newAdvanceDataSetFirst)
          Set the value of m_AdvanceDataSetFirst.
 void setDatasets(javax.swing.DefaultListModel ds)
          Set the datasets to use in the experiment
 void setNotes(java.lang.String newNotes)
          Set the user notes.
 void setOptions(java.lang.String[] options)
          Parses a given list of options.
protected  void setProperty(int propertyDepth, java.lang.Object origValue)
          Recursively sets the custom property value, by setting all values along the property path.
 void setPropertyArray(java.lang.Object newPropArray)
          Sets the array of values to set the custom property to.
 void setPropertyPath(PropertyNode[] newPropertyPath)
          Sets the path of properties taken to get to the custom property to iterate over.
 void setResultListener(ResultListener newResultListener)
          Sets the result listener where results will be sent.
 void setResultProducer(ResultProducer newResultProducer)
          Set the result producer used for the current experiment.
 void setRunLower(int newRunLower)
          Set the lower run number for the experiment.
 void setRunUpper(int newRunUpper)
          Set the upper run number for the experiment.
 void setUsePropertyIterator(boolean newUsePropertyIterator)
          Sets whether the custom property iterator should be used.
 java.lang.String toString()
          Gets a string representation of the experiment configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_EXTENSION

public static java.lang.String FILE_EXTENSION
The filename extension that should be used for experiment files


m_ResultListener

protected ResultListener m_ResultListener
Where results will be sent


m_ResultProducer

protected ResultProducer m_ResultProducer
The result producer


m_RunLower

protected int m_RunLower
Lower run number


m_RunUpper

protected int m_RunUpper
Upper run number


m_Datasets

protected javax.swing.DefaultListModel m_Datasets
An array of dataset files


m_UsePropertyIterator

protected boolean m_UsePropertyIterator
True if the exp should also iterate over a property of the RP


m_PropertyPath

protected PropertyNode[] m_PropertyPath
The path to the iterator property


m_PropertyArray

protected java.lang.Object m_PropertyArray
The array of values to set the property to


m_Notes

protected java.lang.String m_Notes
User notes about the experiment


m_AdditionalMeasures

protected java.lang.String[] m_AdditionalMeasures
Method names of additional measures of objects contained in the custom property iterator. Only methods names beginning with "measure" and returning doubles are recognised


m_ClassFirst

protected boolean m_ClassFirst
True if the class attribute is the first attribute for all datasets involved in this experiment.


m_AdvanceDataSetFirst

protected boolean m_AdvanceDataSetFirst
If true an experiment will advance the current data set befor any custom itererator


m_m_AdvanceRunFirst

boolean m_m_AdvanceRunFirst

m_RunNumber

protected transient int m_RunNumber
The current run number when the experiment is running


m_DatasetNumber

protected transient int m_DatasetNumber
The current dataset number when the experiment is running


m_PropertyNumber

protected transient int m_PropertyNumber
The current custom property value index when the experiment is running


m_Finished

protected transient boolean m_Finished
True if the experiment has finished running


m_CurrentInstances

protected transient Instances m_CurrentInstances
The dataset currently being used


m_CurrentProperty

protected transient int m_CurrentProperty
The custom property value that has actually been set

Constructor Detail

Experiment

public Experiment()
Method Detail

classFirst

public void classFirst(boolean flag)
Sets whether the first attribute is treated as the class for all datasets involved in the experiment. This information is not output with the result of the experiments!


getAdvanceDataSetFirst

public boolean getAdvanceDataSetFirst()
Get the value of m_DataSetFirstFirst.

Returns:
Value of m_DataSetFirstFirst.

setAdvanceDataSetFirst

public void setAdvanceDataSetFirst(boolean newAdvanceDataSetFirst)
Set the value of m_AdvanceDataSetFirst.


getUsePropertyIterator

public boolean getUsePropertyIterator()
Gets whether the custom property iterator should be used.

Returns:
true if so

setUsePropertyIterator

public void setUsePropertyIterator(boolean newUsePropertyIterator)
Sets whether the custom property iterator should be used.

Parameters:
newUsePropertyIterator - true if so

getPropertyPath

public PropertyNode[] getPropertyPath()
Gets the path of properties taken to get to the custom property to iterate over.

Returns:
an array of PropertyNodes

setPropertyPath

public void setPropertyPath(PropertyNode[] newPropertyPath)
Sets the path of properties taken to get to the custom property to iterate over.

Parameters:
newPropertyPath - an array of PropertyNodes

setPropertyArray

public void setPropertyArray(java.lang.Object newPropArray)
Sets the array of values to set the custom property to.

Parameters:
newPropArray - a value of type Object which should be an array of the appropriate values.

getPropertyArray

public java.lang.Object getPropertyArray()
Gets the array of values to set the custom property to.

Returns:
a value of type Object which should be an array of the appropriate values.

getPropertyArrayLength

public int getPropertyArrayLength()
Gets the number of custom iterator values that have been defined for the experiment.

Returns:
the number of custom property iterator values.

getPropertyArrayValue

public java.lang.Object getPropertyArrayValue(int index)
Gets a specified value from the custom property iterator array.

Parameters:
index - the index of the value wanted
Returns:
the property array value

getCurrentRunNumber

public int getCurrentRunNumber()
When an experiment is running, this returns the current run number.

Returns:
the current run number.

getCurrentDatasetNumber

public int getCurrentDatasetNumber()
When an experiment is running, this returns the current dataset number.

Returns:
the current dataset number.

getCurrentPropertyNumber

public int getCurrentPropertyNumber()
When an experiment is running, this returns the index of the current custom property value.

Returns:
the index of the current custom property value.

initialize

public void initialize()
                throws java.lang.Exception
Prepares an experiment for running, initializing current iterator settings.

Throws:
java.lang.Exception - if an error occurs

determineAdditionalResultMeasures

private void determineAdditionalResultMeasures()
                                        throws java.lang.Exception
Iterate over the objects in the property array to determine what (if any) additional measures they support

Throws:
java.lang.Exception

setProperty

protected void setProperty(int propertyDepth,
                           java.lang.Object origValue)
                    throws java.lang.Exception
Recursively sets the custom property value, by setting all values along the property path.

Parameters:
propertyDepth - the current position along the property path
origValue - the value to set the property to
Throws:
java.lang.Exception - if an error occurs

hasMoreIterations

public boolean hasMoreIterations()
Returns true if there are more iterations to carry out in the experiment.

Returns:
true if so

nextIteration

public void nextIteration()
                   throws java.lang.Exception
Carries out the next iteration of the experiment.

Throws:
java.lang.Exception - if an error occurs

advanceCounters

public void advanceCounters()
Increments iteration counters appropriately.


runExperiment

public void runExperiment()
Runs all iterations of the experiment, continuing past errors.


postProcess

public void postProcess()
                 throws java.lang.Exception
Signals that the experiment is finished running, so that cleanup can be done.

Throws:
java.lang.Exception - if an error occurs

getDatasets

public javax.swing.DefaultListModel getDatasets()
Gets the datasets in the experiment.

Returns:
the datasets in the experiment.

setDatasets

public void setDatasets(javax.swing.DefaultListModel ds)
Set the datasets to use in the experiment

Parameters:
ds - the list of datasets to use

getResultListener

public ResultListener getResultListener()
Gets the result listener where results will be sent.

Returns:
the result listener where results will be sent.

setResultListener

public void setResultListener(ResultListener newResultListener)
Sets the result listener where results will be sent.

Parameters:
newResultListener - the result listener where results will be sent.

getResultProducer

public ResultProducer getResultProducer()
Get the result producer used for the current experiment.

Returns:
the result producer used for the current experiment.

setResultProducer

public void setResultProducer(ResultProducer newResultProducer)
Set the result producer used for the current experiment.

Parameters:
newResultProducer - result producer to use for the current experiment.

getRunUpper

public int getRunUpper()
Get the upper run number for the experiment.

Returns:
the upper run number for the experiment.

setRunUpper

public void setRunUpper(int newRunUpper)
Set the upper run number for the experiment.

Parameters:
newRunUpper - the upper run number for the experiment.

getRunLower

public int getRunLower()
Get the lower run number for the experiment.

Returns:
the lower run number for the experiment.

setRunLower

public void setRunLower(int newRunLower)
Set the lower run number for the experiment.

Parameters:
newRunLower - the lower run number for the experiment.

getNotes

public java.lang.String getNotes()
Get the user notes.

Returns:
User notes associated with the experiment.

setNotes

public void setNotes(java.lang.String newNotes)
Set the user notes.

Parameters:
newNotes - New user notes.

listOptions

public java.util.Enumeration listOptions()
Returns an enumeration describing the available options..

Specified by:
listOptions in interface OptionHandler
Returns:
an enumeration of all the available options.

setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Parses a given list of options. Valid options are:

-L num
The lower run number to start the experiment from. (default 1)

-U num
The upper run number to end the experiment at (inclusive). (default 10)

-T arff_file
The dataset to run the experiment on. (required, may be specified multiple times)

-P class_name
The full class name of a ResultProducer (required). eg: weka.experiment.RandomSplitResultProducer

-D "class_name"
The full class name of a ResultListener followed by any options. If options are supplied then full string must be enclosed in quotes. (required). eg: "weka.experiment.CSVResultListener -O outfile.csv"

All option after -- will be passed to the result producer.

Specified by:
setOptions in interface OptionHandler
Parameters:
options - the list of options as an array of strings
Throws:
java.lang.Exception - if an option is not supported

getOptions

public java.lang.String[] getOptions()
Gets the current settings of the experiment iterator.

Specified by:
getOptions in interface OptionHandler
Returns:
an array of strings suitable for passing to setOptions

toString

public java.lang.String toString()
Gets a string representation of the experiment configuration.

Returns:
a value of type 'String'

main

public static void main(java.lang.String[] args)
Configures/Runs the Experiment from the command line.

Parameters:
args - command line arguments to the Experiment.