Class WekaCrossValidationJob

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.logging.LoggingSupporter, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, adams.flow.core.FlowContextHandler, adams.multiprocess.Job, Serializable

    public class WekaCrossValidationJob
    extends adams.multiprocess.AbstractJob
    implements adams.flow.core.FlowContextHandler
    For evaluation of a single train/test fold in parallel.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected weka.classifiers.Classifier m_Classifier
      the classifier to evaluate.
      protected boolean m_DiscardPredictions
      whether to discard the predictions.
      protected weka.classifiers.Evaluation m_Evaluation
      the evaluation.
      protected adams.flow.core.Actor m_FlowContext
      the flow context.
      protected int m_Fold
      the fold.
      protected adams.core.StatusMessageHandler m_StatusMessageHandler
      for outputting notifications.
      protected weka.core.Instances m_Test
      the test set.
      protected weka.core.Instances m_Train
      the training set.
      • Fields inherited from class adams.multiprocess.AbstractJob

        m_Complete, m_ExecutionError, m_JobCompleteListener, m_JobInfo, m_Stopped
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      WekaCrossValidationJob​(weka.classifiers.Classifier classifier, weka.core.Instances train, weka.core.Instances test, int fold, boolean discardPred)
      Initializes the job.
      WekaCrossValidationJob​(weka.classifiers.Classifier classifier, weka.core.Instances train, weka.core.Instances test, int fold, boolean discardPred, adams.core.StatusMessageHandler handler)
      Initializes the job.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cleanUp()
      Cleans up data structures, frees up memory.
      weka.classifiers.Classifier getClassifier()
      Returns the classifier (should be built after the job finished).
      boolean getDiscardPredictions()
      Returns whether the predictions are discarded.
      weka.classifiers.Evaluation getEvaluation()
      Returns the generated evaluation object.
      adams.flow.core.Actor getFlowContext()
      Returns the flow context, if any.
      int getFold()
      Returns the fold index.
      adams.core.StatusMessageHandler getStatusMessageHandler()
      Returns the status message handler.
      weka.core.Instances getTest()
      Returns the test set.
      weka.core.Instances getTrain()
      Returns the training set.
      protected String postProcessCheck()
      Checks whether all post-conditions have been met.
      protected String preProcessCheck()  
      protected void process()
      Does the actual execution of the job.
      void setFlowContext​(adams.flow.core.Actor value)
      Sets the flow context.
      String toString()
      Returns a string representation of this job.
      • Methods inherited from class adams.multiprocess.AbstractJob

        execute, getAdditionalErrorInformation, getExecutionError, getJobCompleteListener, getJobInfo, hasExecutionError, isComplete, isStopped, jobCompleted, setJobCompleteListener, setJobInfo, stopExecution
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingSupporter

        getLogger, isLoggingEnabled
    • Field Detail

      • m_Classifier

        protected weka.classifiers.Classifier m_Classifier
        the classifier to evaluate.
      • m_Fold

        protected int m_Fold
        the fold.
      • m_Train

        protected weka.core.Instances m_Train
        the training set.
      • m_Test

        protected weka.core.Instances m_Test
        the test set.
      • m_DiscardPredictions

        protected boolean m_DiscardPredictions
        whether to discard the predictions.
      • m_Evaluation

        protected weka.classifiers.Evaluation m_Evaluation
        the evaluation.
      • m_StatusMessageHandler

        protected transient adams.core.StatusMessageHandler m_StatusMessageHandler
        for outputting notifications.
      • m_FlowContext

        protected transient adams.flow.core.Actor m_FlowContext
        the flow context.
    • Constructor Detail

      • WekaCrossValidationJob

        public WekaCrossValidationJob​(weka.classifiers.Classifier classifier,
                                      weka.core.Instances train,
                                      weka.core.Instances test,
                                      int fold,
                                      boolean discardPred)
        Initializes the job.
        Parameters:
        classifier - the classifier to evaluate
        train - the training set
        test - the test set
        fold - the fold index
        discardPred - whether to discard the predictions
      • WekaCrossValidationJob

        public WekaCrossValidationJob​(weka.classifiers.Classifier classifier,
                                      weka.core.Instances train,
                                      weka.core.Instances test,
                                      int fold,
                                      boolean discardPred,
                                      adams.core.StatusMessageHandler handler)
        Initializes the job.
        Parameters:
        classifier - the classifier to evaluate
        train - the training set
        test - the test set
        fold - the fold index
        discardPred - whether to discard the predictions
        handler - for displaying notifications, can be null
    • Method Detail

      • setFlowContext

        public void setFlowContext​(adams.flow.core.Actor value)
        Sets the flow context.
        Specified by:
        setFlowContext in interface adams.flow.core.FlowContextHandler
        Parameters:
        value - the actor
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the flow context, if any.
        Specified by:
        getFlowContext in interface adams.flow.core.FlowContextHandler
        Returns:
        the actor, null if none available
      • getTrain

        public weka.core.Instances getTrain()
        Returns the training set.
        Returns:
        the dataset
      • getTest

        public weka.core.Instances getTest()
        Returns the test set.
        Returns:
        the dataset
      • getFold

        public int getFold()
        Returns the fold index.
        Returns:
        the fold
      • getDiscardPredictions

        public boolean getDiscardPredictions()
        Returns whether the predictions are discarded.
        Returns:
        true if discarded
      • getStatusMessageHandler

        public adams.core.StatusMessageHandler getStatusMessageHandler()
        Returns the status message handler.
        Returns:
        the handler
      • getEvaluation

        public weka.classifiers.Evaluation getEvaluation()
        Returns the generated evaluation object.
        Returns:
        the evaluation, null if not available
      • getClassifier

        public weka.classifiers.Classifier getClassifier()
        Returns the classifier (should be built after the job finished).
        Returns:
        the classifier
      • preProcessCheck

        protected String preProcessCheck()
        Specified by:
        preProcessCheck in class adams.multiprocess.AbstractJob
      • process

        protected void process()
                        throws Exception
        Does the actual execution of the job.
        Specified by:
        process in class adams.multiprocess.AbstractJob
        Throws:
        Exception - if fails to execute job
      • postProcessCheck

        protected String postProcessCheck()
        Checks whether all post-conditions have been met.
        Specified by:
        postProcessCheck in class adams.multiprocess.AbstractJob
        Returns:
        null if everything is OK, otherwise an error message
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory. Removes dependencies and job parameters.
        Specified by:
        cleanUp in interface adams.core.CleanUpHandler
        Specified by:
        cleanUp in interface adams.multiprocess.Job
        Overrides:
        cleanUp in class adams.multiprocess.AbstractJob
      • toString

        public String toString()
        Returns a string representation of this job.
        Specified by:
        toString in class adams.multiprocess.AbstractJob
        Returns:
        the job as string