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 classGeneticAlgorithm.GAJobClass for multithreading the ga.
-
Field Summary
Fields Modifier and Type Field Description protected intm_bitsprotected FitnessFunctionm_fitnessfnprotected Longm_LastNotificationTimethe timestamp the last notification got sent.protected PackDataDefm_pddHashtable<String,Double>m_StoredResultsthe cache for results.protected intm_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 voidaddResult(String key, Double val)Adds a result to the cache.StringbitsTipText()Returns the tip text for this property.voidcalcFitness()Calculates the fitness of the population.doublecalcNewFitness(FitnessFunction ff, int[] weights)Calculates the new fitness.voidcheckBest(Double fitness, OptData vars, FitnessFunction ff, int zerocount)voidcleanUp()Cleans up data structures, frees up memory.protected voidclearResults()Clears all currently stored results.voiddefineOptions()Adds options to the internal list of options.intgetBits()Gets the number of bits.PackDataDefgetDataDef()List<PackData>getDataSetups()protected DoublegetResult(String key)Returns a value from the cache.StringglobalInfo()Returns a string describing the object.protected voidinitialize()Initializes the members.static voidmain(String[] args)OptDataoptimise(OptData datadef, FitnessFunction fitness)Do the optimisation.protected voidpreRun()Some more initializations.voidreset()Resets the genetic algorihtm.voidsetBits(int value)Bits per gene.StringweightsToString(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:
resetin 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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractGeneticAlgorithm
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin 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:
calcFitnessin classAbstractGeneticAlgorithm
-
preRun
protected void preRun()
Some more initializations.- Overrides:
preRunin classAbstractGeneticAlgorithm
-
getDataDef
public PackDataDef getDataDef()
- Specified by:
getDataDefin classPackDataGeneticAlgorithm
-
getDataSetups
public List<PackData> getDataSetups()
- Specified by:
getDataSetupsin classPackDataGeneticAlgorithm
-
optimise
public OptData optimise(OptData datadef, FitnessFunction fitness)
Description copied from class:AbstractOptimiserDo the optimisation.- Specified by:
optimisein classAbstractOptimiser- Parameters:
datadef- data initialisations.fitness- fitness function.- Returns:
- best vars
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUpin interfaceCleanUpHandler- Overrides:
cleanUpin classAbstractOptimiser
-
main
public static void main(String[] args)
-
-