|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectadams.core.ConsoleObject
adams.core.option.AbstractOptionHandler
adams.optimise.AbstractOptimiser
adams.optimise.genetic.AbstractGeneticAlgorithm
public abstract class AbstractGeneticAlgorithm
Base class for genetic algorithms.
| Field Summary | |
|---|---|
protected Range |
m_BestRange
stores the best range of attribtues. |
protected boolean |
m_FavorZeroes
whether to favor 0s instead of 1s. |
protected double[] |
m_Fitness
the fitness of the genes. |
protected BitSet[] |
m_Genes
the genes. |
protected int |
m_Iterations
number of iterations. |
protected int |
m_MaxTrainTime
the maximum number of seconds to train. |
protected int |
m_NumChrom
number of chromosomes. |
protected int |
m_NumGenes
number of genes per chromosome. |
protected Random |
m_Random
the random number generator. |
protected boolean |
m_Running
whether the algorithm is still running. |
protected int |
m_Seed
the seed value. |
protected long |
m_TrainStart
the time when training commenced. |
static String |
PROPS_FILTER
the key for a filter setup in the setup properties. |
static String |
PROPS_MASK
the key for the mask in the setup properties. |
static String |
PROPS_RELATION
the key for the relation name in the generated properties file. |
| Fields inherited from class adams.optimise.AbstractOptimiser |
|---|
m_bestf, m_bestv |
| Fields inherited from class adams.core.option.AbstractOptionHandler |
|---|
m_DebugLevel, m_OptionManager |
| Constructor Summary | |
|---|---|
AbstractGeneticAlgorithm()
|
|
| Method Summary | |
|---|---|
String |
bestRangeTipText()
Returns the tip text for this property. |
abstract void |
calcFitness()
Override the following function in sub-classes. |
protected void |
copyGene(int to,
int from)
Copies the values of one gene to another. |
void |
defineOptions()
Adds options to the internal list of options. |
void |
doCrossovers()
Performs cross-over. |
void |
doMutations()
Performs mutations. |
void |
doMutations2()
Performs mutations. |
String |
favorZeroesTipText()
Returns the tip text for this property. |
static AbstractGeneticAlgorithm |
forCommandLine(String cmdline)
Instantiates the genetic algorithm from the given commandline (i.e., classname and optional options). |
static AbstractGeneticAlgorithm |
forName(String classname,
String[] options)
Instantiates the genetic algorithm with the given options. |
String |
getBestRange()
Returns the best range of attributes. |
boolean |
getFavorZeroes()
Returns whether 0s are favored over 1s. |
double[] |
getFitness()
Returns the current fitness values. |
boolean |
getGene(int chromosome,
int gene)
Returns the value of the specified gene. |
static String[] |
getGeneticAlgorithms()
Returns a list with classnames of genetic algorithms. |
abstract Vector<int[]> |
getInitialSetups()
|
int |
getIterations()
Gets the iterations use. |
int |
getMaxTrainTime()
Returns the maximum number of seconds to perform training. |
int |
getNumChrom()
Returns the number of chromosomes to use. |
int |
getNumGenes()
Returns the number of genes to use. |
int |
getSeed()
Returns the current seed value. |
boolean |
hasMoreZeroes(BitSet a,
BitSet b)
return if a has more zeroes than b. |
protected void |
init(int ch,
int genes)
Initializes the algorithm. |
protected void |
initialize()
Initializes the members. |
boolean |
isRunning()
Returns whether the algorithm is still running. |
String |
iterationsTipText()
Returns the tip text for this property. |
String |
maxTrainTimeTipText()
Returns the tip text for this property. |
String |
numChromTipText()
Returns the tip text for this property. |
protected void |
postRun()
Further clean-ups in derived classes. |
protected void |
preRun()
Further initializations in derived classes. |
void |
reset()
Resets the genetic algorihtm. |
boolean |
run()
Runs the genetic algorithm. |
static void |
runGeneticAlgorithm(Class env,
Class genetic,
String[] options)
Runs the genetic algorithm with the given options. |
String |
seedTipText()
Returns the tip text for this property. |
protected void |
setBestRange(Range value)
Sets the best range of attributes. |
void |
setBestRange(String value)
Sets the best range of attributes. |
void |
setFavorZeroes(boolean value)
Sets whether 0s are favored over 1s. |
void |
setGene(int chromosome,
int gene,
boolean value)
Sets the value of the specified gene. |
void |
setGene(int chromosome,
int gene,
int value)
Sets the value of the specified gene. |
void |
setIterations(int value)
Sets the iterations to use. |
void |
setMaxTrainTime(int value)
Sets the maximum number of seconds to perform training. |
void |
setNumChrom(int value)
Sets the number of chromosomes to use. |
void |
setSeed(int value)
Sets the seed value to use, resets the random number generator. |
void |
sort()
Sorts genes and fitness arrays according to fitness. |
void |
stop()
Stops the execution of the algorithm. |
protected Properties |
storeSetup(weka.core.Instances data)
Generates a Properties file that stores information on the setup of the genetic algorithm. |
protected weka.core.Instances |
updateHeader(weka.core.Instances data)
Creates a new dataset, with the setup as the new relation name. |
| Methods inherited from class adams.optimise.AbstractOptimiser |
|---|
checkBest, cleanUp, compareTo, destroy, equals, getOptimisers, optimise, shallowCopy, shallowCopy |
| Methods inherited from class adams.core.option.AbstractOptionHandler |
|---|
cleanUpOptions, debug, debug, debugLevelTipText, finishInit, getDebugLevel, getOptionManager, globalInfo, isDebugOn, newOptionManager, setDebugLevel, toCommandLine, toString |
| Methods inherited from class adams.core.ConsoleObject |
|---|
getDebugging, getSystemErr, getSystemOut, sizeOf |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String PROPS_RELATION
#storeSetup(Instances,GeneticAlgorithmJob).,
Constant Field Valuespublic static final String PROPS_FILTER
public static final String PROPS_MASK
protected int m_NumGenes
protected int m_NumChrom
protected BitSet[] m_Genes
protected double[] m_Fitness
protected Range m_BestRange
protected boolean m_FavorZeroes
protected int m_Seed
protected Random m_Random
protected boolean m_Running
protected int m_MaxTrainTime
protected long m_TrainStart
protected int m_Iterations
| Constructor Detail |
|---|
public AbstractGeneticAlgorithm()
| Method Detail |
|---|
public abstract Vector<int[]> getInitialSetups()
protected void initialize()
initialize in class AbstractOptimiserpublic void reset()
reset in class AbstractOptimiserpublic void defineOptions()
defineOptions in interface OptionHandlerdefineOptions in class AbstractOptionHandlerprotected void setBestRange(Range value)
value - the rangepublic void setBestRange(String value)
value - the rangepublic String getBestRange()
public String bestRangeTipText()
public void setSeed(int value)
value - the seed to usepublic int getSeed()
public String seedTipText()
public void setFavorZeroes(boolean value)
value - if true then 0s are favored over 1spublic boolean getFavorZeroes()
public String favorZeroesTipText()
public int getNumGenes()
public void setNumChrom(int value)
value - the numberpublic int getNumChrom()
public String numChromTipText()
public void setMaxTrainTime(int value)
value - the number of secondspublic int getMaxTrainTime()
public String maxTrainTimeTipText()
public void stop()
public boolean isRunning()
public double[] getFitness()
public void setIterations(int value)
value - the iterations.public int getIterations()
public String iterationsTipText()
protected void init(int ch,
int genes)
ch - the chromosomegenes - the number of genes
public boolean getGene(int chromosome,
int gene)
chromosome - the chromosome indexgene - the gene index
public void setGene(int chromosome,
int gene,
int value)
chromosome - the chromosome indexgene - the gene indexvalue - the value to set, 0=clear, otherwise activate it
public void setGene(int chromosome,
int gene,
boolean value)
chromosome - the chromosome indexgene - the gene indexvalue - false=clear, true=activate it
public boolean hasMoreZeroes(BitSet a,
BitSet b)
a - the first geneb - the second gene
public void sort()
public void doCrossovers()
protected void copyGene(int to,
int from)
to - the gene to copy tofrom - the gene to copy frompublic void doMutations()
public void doMutations2()
public abstract void calcFitness()
protected Properties storeSetup(weka.core.Instances data)
data - the data to create the setup forjob - the associated job
PROPS_RELATIONprotected weka.core.Instances updateHeader(weka.core.Instances data)
data - the data to replace the relation name with the setupjob - the associated job
protected void preRun()
public boolean run()
protected void postRun()
throws Exception
Exception - if something goes wrong
public static void runGeneticAlgorithm(Class env,
Class genetic,
String[] options)
env - the environment class to usegenetic - the genetic algorithm to runoptions - the options to setpublic static String[] getGeneticAlgorithms()
public static AbstractGeneticAlgorithm forName(String classname,
String[] options)
classname - the classname of the genetic algorithm to instantiateoptions - the options for the genetic algorithm
public static AbstractGeneticAlgorithm forCommandLine(String cmdline)
cmdline - the classname (and optional options) of the
genetic algorithm to instantiate
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||