Package adams.multiprocess
Class WekaCrossValidationExecution
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.multiprocess.WekaCrossValidationExecution
-
- All Implemented Interfaces:
adams.core.CleanUpHandler,adams.core.logging.LoggingLevelHandler,adams.core.logging.LoggingSupporter,adams.core.SizeOfHandler,adams.core.Stoppable,adams.core.ThreadLimiter,InstancesViewSupporter,adams.flow.core.FlowContextHandler,Serializable
public class WekaCrossValidationExecution extends adams.core.logging.CustomLoggingLevelObject implements adams.core.Stoppable, InstancesViewSupporter, adams.core.ThreadLimiter, adams.flow.core.FlowContextHandler, adams.core.CleanUpHandler
Performs cross-validation, either single or multi-threaded.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intm_ActualFoldsthe actual folds used.protected adams.multiprocess.JobRunnerm_ActualJobRunnerthe runner in use.protected intm_ActualNumThreadsthe actual number of threads to use.protected weka.classifiers.Classifierm_Classifierthe classifier to evaluate.protected weka.classifiers.Classifier[]m_Classifiersthe separate classifiers.protected weka.classifiers.Classifierm_CurrentClassifierthe current classifier that is being trained.protected StoppableEvaluationm_CurrentEvaluationthe evaluation currently being run.protected weka.core.Instancesm_Datathe data to evaluate on.protected booleanm_DiscardPredictionswhether to discard predictions.protected weka.classifiers.Evaluationm_Evaluationthe (aggregated) evaluation.protected weka.classifiers.Evaluation[]m_Evaluationsthe separate evaluations.protected adams.flow.core.Actorm_FlowContextthe flow context.protected intm_Foldsthe number of folds.protected CrossValidationFoldGeneratorm_Generatorthe cross-validation fold generator.protected adams.multiprocess.JobRunnerm_JobRunnerthe jobrunner template.protected adams.flow.standalone.JobRunnerSetupm_JobRunnerSetupthe jobrunner setup.protected intm_NumThreadsthe number of threads to use for parallel execution (only used if no JobRunnerSetup/JobRunner set).protected int[]m_OriginalIndicesthe original indices.protected int[][]m_OriginalIndicesFoldsthe original indices per fold.protected weka.classifiers.evaluation.output.prediction.AbstractOutputm_Outputfor generating predictions output.protected StringBufferm_OutputBufferthe buffer for the predictions.protected longm_Seedthe seed value.protected booleanm_SeparateFoldswhether to separate folds.protected adams.core.StatusMessageHandlerm_StatusMessageHandlerfor outputting notifications.protected booleanm_Stoppedwhether the execution has been stopped.protected booleanm_UseViewswhether to use views.protected booleanm_WaitForJobswhether to wait for jobs to finish when stopping.
-
Constructor Summary
Constructors Constructor Description WekaCrossValidationExecution()Initializes the execution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanUp()Cleans up data structures, frees up memory.Stringexecute()Executes the flow item.intgetActualFolds()Returns the actual number of folds used.weka.classifiers.ClassifiergetClassifier()Returns the classifier in use.weka.classifiers.Classifier[]getClassifiers()Returns the classifiers per fold.weka.core.InstancesgetData()Returns the data in use.booleangetDiscardPredictions()Returns whether to discard the predictions in order to preserve memory.weka.classifiers.EvaluationgetEvaluation()Returns the generated (aggregated) evaluation.weka.classifiers.Evaluation[]getEvaluations()Returns the generated evaluations (if multi-threaded or separated).adams.flow.core.ActorgetFlowContext()Returns the flow context, if any.intgetFolds()Returns the number of folds.CrossValidationFoldGeneratorgetGenerator()Returns the generator to use for generating the folds.adams.multiprocess.JobRunnergetJobRunner()Returns the JobRunner, if any.adams.flow.standalone.JobRunnerSetupgetJobRunnerSetup()Returns the JobRunnerSetup, if any.intgetNumThreads()Returns the number of threads to use for cross-validation (only used if no JobRunnerSetup/JobRunner set).int[]getOriginalIndices()Returns the original indices.int[][]getOriginalIndicesFolds()Returns the original indices per fold.weka.classifiers.evaluation.output.prediction.AbstractOutputgetOutput()Returns the prediction output generator in use.StringBuffergetOutputBuffer()Returns the output buffer.longgetSeed()Returns the seed value.booleangetSeparateFolds()Returns whether to separate the folds, an Evaluation object per fold.adams.core.StatusMessageHandlergetStatusMessageHandler()Returns the status message handler for outputting notifications.booleangetUseViews()Returns whether to use views instead of dataset copies, in order to conserve memory.booleangetWaitForJobs()Returns whether to wait for jobs to finish when terminating.protected voidinitOutputBuffer()Initializes the output buffer.booleanisSingleThreaded()Returns whether the execution was single-threaded (afterexecute()).booleanisStopped()Returns whether the execution has been stopped.voidsetClassifier(weka.classifiers.Classifier value)Sets the classifier to use.voidsetData(weka.core.Instances value)Sets the data to use.voidsetDiscardPredictions(boolean value)Sets whether to discard the predictions instead of collecting them for future use, in order to conserve memory.voidsetFlowContext(adams.flow.core.Actor value)Sets the flow context.voidsetFolds(int value)Sets the number of folds.voidsetGenerator(CrossValidationFoldGenerator value)Sets the generator to use for generating the folds.voidsetJobRunner(adams.multiprocess.JobRunner value)Sets the JobRunner.voidsetJobRunnerSetup(adams.flow.standalone.JobRunnerSetup value)Sets the JobRunnerSetup.voidsetNumThreads(int value)Sets the number of threads to use for cross-validation (only used if no JobRunnerSetup/JobRunner set).voidsetOutput(weka.classifiers.evaluation.output.prediction.AbstractOutput value)Sets the prediction output generator to use.voidsetSeed(long value)Sets the seed value.voidsetSeparateFolds(boolean value)Sets whether to separate the folds, an Evaluation object per fold.voidsetStatusMessageHandler(adams.core.StatusMessageHandler value)Sets the status message handler for outputting notifications.voidsetUseViews(boolean value)Sets whether to use views instead of dataset copies, in order to conserve memory.voidsetWaitForJobs(boolean value)Sets whether to wait for jobs to finish when terminating.voidstopExecution()Stops the execution.-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
-
-
-
Field Detail
-
m_Classifier
protected weka.classifiers.Classifier m_Classifier
the classifier to evaluate.
-
m_Data
protected weka.core.Instances m_Data
the data to evaluate on.
-
m_Output
protected weka.classifiers.evaluation.output.prediction.AbstractOutput m_Output
for generating predictions output.
-
m_OutputBuffer
protected StringBuffer m_OutputBuffer
the buffer for the predictions.
-
m_Folds
protected int m_Folds
the number of folds.
-
m_ActualFolds
protected int m_ActualFolds
the actual folds used.
-
m_SeparateFolds
protected boolean m_SeparateFolds
whether to separate folds.
-
m_Seed
protected long m_Seed
the seed value.
-
m_UseViews
protected boolean m_UseViews
whether to use views.
-
m_Generator
protected CrossValidationFoldGenerator m_Generator
the cross-validation fold generator.
-
m_DiscardPredictions
protected boolean m_DiscardPredictions
whether to discard predictions.
-
m_NumThreads
protected int m_NumThreads
the number of threads to use for parallel execution (only used if no JobRunnerSetup/JobRunner set).
-
m_ActualNumThreads
protected int m_ActualNumThreads
the actual number of threads to use.
-
m_JobRunnerSetup
protected transient adams.flow.standalone.JobRunnerSetup m_JobRunnerSetup
the jobrunner setup.
-
m_JobRunner
protected transient adams.multiprocess.JobRunner m_JobRunner
the jobrunner template.
-
m_ActualJobRunner
protected transient adams.multiprocess.JobRunner m_ActualJobRunner
the runner in use.
-
m_Evaluation
protected weka.classifiers.Evaluation m_Evaluation
the (aggregated) evaluation.
-
m_Evaluations
protected weka.classifiers.Evaluation[] m_Evaluations
the separate evaluations.
-
m_Classifiers
protected weka.classifiers.Classifier[] m_Classifiers
the separate classifiers.
-
m_OriginalIndices
protected int[] m_OriginalIndices
the original indices.
-
m_OriginalIndicesFolds
protected int[][] m_OriginalIndicesFolds
the original indices per fold.
-
m_Stopped
protected boolean m_Stopped
whether the execution has been stopped.
-
m_StatusMessageHandler
protected adams.core.StatusMessageHandler m_StatusMessageHandler
for outputting notifications.
-
m_WaitForJobs
protected boolean m_WaitForJobs
whether to wait for jobs to finish when stopping.
-
m_FlowContext
protected transient adams.flow.core.Actor m_FlowContext
the flow context.
-
m_CurrentEvaluation
protected transient StoppableEvaluation m_CurrentEvaluation
the evaluation currently being run.
-
m_CurrentClassifier
protected transient weka.classifiers.Classifier m_CurrentClassifier
the current classifier that is being trained.
-
-
Method Detail
-
setFlowContext
public void setFlowContext(adams.flow.core.Actor value)
Sets the flow context.- Specified by:
setFlowContextin interfaceadams.flow.core.FlowContextHandler- Parameters:
value- the actor
-
getFlowContext
public adams.flow.core.Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContextin interfaceadams.flow.core.FlowContextHandler- Returns:
- the actor, null if none available
-
setJobRunnerSetup
public void setJobRunnerSetup(adams.flow.standalone.JobRunnerSetup value)
Sets the JobRunnerSetup.- Parameters:
value- the setup
-
getJobRunnerSetup
public adams.flow.standalone.JobRunnerSetup getJobRunnerSetup()
Returns the JobRunnerSetup, if any.- Returns:
- the JobRunnerSetup, null if none available
-
setJobRunner
public void setJobRunner(adams.multiprocess.JobRunner value)
Sets the JobRunner.- Parameters:
value- the template
-
getJobRunner
public adams.multiprocess.JobRunner getJobRunner()
Returns the JobRunner, if any.- Returns:
- the JobRunner, null if none available
-
setWaitForJobs
public void setWaitForJobs(boolean value)
Sets whether to wait for jobs to finish when terminating.- Parameters:
value- true if to wait
-
getWaitForJobs
public boolean getWaitForJobs()
Returns whether to wait for jobs to finish when terminating.- Returns:
- true if to wait
-
setClassifier
public void setClassifier(weka.classifiers.Classifier value)
Sets the classifier to use.- Parameters:
value- the classifier
-
getClassifier
public weka.classifiers.Classifier getClassifier()
Returns the classifier in use.- Returns:
- the classifier
-
getClassifiers
public weka.classifiers.Classifier[] getClassifiers()
Returns the classifiers per fold.- Returns:
- the classifiers, null if not stored
-
setData
public void setData(weka.core.Instances value)
Sets the data to use.- Parameters:
value- the data
-
getData
public weka.core.Instances getData()
Returns the data in use.- Returns:
- the data
-
setOutput
public void setOutput(weka.classifiers.evaluation.output.prediction.AbstractOutput value)
Sets the prediction output generator to use.- Parameters:
value- the output generator
-
getOutput
public weka.classifiers.evaluation.output.prediction.AbstractOutput getOutput()
Returns the prediction output generator in use.- Returns:
- the output generator
-
setFolds
public void setFolds(int value)
Sets the number of folds.- Parameters:
value- the folds, <2 for LOOCV
-
getFolds
public int getFolds()
Returns the number of folds.- Returns:
- the folds
-
getActualFolds
public int getActualFolds()
Returns the actual number of folds used.- Returns:
- the actual folds, -1 if not yet determined
-
setSeparateFolds
public void setSeparateFolds(boolean value)
Sets whether to separate the folds, an Evaluation object per fold.- Parameters:
value- true if to separate
-
getSeparateFolds
public boolean getSeparateFolds()
Returns whether to separate the folds, an Evaluation object per fold.- Returns:
- true if to separate
-
setSeed
public void setSeed(long value)
Sets the seed value.- Parameters:
value- the seed
-
getSeed
public long getSeed()
Returns the seed value.- Returns:
- the seed
-
setUseViews
public void setUseViews(boolean value)
Sets whether to use views instead of dataset copies, in order to conserve memory.- Specified by:
setUseViewsin interfaceInstancesViewSupporter- Parameters:
value- true if to use views
-
getUseViews
public boolean getUseViews()
Returns whether to use views instead of dataset copies, in order to conserve memory.- Specified by:
getUseViewsin interfaceInstancesViewSupporter- Returns:
- true if using views
-
setGenerator
public void setGenerator(CrossValidationFoldGenerator value)
Sets the generator to use for generating the folds.- Parameters:
value- the generator
-
getGenerator
public CrossValidationFoldGenerator getGenerator()
Returns the generator to use for generating the folds.- Returns:
- the generator
-
setDiscardPredictions
public void setDiscardPredictions(boolean value)
Sets whether to discard the predictions instead of collecting them for future use, in order to conserve memory. NB: Must be false in case of parallel execution to allow for aggregation of statistics;- Parameters:
value- true if to discard predictions
-
getDiscardPredictions
public boolean getDiscardPredictions()
Returns whether to discard the predictions in order to preserve memory. NB: Must be false in case of parallel execution to allow for aggregation of statistics;- Returns:
- true if predictions discarded
-
setNumThreads
public void setNumThreads(int value)
Sets the number of threads to use for cross-validation (only used if no JobRunnerSetup/JobRunner set).- Specified by:
setNumThreadsin interfaceadams.core.ThreadLimiter- Parameters:
value- the number of threads: -1 = # of CPUs/cores; 0/1 = sequential execution
-
getNumThreads
public int getNumThreads()
Returns the number of threads to use for cross-validation (only used if no JobRunnerSetup/JobRunner set).- Specified by:
getNumThreadsin interfaceadams.core.ThreadLimiter- Returns:
- the number of threads: -1 = # of CPUs/cores; 0/1 = sequential execution
-
setStatusMessageHandler
public void setStatusMessageHandler(adams.core.StatusMessageHandler value)
Sets the status message handler for outputting notifications.- Parameters:
value- the handler
-
getStatusMessageHandler
public adams.core.StatusMessageHandler getStatusMessageHandler()
Returns the status message handler for outputting notifications.- Returns:
- the handler, null if none set
-
initOutputBuffer
protected void initOutputBuffer()
Initializes the output buffer.
-
getOutputBuffer
public StringBuffer getOutputBuffer()
Returns the output buffer.- Returns:
- the output buffer
-
getEvaluation
public weka.classifiers.Evaluation getEvaluation()
Returns the generated (aggregated) evaluation.- Returns:
- the evaluation
-
getEvaluations
public weka.classifiers.Evaluation[] getEvaluations()
Returns the generated evaluations (if multi-threaded or separated).- Returns:
- the evaluations, null if not multi-threaded or not separated
-
getOriginalIndices
public int[] getOriginalIndices()
Returns the original indices.- Returns:
- the indices
-
getOriginalIndicesFolds
public int[][] getOriginalIndicesFolds()
Returns the original indices per fold.- Returns:
- the indices, null if not available
-
isSingleThreaded
public boolean isSingleThreaded()
Returns whether the execution was single-threaded (afterexecute()).- Returns:
- true if single-threaded
-
execute
public String execute()
Executes the flow item.- Returns:
- null if everything is fine, otherwise error message
-
isStopped
public boolean isStopped()
Returns whether the execution has been stopped.- Returns:
- true if stopped
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceadams.core.Stoppable
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceadams.core.CleanUpHandler
-
-