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:
Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,Pausable,Randomizable,ShallowCopySupporter<AbstractGeneticAlgorithm>,SizeOfHandler,Stoppable,StoppableWithFeedback,ThreadLimiter,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 classAbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation.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>
-
Nested classes/interfaces inherited from class adams.opt.genetic.AbstractGeneticAlgorithm
AbstractGeneticAlgorithm.FitnessContainer, AbstractGeneticAlgorithm.GeneticAlgorithmJob<T extends AbstractGeneticAlgorithm>
-
-
Field Summary
Fields Modifier and Type Field Description protected doublem_SecondBestFitnessthe best fitness so far (second evaluation).protected Objectm_SecondBestSetupthe best setup so far (second evaluation).protected int[]m_SecondBestWeightsthe best weights/bits so far (second evaluation).protected intm_SecondCrossValidationSeedthe cross-validation seed (second evaluation).protected intm_SecondFoldsthe number of folds for cross-validation (second evaluation).Hashtable<String,Double>m_SecondStoredResultsthe cache for results (second evaluation).protected booleanm_UseSecondEvaluationwhether 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
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description AbstractClassifierBasedGeneticAlgorithmWithSecondEvaluation()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddSecondResult(String key, Double val)Adds a result to the cache (second evaluation).protected voidclearResults()Clears all currently stored results.voiddefineOptions()Adds options to the internal list of options.intgetSecondCrossValidationSeed()Returns the current seed value for cross-validation (second evaluation).intgetSecondFolds()Returns the number of folds to use in cross-validation (second evaluation).protected DoublegetSecondResult(String key)Returns a value from the cache (second evaluation).booleangetUseSecondEvaluation()Returns whether to use the second evaluation.protected voidinitialize()Initializes the members.booleanisSecondBetterFitness(double fitness)Checks whether the fitness is better (second evaluation).protected voidpreRun()Further initializations in derived classes.StringsecondCrossValidationSeedTipText()Returns the tip text for this property.StringsecondFoldsTipText()Returns the tip text for this property.voidsetSecondCrossValidationSeed(int value)Sets the seed value to use for cross-validation (second evaluation).voidsetSecondFolds(int value)Sets the number of folds to use in cross-validation (second evaluation).booleansetSecondNewFitness(double fitness, Object setup, int chromosome, int[] weights)Sets a fitness and keep it if better (second evaluation).voidsetUseSecondEvaluation(boolean value)Sets whether to use the second evaluation.StringuseSecondEvaluationTipText()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
-
Methods inherited from interface adams.event.GeneticFitnessChangeNotifier
addFitnessChangeListener, removeFitnessChangeListener
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
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:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractClassifierBasedGeneticAlgorithm
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractGeneticAlgorithm
-
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:
clearResultsin 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:
preRunin classAbstractClassifierBasedGeneticAlgorithm
-
-