Package adams.opt.optimise
Class GeneticAlgorithm
-
- All Implemented Interfaces:
CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,Serializable
,Comparable
public class GeneticAlgorithm extends PackDataGeneticAlgorithm
Morticia (GEX).
Valid options are:
-D (property: debug) If set to true, scheme may output additional info to the console.
-num-chrom <int> (property: numChrom) The number of chromosomes, ie, the population size. default: 50
-num-iter <int> (property: numIterations) The number of iterations to perform. default: 10000000
-seed <int> (property: seed) The seed value for the random number generator. default: 1
-favor-zeroes (property: favorZeroes) Whether to favor 0s instead of 1s.
-best <java.lang.String> (property: bestRange) The range of the best attributes. default: -none-
-max-train <int> (property: maxTrainTime) The maximum number of seconds to training time (0 = unlimited time). default: 0
-notify <int> (property: notificationInterval) The time interval in seconds after which notification events about changes in the fitness can be sent (-1 = never send notifications; 0 = whenever a change occurs). default: -1
- Version:
- $Revision$
- Author:
- Dale (dale at cs dot waikato dot ac dot nz), FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GeneticAlgorithm.GAJob
Class for multithreading the ga.
-
Field Summary
Fields Modifier and Type Field Description protected int
m_bits
protected FitnessFunction
m_fitnessfn
protected Long
m_LastNotificationTime
the timestamp the last notification got sent.protected PackDataDef
m_pdd
Hashtable<String,Double>
m_StoredResults
the cache for results.protected int
m_zerocount
-
Fields inherited from class adams.opt.optimise.genetic.AbstractGeneticAlgorithm
m_BestRange, m_FavorZeroes, m_Fitness, m_Genes, m_Iterations, m_MaxTrainTime, m_NumChrom, m_NumGenes, m_Random, m_Running, m_Seed, m_TrainStart, PROPS_FILTER, PROPS_MASK, PROPS_RELATION
-
Fields inherited from class adams.opt.optimise.AbstractOptimiser
m_bestf, m_bestv
-
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 GeneticAlgorithm()
The default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addResult(String key, Double val)
Adds a result to the cache.String
bitsTipText()
Returns the tip text for this property.void
calcFitness()
Calculates the fitness of the population.double
calcNewFitness(FitnessFunction ff, int[] weights)
Calculates the new fitness.void
checkBest(Double fitness, OptData vars, FitnessFunction ff, int zerocount)
void
cleanUp()
Cleans up data structures, frees up memory.protected void
clearResults()
Clears all currently stored results.void
defineOptions()
Adds options to the internal list of options.int
getBits()
Gets the number of bits.PackDataDef
getDataDef()
List<PackData>
getDataSetups()
protected Double
getResult(String key)
Returns a value from the cache.String
globalInfo()
Returns a string describing the object.protected void
initialize()
Initializes the members.static void
main(String[] args)
OptData
optimise(OptData datadef, FitnessFunction fitness)
Do the optimisation.protected void
preRun()
Some more initializations.void
reset()
Resets the genetic algorihtm.void
setBits(int value)
Bits per gene.String
weightsToString(int[] weights)
Turns the weights into a string representation.-
Methods inherited from class adams.opt.optimise.genetic.PackDataGeneticAlgorithm
getInitialSetups, init, print, printBits
-
Methods inherited from class adams.opt.optimise.genetic.AbstractGeneticAlgorithm
bestRangeTipText, copyGene, doCrossovers, doMutations, doMutations2, favorZeroesTipText, forCommandLine, forName, getBestRange, getFavorZeroes, getFitness, getGene, getGeneticAlgorithms, getIterations, getMaxTrainTime, getNumChrom, getNumGenes, getSeed, hasMoreZeroes, init, isRunning, iterationsTipText, maxTrainTimeTipText, numChromTipText, postRun, run, runGeneticAlgorithm, seedTipText, setBestRange, setBestRange, setFavorZeroes, setGene, setGene, setIterations, setMaxTrainTime, setNumChrom, setSeed, sort, stop, storeSetup, updateHeader
-
Methods inherited from class adams.opt.optimise.AbstractOptimiser
checkBest, compareTo, destroy, equals, getOptimisers, shallowCopy, shallowCopy
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Field Detail
-
m_bits
protected int m_bits
-
m_zerocount
protected int m_zerocount
-
m_pdd
protected PackDataDef m_pdd
-
m_fitnessfn
protected FitnessFunction m_fitnessfn
-
m_LastNotificationTime
protected Long m_LastNotificationTime
the timestamp the last notification got sent.
-
-
Method Detail
-
addResult
protected void addResult(String key, Double val)
Adds a result to the cache.- Parameters:
key
- the key of the resultval
- the value to add
-
reset
public void reset()
Resets the genetic algorihtm. Derived classes must call this method in set-methods of parameters to assure the invalidation of previously generated data.- Overrides:
reset
in classAbstractGeneticAlgorithm
-
getResult
protected Double getResult(String key)
Returns a value from the cache.- Parameters:
key
- the key of the result- Returns:
- the result or null if not present
-
clearResults
protected void clearResults()
Clears all currently stored results.
-
weightsToString
public String weightsToString(int[] weights)
Turns the weights into a string representation.- Parameters:
weights
- the weights to turn into a string- Returns:
- the weights as string
-
calcNewFitness
public double calcNewFitness(FitnessFunction ff, int[] weights)
Calculates the new fitness.
-
checkBest
public void checkBest(Double fitness, OptData vars, FitnessFunction ff, int zerocount)
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractGeneticAlgorithm
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractGeneticAlgorithm
-
setBits
public void setBits(int value)
Bits per gene.- Parameters:
value
- the number of bits.
-
getBits
public int getBits()
Gets the number of bits.- Returns:
- the number of bits
-
bitsTipText
public String bitsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
calcFitness
public void calcFitness()
Calculates the fitness of the population.- Specified by:
calcFitness
in classAbstractGeneticAlgorithm
-
preRun
protected void preRun()
Some more initializations.- Overrides:
preRun
in classAbstractGeneticAlgorithm
-
getDataDef
public PackDataDef getDataDef()
- Specified by:
getDataDef
in classPackDataGeneticAlgorithm
-
getDataSetups
public List<PackData> getDataSetups()
- Specified by:
getDataSetups
in classPackDataGeneticAlgorithm
-
optimise
public OptData optimise(OptData datadef, FitnessFunction fitness)
Description copied from class:AbstractOptimiser
Do the optimisation.- Specified by:
optimise
in classAbstractOptimiser
- Parameters:
datadef
- data initialisations.fitness
- fitness function.- Returns:
- best vars
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Overrides:
cleanUp
in classAbstractOptimiser
-
main
public static void main(String[] args)
-
-