Class AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm>

    • 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
      • 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