Package adams.opt.genetic
Class AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.opt.genetic.AbstractGeneticAlgorithm
-
- adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithm
-
- adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation
-
- All Implemented Interfaces:
adams.core.Destroyable
,adams.core.GlobalInfoSupporter
,adams.core.logging.LoggingLevelHandler
,adams.core.logging.LoggingSupporter
,adams.core.option.OptionHandler
,adams.core.Pausable
,adams.core.Randomizable
,adams.core.ShallowCopySupporter<adams.opt.genetic.AbstractGeneticAlgorithm>
,adams.core.SizeOfHandler
,adams.core.Stoppable
,adams.core.StoppableWithFeedback
,adams.core.ThreadLimiter
,adams.event.GeneticFitnessChangeNotifier
,Serializable
public abstract class AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation extends AbstractClassifierBasedGeneticAlgorithm
Ancestor for genetic algorithms that offer a second evaluation using a different seed value. The fitness value of the first evaluation only gets added if it the best one so far and the evaluation with the second seed value also generates the best value so far (using a second set of stored results).- Version:
- $Revision$
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation.ClassifierBasedGeneticAlgorithmWithSecondEvaluationJob<T extends AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation>
Job class for algorithms with datasets.-
Nested classes/interfaces inherited from class adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithm
AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob<T extends AbstractClassifierBasedGeneticAlgorithm>
-
-
Field Summary
Fields Modifier and Type Field Description protected double
m_SecondBestFitness
the best fitness so far (second evaluation).protected Object
m_SecondBestSetup
the best setup so far (second evaluation).protected int[]
m_SecondBestWeights
the best weights/bits so far (second evaluation).protected int
m_SecondCrossValidationSeed
the cross-validation seed (second evaluation).protected int
m_SecondFolds
the number of folds for cross-validation (second evaluation).Hashtable<String,Double>
m_SecondStoredResults
the cache for results (second evaluation).protected boolean
m_UseSecondEvaluation
whether to use second evaluation with different seed.-
Fields inherited from class adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithm
m_BitsPerGene, m_Classifier, m_ClassIndex, m_ClassLabelIndex, m_CrossValidationSeed, m_EvaluationPostProcessor, m_FlowContext, m_Folds, m_Generator, m_Instances, m_JobRunner, m_JobRunnerSetup, m_Measure, m_OutputDirectory, m_OutputPrefixType, m_OutputType, m_SetupUpload, m_StoredResults, m_SuppliedPrefix, m_TestInstances, PROPS_FILTER, PROPS_MASK, PROPS_RELATION
-
Fields inherited from class adams.opt.genetic.AbstractGeneticAlgorithm
m_ActualNumChrom, m_BestFitness, m_BestRange, m_BestSetup, m_BestWeights, m_CurrentIteration, m_FavorZeroes, m_Fitness, m_FitnessChangeListeners, m_FitnessHistory, m_Genes, m_InitialSetupsProvider, m_InitialWeights, m_LastNotificationTime, m_MaxFitnessHistorySize, m_NotificationInterval, m_NumChrom, m_NumGenes, m_NumThreads, m_Paused, m_Random, m_Running, m_Seed, m_Stopped, m_StoppingCriterion
-
-
Constructor Summary
Constructors Constructor Description AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addSecondResult(String key, Double val)
Adds a result to the cache (second evaluation).protected void
clearResults()
Clears all currently stored results.void
defineOptions()
Adds options to the internal list of options.int
getSecondCrossValidationSeed()
Returns the current seed value for cross-validation (second evaluation).int
getSecondFolds()
Returns the number of folds to use in cross-validation (second evaluation).protected Double
getSecondResult(String key)
Returns a value from the cache (second evaluation).boolean
getUseSecondEvaluation()
Returns whether to use the second evaluation.protected void
initialize()
Initializes the members.boolean
isSecondBetterFitness(double fitness)
Checks whether the fitness is better (second evaluation).protected void
preRun()
Further initializations in derived classes.String
secondCrossValidationSeedTipText()
Returns the tip text for this property.String
secondFoldsTipText()
Returns the tip text for this property.void
setSecondCrossValidationSeed(int value)
Sets the seed value to use for cross-validation (second evaluation).void
setSecondFolds(int value)
Sets the number of folds to use in cross-validation (second evaluation).boolean
setSecondNewFitness(double fitness, Object setup, int chromosome, int[] weights)
Sets a fitness and keep it if better (second evaluation).void
setUseSecondEvaluation(boolean value)
Sets whether to use the second evaluation.String
useSecondEvaluationTipText()
Returns the tip text for this property.-
Methods inherited from class adams.opt.genetic.AbstractClassifierBasedGeneticAlgorithm
addResult, bitsPerGeneTipText, calcFitness, classifierTipText, classIndexTipText, classLabelIndexTipText, crossValidationSeedTipText, evaluationPostProcessorTipText, foldsTipText, generatorTipText, getBitsPerGene, getClassifier, getClassIndex, getClassLabelIndex, getCrossValidationSeed, getCurrentFitness, getDefaultClassifier, getDefaultOutputType, getEvaluationPostProcessor, getFlowContext, getFolds, getGenerator, getInstances, getJobRunnerSetup, getMeasure, getOutputDirectory, getOutputPrefixType, getOutputType, getResult, getSetupUpload, getSuppliedPrefix, getTestInstances, measureTipText, newJob, outputDirectoryTipText, outputPrefixTypeTipText, outputTypeTipText, postRun, setBitsPerGene, setClassifier, setClassIndex, setClassLabelIndex, setCrossValidationSeed, setEvaluationPostProcessor, setFlowContext, setFolds, setGenerator, setInstances, setJobRunnerSetup, setMeasure, setOutputDirectory, setOutputPrefixType, setOutputType, setSetupUpload, setSuppliedPrefix, setTestInstances, setupUploadTipText, stopExecution, storeSetup, suppliedPrefixTipText, toString, updateHeader
-
Methods inherited from class adams.opt.genetic.AbstractGeneticAlgorithm
addFitnessChangeListener, addToFitnessHistory, bestRangeTipText, copyGene, doCrossovers, doMutations, doMutations2, favorZeroesTipText, forCommandLine, forName, getBestRange, getCurrentIteration, getCurrentSetup, getCurrentWeights, getDefaultInitialSetupsProvider, getFavorZeroes, getFitness, getFitnessHistory, getGene, getGeneticAlgorithms, getInitialSetups, getInitialSetupsProvider, getInitialWeights, getMaxFitnessHistorySize, getNotificationInterval, getNumChrom, getNumGenes, getNumThreads, getSeed, getStoppingCriterion, hasMoreZeroes, init, initialSetupsProviderTipText, initialWeightsTipText, isBetterFitness, isPaused, isRunning, isStopped, logChromosomes, maxFitnessHistorySizeTipText, notificationIntervalTipText, notifyFitnessChangeListeners, notifyFitnessChangeListeners, numChromTipText, numThreadsTipText, pauseExecution, removeFitnessChangeListener, reset, resumeExecution, run, runGeneticAlgorithm, seedTipText, setBestRange, setBestRange, setFavorZeroes, setGene, setGene, setInitialSetupsProvider, setInitialWeights, setMaxFitnessHistorySize, setNewFitness, setNotificationInterval, setNumChrom, setNumThreads, setSeed, setStoppingCriterion, shallowCopy, shallowCopy, sort, stoppingCriterionTipText
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine
-
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_UseSecondEvaluation
protected boolean m_UseSecondEvaluation
whether to use second evaluation with different seed.
-
m_SecondFolds
protected int m_SecondFolds
the number of folds for cross-validation (second evaluation).
-
m_SecondCrossValidationSeed
protected int m_SecondCrossValidationSeed
the cross-validation seed (second evaluation).
-
m_SecondStoredResults
public Hashtable<String,Double> m_SecondStoredResults
the cache for results (second evaluation).
-
m_SecondBestFitness
protected double m_SecondBestFitness
the best fitness so far (second evaluation).
-
m_SecondBestSetup
protected Object m_SecondBestSetup
the best setup so far (second evaluation).
-
m_SecondBestWeights
protected int[] m_SecondBestWeights
the best weights/bits so far (second evaluation).
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceadams.core.option.OptionHandler
- Overrides:
defineOptions
in classAbstractClassifierBasedGeneticAlgorithm
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classadams.opt.genetic.AbstractGeneticAlgorithm
-
setUseSecondEvaluation
public void setUseSecondEvaluation(boolean value)
Sets whether to use the second evaluation.- Parameters:
value
- true if to use second evaluation
-
getUseSecondEvaluation
public boolean getUseSecondEvaluation()
Returns whether to use the second evaluation.- Returns:
- true if to use second evaluation
-
useSecondEvaluationTipText
public String useSecondEvaluationTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSecondFolds
public void setSecondFolds(int value)
Sets the number of folds to use in cross-validation (second evaluation).- Parameters:
value
- the number of folds
-
getSecondFolds
public int getSecondFolds()
Returns the number of folds to use in cross-validation (second evaluation).- Returns:
- the number of folds
-
secondFoldsTipText
public String secondFoldsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setSecondCrossValidationSeed
public void setSecondCrossValidationSeed(int value)
Sets the seed value to use for cross-validation (second evaluation).- Parameters:
value
- the seed to use
-
getSecondCrossValidationSeed
public int getSecondCrossValidationSeed()
Returns the current seed value for cross-validation (second evaluation).- Returns:
- the seed value
-
secondCrossValidationSeedTipText
public String secondCrossValidationSeedTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
addSecondResult
protected void addSecondResult(String key, Double val)
Adds a result to the cache (second evaluation).- Parameters:
key
- the key of the resultval
- the value to add
-
getSecondResult
protected Double getSecondResult(String key)
Returns a value from the cache (second evaluation).- Parameters:
key
- the key of the result- Returns:
- the result or null if not present
-
clearResults
protected void clearResults()
Clears all currently stored results.- Overrides:
clearResults
in classAbstractClassifierBasedGeneticAlgorithm
-
isSecondBetterFitness
public boolean isSecondBetterFitness(double fitness)
Checks whether the fitness is better (second evaluation).- Parameters:
fitness
- the new fitness- Returns:
- true if the new fitness is better
-
setSecondNewFitness
public boolean setSecondNewFitness(double fitness, Object setup, int chromosome, int[] weights)
Sets a fitness and keep it if better (second evaluation).- Parameters:
fitness
- the new fitnesssetup
- the new setupchromosome
- the chromosome responsibleweights
- the new weights- Returns:
- true if the new fitness was better
-
preRun
protected void preRun()
Further initializations in derived classes.- Overrides:
preRun
in classAbstractClassifierBasedGeneticAlgorithm
-
-