Class AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int m_ClassLabelIndex
      the class label index.
      protected weka.core.Instances m_Data
      the data to use.
      protected int m_Folds
      the cross-validation folds.
      protected Measure m_Measure
      the measure to use for evaluating the fitness.
      protected int m_Seed
      the cross-validation seed.
      protected weka.core.Instances m_TestData
      the test data to use (can be null).
      • Fields inherited from class adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob

        m_Chromosome, m_Fitness, m_Genetic, m_Weights
      • Fields inherited from class adams.multiprocess.AbstractJob

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

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassifierBasedGeneticAlgorithmJob​(T g, int chromosome, int[] w, weka.core.Instances data, weka.core.Instances testData)
      Initializes the job.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected Map<String,​Object> assembleSetup​(double fitness, weka.classifiers.Classifier cls, int chromosome, int[] weights)
      Assembles the data for the textual setup output.
      protected File createFileName​(double fitness, weka.core.Instances data, String ext)
      Generates a file name for the fitness.
      protected double evaluateClassifier​(weka.classifiers.Classifier cls, weka.core.Instances data, int folds, int seed)
      Evaluates the classifier on the dataset and returns the metric.
      protected double evaluateClassifier​(weka.classifiers.Classifier cls, weka.core.Instances data, weka.core.Instances test)
      Evaluates the classifier on the dataset and returns the metric.
      protected void generateOutput​(double fitness, weka.core.Instances data, weka.classifiers.Classifier cls, int chromosome, int[] weights)
      Generates the output requested output.
      int getFolds()
      Returns the number of cross-validation folds.
      protected weka.core.Instances getInstances()
      Returns the instances in use by the genetic algorithm.
      Measure getMeasure()
      Returns the measure used for evaluating the fitness.
      int getSeed()
      Returns the cross-validation seed.
      protected weka.core.Instances getTestInstances()
      Returns the test instances in use by the genetic algorithm.
      protected void outputDataset​(double fitness, weka.core.Instances data)
      Saves the instances to a file.
      protected void outputSetup​(double fitness, weka.core.Instances data, weka.classifiers.Classifier cls, int chromosome, int[] weights)
      Saves the setup to a props file.
      protected weka.classifiers.Evaluation postProcess​(weka.classifiers.Evaluation eval)
      Post-processes the Evaluation if necessary.
      protected String preProcessCheck()
      Checks whether all pre-conditions have been met.
      • Methods inherited from class adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob

        calcNewFitness, cleanUp, getChromosome, getFitness, getOwner, getWeights, postProcessCheck, process, toString, weightsToString, weightsToString
      • Methods inherited from class adams.multiprocess.AbstractJob

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

        setLoggingLevel
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.multiprocess.Job

        execute, getExecutionError, getJobCompleteListener, getJobInfo, hasExecutionError, isComplete, jobCompleted, setJobCompleteListener
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
      • Methods inherited from interface adams.core.logging.LoggingSupporter

        getLogger, isLoggingEnabled
      • Methods inherited from interface adams.core.Stoppable

        stopExecution
      • Methods inherited from interface adams.core.StoppableWithFeedback

        isStopped
    • Field Detail

      • m_Measure

        protected Measure m_Measure
        the measure to use for evaluating the fitness.
      • m_ClassLabelIndex

        protected int m_ClassLabelIndex
        the class label index.
      • m_Data

        protected weka.core.Instances m_Data
        the data to use.
      • m_TestData

        protected weka.core.Instances m_TestData
        the test data to use (can be null).
      • m_Seed

        protected int m_Seed
        the cross-validation seed.
      • m_Folds

        protected int m_Folds
        the cross-validation folds.
    • Constructor Detail

      • ClassifierBasedGeneticAlgorithmJob

        public ClassifierBasedGeneticAlgorithmJob​(T g,
                                                  int chromosome,
                                                  int[] w,
                                                  weka.core.Instances data,
                                                  weka.core.Instances testData)
        Initializes the job.
        Parameters:
        g - the algorithm object this job belongs to
        chromosome - the chromsome index
        w - the initial weights
        data - the data to use
        testData - the test data to use, null for cross-validation
    • Method Detail

      • getInstances

        protected weka.core.Instances getInstances()
        Returns the instances in use by the genetic algorithm.
        Returns:
        the instances
      • getTestInstances

        protected weka.core.Instances getTestInstances()
        Returns the test instances in use by the genetic algorithm.
        Returns:
        the instances
      • getMeasure

        public Measure getMeasure()
        Returns the measure used for evaluating the fitness.
        Returns:
        the measure
      • getSeed

        public int getSeed()
        Returns the cross-validation seed.
        Returns:
        the seed
      • getFolds

        public int getFolds()
        Returns the number of cross-validation folds.
        Returns:
        the number of folds
      • preProcessCheck

        protected String preProcessCheck()
        Checks whether all pre-conditions have been met.
        Overrides:
        preProcessCheck in class adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm>
        Returns:
        null if everything is OK, otherwise an error message
      • postProcess

        protected weka.classifiers.Evaluation postProcess​(weka.classifiers.Evaluation eval)
        Post-processes the Evaluation if necessary.
        Parameters:
        eval - the evaluation to post-process
        Returns:
        the (potentially) updated evaluation
      • evaluateClassifier

        protected double evaluateClassifier​(weka.classifiers.Classifier cls,
                                            weka.core.Instances data,
                                            int folds,
                                            int seed)
                                     throws Exception
        Evaluates the classifier on the dataset and returns the metric.
        Parameters:
        cls - the classifier to evaluate
        data - the data to use for evaluation
        folds - the number of folds to use
        seed - the seed for the randomization
        Returns:
        the metric
        Throws:
        Exception - if the evaluation fails
      • evaluateClassifier

        protected double evaluateClassifier​(weka.classifiers.Classifier cls,
                                            weka.core.Instances data,
                                            weka.core.Instances test)
                                     throws Exception
        Evaluates the classifier on the dataset and returns the metric.
        Parameters:
        cls - the classifier to evaluate
        data - the data to use for evaluation
        test - the test data to use
        Returns:
        the metric
        Throws:
        Exception - if the evaluation fails
      • createFileName

        protected File createFileName​(double fitness,
                                      weka.core.Instances data,
                                      String ext)
        Generates a file name for the fitness.
        Parameters:
        fitness - the current fitness
        data - the dataset
        ext - the extension (not dot!)
        Returns:
        the file
      • outputDataset

        protected void outputDataset​(double fitness,
                                     weka.core.Instances data)
                              throws Exception
        Saves the instances to a file.
        Parameters:
        fitness - the current measure/fitness
        data - the instances to save
        Throws:
        Exception - if saving the file fails
      • assembleSetup

        protected Map<String,​Object> assembleSetup​(double fitness,
                                                         weka.classifiers.Classifier cls,
                                                         int chromosome,
                                                         int[] weights)
        Assembles the data for the textual setup output.
        Parameters:
        fitness - the current fitness
        cls - the current classifier
        chromosome - the chromosome responsible
        weights - the weights
        Returns:
        the data
      • outputSetup

        protected void outputSetup​(double fitness,
                                   weka.core.Instances data,
                                   weka.classifiers.Classifier cls,
                                   int chromosome,
                                   int[] weights)
                            throws Exception
        Saves the setup to a props file.
        Parameters:
        fitness - the current measure/fitness
        data - the dataset
        cls - the current classifier setup
        chromosome - the chromosome responsible
        weights - the current weights/bits
        Throws:
        Exception - if saving the file fails
      • generateOutput

        protected void generateOutput​(double fitness,
                                      weka.core.Instances data,
                                      weka.classifiers.Classifier cls,
                                      int chromosome,
                                      int[] weights)
                               throws Exception
        Generates the output requested output.
        Parameters:
        fitness - the current fitness
        data - the dataset
        cls - the current classifier
        chromosome - the chromosome responsible
        weights - the current weights/bits
        Throws:
        Exception - if output fails