Package adams.opt.genetic
Class AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.multiprocess.AbstractJob
-
- adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob<T>
-
- adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T>
-
- All Implemented Interfaces:
adams.core.CleanUpHandler
,adams.core.logging.LoggingLevelHandler
,adams.core.logging.LoggingSupporter
,adams.core.SizeOfHandler
,adams.core.Stoppable
,adams.core.StoppableWithFeedback
,adams.multiprocess.Job
,adams.multiprocess.JobWithOwner<T>
,Serializable
- Direct Known Subclasses:
AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation.ClassifierBasedGeneticAlgorithmWithSecondEvaluationJob
- Enclosing class:
- AbstractClassifierBasedGeneticAlgorithm
public abstract static class AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm> extends adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob<T>
Job class for algorithms with datasets.- Author:
- dale
- See Also:
- Serialized Form
-
-
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
-
-
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.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
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 tochromosome
- the chromsome indexw
- the initial weightsdata
- the data to usetestData
- 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 classadams.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 evaluatedata
- the data to use for evaluationfolds
- the number of folds to useseed
- 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 evaluatedata
- the data to use for evaluationtest
- 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 fitnessdata
- the datasetext
- 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/fitnessdata
- 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 fitnesscls
- the current classifierchromosome
- the chromosome responsibleweights
- 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/fitnessdata
- the datasetcls
- the current classifier setupchromosome
- the chromosome responsibleweights
- 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 fitnessdata
- the datasetcls
- the current classifierchromosome
- the chromosome responsibleweights
- the current weights/bits- Throws:
Exception
- if output fails
-
-