ABLE 2.0.0 07/02/2003 10:25:01

com.ibm.able.agents
Class AbleGeneticSearchAgent

java.lang.Object
  |
  +--com.ibm.able.AbleObject
        |
        +--com.ibm.able.AbleDefaultAgent
              |
              +--com.ibm.able.agents.AbleGeneticSearchAgent
All Implemented Interfaces:
AbleAgent, AbleBean, AbleBeanContainer, AbleDataBufferManager, AbleEventListener, AbleEventListenerManager, AbleEventQueueManager, AbleEventQueueProcessor, AblePropertyChangeManager, AbleSerializable, AbleUserDefinedFunctionManager, java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable

public class AbleGeneticSearchAgent
extends AbleDefaultAgent
implements java.io.Serializable

This class implements an AbleAgent for conducting genetic search over a population of AbleBeans. An intermediate class, derived from AbleGeneticObject is used as an interface between this agent and the original AbleBeans.

See Also:
Serialized Form

Field Summary
protected  boolean autoEvolve
           
protected  double avgFitness
           
protected  int chromosomeLength
           
protected  java.util.Hashtable chromosomeList
           
protected  double crossoverRate
           
static java.lang.String defaultName
          Value assigned to name by default.
protected  boolean evolving
           
protected  double fitnessThreshold
           
protected  java.lang.Class geneticObjectClass
           
protected  java.lang.String geneticObjectClassName
           
protected  double maxFitness
           
protected  int maxNumPasses
           
protected  double minFitness
           
protected  double mutationRate
           
protected  boolean noDuplicatesAllowed
           
protected  int numPasses
           
protected  java.util.Hashtable operatorFitness
           
protected  java.util.Vector population
           
protected  int populationSize
           
static int REPLACE_ALL
           
static int REPLACE_SOME
           
protected  int replacementSize
           
protected  int reproductionTechnique
           
protected  java.lang.String sourceFileName
          The genetic search algorithm is as follows: initialize the population evaluate each chromosome and insert into the population create new chromosomes using crossover/mutation operators delete members of the old population to make room for new members go to step 2 until time is up or other stopping condition is reached Note: a Chromosome is an Object, usually a String, but could be String[] or double[]
protected  double[] summedFitness
           
protected  double totalFitness
           
protected  double totalNormalizedFitness
           
protected  boolean useNormalizedFitness
           
protected  java.lang.String vocabulary
           
 
Fields inherited from class com.ibm.able.AbleDefaultAgent
activeDataSource, eventConnections, myBeans, numEpochs, processList, processListOK, userDefinedFunctions
 
Fields inherited from class com.ibm.able.AbleObject
changed, chgSupport, comment, dataFlowEnabled, destBufferConnections, eventQueue, fileName, inputBuffer, listeners, logger, name, outputBuffer, parent, propertyConnectionMgr, sourceBufferConnections, state, stateChgSupport, trace
 
Constructor Summary
AbleGeneticSearchAgent()
          construct a genetic search agent
AbleGeneticSearchAgent(java.lang.String aName)
          construct a genetic search agent with specified name
 
Method Summary
static java.lang.String Copyright()
          Determine the copyright of this class.
 AbleGeneticObject createChild(java.lang.Object chromosome)
          Given a prospective chromosome a) see if dups are allowed and if it is unique b) if ok, create a child genetic object from the chromsome and initialize the associated bean (if any)
 AbleGeneticObject[] createChildren(java.lang.Object[] chromosome)
          given a newly derived chromosome(s), create a new population member(s) and initialize it/them Note: could be zero, one or two (depending on operators and if no dups allowed)
protected  java.util.Vector createNewMembers()
          Generate replacementSize population members through application of genetic operators.
protected  void evaluatePopulation()
          evaluate each population member based on fitness first process the AbleBeans contained in this SearchAgent if an evaluationAgent bean exists, process() it compute min, max, avg, and total fitness if normalization is specified, then normalize the raw fitness values
 void evolve()
          automatically evolve the population by turning the evolving boolean on create and start the async thread if it is not already running
 boolean getAutoEvolve()
           
 double getAvgFitness()
          Get the average raw fitness value for the current population
 int getChromosomeLength()
          Get the length of the chromsome used by the current genetic objects
 double getCrossoverRate()
          Get the crossover rate
 double getFitnessThreshold()
          Get the raw fitness threshold value
 java.lang.String getGeneticObjectClassName()
          Return the name of the genetic object class
 double getMaxFitness()
          Get the maximum raw fitness value for the current population
 int getMaxNumPasses()
          Get the maximum number of passes to search
 double getMinFitness()
          Get the minimum raw fitness value for the current population
 double getMutationRate()
          Get the current mutation rate
 int getNumPasses()
          Get the number of generations we have searched
 java.util.Hashtable getOperatorFitness()
          Get the supported operators and their fitness (selection probability) values
 java.util.Vector getPopulation()
           
 int getPopulationSize()
          Get the population size
 int getReplacementSize()
          Get the replacement size
 java.lang.String getSourceFileName()
          not sure if we need this
 java.lang.String getVocabulary()
          Get the chromosome vocabulary (default is "01")
 void init()
          generate a complete genetic search agent
protected  void insertIntoPopulation(AbleGeneticObject newMember, java.util.Vector list)
          Insert a member into the population vector sorted by raw fitness update the min and max fitness values
protected  void integratePopulation(java.util.Vector newPopulation)
          add the new members to the population reduce the population by removing lowest fitness members of current population
 boolean isEvolving()
          Check to see if the agent is in the process of evolving.
 boolean isNoDuplicatesAllowed()
          Get the boolean flag indicating whether duplicate members are allowed or not
 boolean isUseNormalizedFitness()
          Get the boolean flag indicating whether raw or normalized fitness is used.
protected  void normalizeFitness()
          perform linear normalization of the raw fitness values also pre-compute the summed fitness values for roulette wheel selection where the normalizedFitness of the best population member is equal to 2 times the average fitness
 void process()
          This method performs the following steps: initialize the population (first time only) evaluate each chromosome and insert into the population create new chromosomes and members using crossover/mutation operators delete members of the old population to make room for new members
 void processTimerEvent()
          This method is called from the asynch thread It is only used for automated evolution the population
protected  void removeLastNFromPopulation(int n)
          remove the last N members (with lowest fitness) from the population
 void reset()
          Reset each contained bean with dataflow on.
 AbleGeneticObject rouletteWheelSelection()
          Select a member of the population using the roulette wheel algorithm
 java.lang.String selectOperator()
          randomly select an operator to be applied to the parents using a roulette wheel selection technique Note: total operator fitness must be equal to 100
 AbleGeneticObject[] selectParents()
          choose two population members to reproduce using rouletteWheel selection technique
 void setAutoEvolve(boolean state)
           
 void setCrossoverRate(double rate)
          Set the crossoverRate , used when a crossover operator is selected to determine whether a crossover will actually be performed
 void setFitnessThreshold(double thresh)
          Set the raw fitness threshold This is used to halt the search if the raw fitness value exceeds this threshold
 void setGeneticObjectClassName(java.lang.String aClassName)
          Set the name of the class of genetic objects we are searching
 void setMaxNumPasses(int num)
          Set the maximum number of generations to search
 void setMode(int mode)
          set the internal config for either 0 = training from an external file or 1 = running (with network locked) from data placed in the input buffer
 void setMutationRate(double rate)
          Set the mutationRate, used when a mutate operator is selected this value is used to determine whether each bit is mutated or not mutation can be to any other value in the vocabulary
 void setNoDuplicatesAllowed(boolean state)
          Set a boolean flag indicating whether members with duplicate chromosomes are allowed in the population or not.
 void setOperatorFitness(java.util.Hashtable opFitness)
          Set a hashtable of operators and their fitness values These values are used to select operators for application during reproduction Fitness values should sum to 100
 void setPopulationSize(int size)
          Set the population size
 void setReplacementSize(int size)
          Set the number of population members to replace each generation
 void setSourceFileName(java.lang.String aFileName)
          not sure if we need this
 void setUseNormalizedFitness(boolean state)
          Set the boolean flag indicating whether raw or normalized fitness values should be used for selecting members for reproduction.
 void startEvolving()
          start automatically evolving from the external data
 void stopEvolving()
          stop automatically training the model from the external data
 
Methods inherited from class com.ibm.able.AbleDefaultAgent
addBean, addBeans, addEventConnection, addUserDefinedFunction, buildProcessList, clsNm, containsBean, containsBean, containsUserDefinedFunction, debugTrace, generateUniqueName, getBean, getBeans, getDataSource, getNumEpochs, getProcessList, getUserDefinedFunction, getUserDefinedFunctions, handleAbleEvent, invokeUserDefinedFunction, isActiveDataSource, propertyChange, quitAll, quitEnabledEventProcessing, removeAllBeans, removeAllConnections, removeAllEventConnections, removeBean, removeBean, removeBeans, removeEventConnection, removeUserDefinedFunction, resumeAll, setActiveDataSource, setDataFlowEnabled, setProcessList, setUserDefinedFunctions, suspendAll
 
Methods inherited from class com.ibm.able.AbleObject
addAbleEventListener, addDestBufferConnection, addPropertyChangeListener, addPropertyConnection, addSourceBufferConnection, addStateChangeListener, dataChanged, firePropertyChange, flushAbleEventQueue, getAbleEventListeners, getAbleEventProcessingEnabled, getAbleEventQueueSize, getComment, getDestBufferConnections, getFileName, getInputBuffer, getInputBuffer, getInputBufferAsStringArray, getInputBufferContents, getLogger, getName, getOutputBuffer, getOutputBuffer, getOutputBufferAsStringArray, getOutputBufferContents, getParent, getPropertyConnectionManager, getSleepTime, getSourceBufferConnections, getState, getTraceLogger, hasInputBuffer, hasOutputBuffer, init, isAbleEventPostingEnabled, isAbleEventProcessingEnabled, isChanged, isConnectable, isDataFlowEnabled, isTimerEventProcessingEnabled, notifyAbleEventListeners, process, processAbleEvent, processBufferConnections, processNoEventProcessingEnabledSituation, removeAbleEventListener, removeAllAbleEventListeners, removeAllBufferConnections, removeAllPropertyConnections, removeDestBufferConnection, removePropertyChangeListener, removePropertyConnection, removeSourceBufferConnection, removeStateChangeListener, restartEnabledEventProcessing, restoreFromFile, restoreFromFile, restoreFromSerializedFile, restoreFromStream, resumeEnabledEventProcessing, saveToFile, saveToFile, setAbleEventProcessingEnabled, setChanged, setComment, setFileName, setInputBuffer, setInputBuffer, setLogger, setName, setOutputBuffer, setOutputBuffer, setParent, setSleepTime, setState, setTimerEventProcessingEnabled, setTraceLogger, sourceConnectionsOK, startEnabledEventProcessing, suspendEnabledEventProcessing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.able.AbleBean
getComment, getLogger, getName, getParent, getState, getTraceLogger, init, isChanged, process, setChanged, setComment, setLogger, setName, setParent, setState, setTraceLogger
 
Methods inherited from interface com.ibm.able.AbleDataBufferManager
addDestBufferConnection, addSourceBufferConnection, getDestBufferConnections, getInputBuffer, getInputBuffer, getInputBufferAsStringArray, getInputBufferContents, getOutputBuffer, getOutputBuffer, getOutputBufferAsStringArray, getOutputBufferContents, getSourceBufferConnections, hasInputBuffer, hasOutputBuffer, isConnectable, isDataFlowEnabled, processBufferConnections, removeAllBufferConnections, removeDestBufferConnection, removeSourceBufferConnection, setInputBuffer, setInputBuffer, setOutputBuffer, setOutputBuffer
 
Methods inherited from interface com.ibm.able.AbleEventListenerManager
addAbleEventListener, dataChanged, getAbleEventListeners, notifyAbleEventListeners, removeAbleEventListener
 
Methods inherited from interface com.ibm.able.AbleEventQueueManager
flushAbleEventQueue, getAbleEventProcessingEnabled, getAbleEventQueueSize, getSleepTime, isAbleEventPostingEnabled, isAbleEventProcessingEnabled, isTimerEventProcessingEnabled, restartEnabledEventProcessing, resumeEnabledEventProcessing, setAbleEventProcessingEnabled, setSleepTime, setTimerEventProcessingEnabled, startEnabledEventProcessing, suspendEnabledEventProcessing
 
Methods inherited from interface com.ibm.able.AbleEventQueueProcessor
processAbleEvent, processNoEventProcessingEnabledSituation
 
Methods inherited from interface com.ibm.able.AblePropertyChangeManager
addPropertyChangeListener, addPropertyConnection, getPropertyConnectionManager, removeAllPropertyConnections, removePropertyChangeListener, removePropertyConnection
 
Methods inherited from interface com.ibm.able.AbleSerializable
getFileName, restoreFromFile, restoreFromFile, saveToFile, saveToFile, setFileName
 
Methods inherited from interface com.ibm.able.AbleBeanContainer
getName
 

Field Detail

defaultName

public static final java.lang.String defaultName
Value assigned to name by default.

REPLACE_ALL

public static final int REPLACE_ALL

REPLACE_SOME

public static final int REPLACE_SOME

sourceFileName

protected java.lang.String sourceFileName
The genetic search algorithm is as follows:
  1. initialize the population
  2. evaluate each chromosome and insert into the population
  3. create new chromosomes using crossover/mutation operators
  4. delete members of the old population to make room for new members
  5. go to step 2 until time is up or other stopping condition is reached
Note: a Chromosome is an Object, usually a String, but could be String[] or double[]

reproductionTechnique

protected int reproductionTechnique

geneticObjectClass

protected java.lang.Class geneticObjectClass

population

protected java.util.Vector population

chromosomeList

protected java.util.Hashtable chromosomeList

operatorFitness

protected java.util.Hashtable operatorFitness

chromosomeLength

protected int chromosomeLength

vocabulary

protected java.lang.String vocabulary

geneticObjectClassName

protected java.lang.String geneticObjectClassName

maxNumPasses

protected int maxNumPasses

fitnessThreshold

protected double fitnessThreshold

populationSize

protected int populationSize

replacementSize

protected int replacementSize

crossoverRate

protected double crossoverRate

mutationRate

protected double mutationRate

noDuplicatesAllowed

protected boolean noDuplicatesAllowed

useNormalizedFitness

protected boolean useNormalizedFitness

autoEvolve

protected boolean autoEvolve

maxFitness

protected double maxFitness

minFitness

protected double minFitness

avgFitness

protected double avgFitness

totalFitness

protected double totalFitness

totalNormalizedFitness

protected double totalNormalizedFitness

summedFitness

protected double[] summedFitness

numPasses

protected int numPasses

evolving

protected boolean evolving
Constructor Detail

AbleGeneticSearchAgent

public AbleGeneticSearchAgent()
                       throws AbleException
construct a genetic search agent

AbleGeneticSearchAgent

public AbleGeneticSearchAgent(java.lang.String aName)
                       throws AbleException
construct a genetic search agent with specified name
Method Detail

reset

public void reset()
           throws AbleException
Reset each contained bean with dataflow on. Restore processing options to default values. Restore counters and performance metrics settings to default values.
Overrides:
reset in class AbleDefaultAgent
Following copied from class: com.ibm.able.AbleDefaultAgent
Throws:
AbleException - If an error occurs when resetting a contained bean. All errors are collected and insert into the exception so that one bean's error does not prevent another from being reset.

init

public void init()
          throws AbleException
generate a complete genetic search agent
Overrides:
init in class AbleObject
Following copied from interface: com.ibm.able.AbleBean
Throws:
AbleException - If an error occurs.

process

public void process()
             throws AbleException
This method performs the following steps:
  1. initialize the population (first time only)
  2. evaluate each chromosome and insert into the population
  3. create new chromosomes and members using crossover/mutation operators
  4. delete members of the old population to make room for new members
Overrides:
process in class AbleDefaultAgent
Following copied from class: com.ibm.able.AbleDefaultAgent
Throws:
AbleException - If an error occurs. Errors from each contained bean are accumulated.

processTimerEvent

public void processTimerEvent()
                       throws AbleException
This method is called from the asynch thread It is only used for automated evolution the population
Overrides:
processTimerEvent in class AbleObject
Following copied from interface: com.ibm.able.AbleEventQueueProcessor
Throws:
AbleException - If an error occurs.

setSourceFileName

public void setSourceFileName(java.lang.String aFileName)
not sure if we need this

getSourceFileName

public java.lang.String getSourceFileName()
not sure if we need this

setGeneticObjectClassName

public void setGeneticObjectClassName(java.lang.String aClassName)
Set the name of the class of genetic objects we are searching
Parameters:
aClassName - fully specified (package prefixed) class name

getGeneticObjectClassName

public java.lang.String getGeneticObjectClassName()
Return the name of the genetic object class

setPopulationSize

public void setPopulationSize(int size)
Set the population size
Parameters:
size - the population size

getPopulationSize

public int getPopulationSize()
Get the population size

getPopulation

public java.util.Vector getPopulation()

setReplacementSize

public void setReplacementSize(int size)
Set the number of population members to replace each generation
Parameters:
size - the number of members to be replaced

getReplacementSize

public int getReplacementSize()
Get the replacement size
Returns:
the number of members created/replaced each cycle

getVocabulary

public java.lang.String getVocabulary()
Get the chromosome vocabulary (default is "01")
Returns:
the chromosome vocabulary (if chromosome is a string)

getNumPasses

public int getNumPasses()
Get the number of generations we have searched
Returns:
the current generation number

setMaxNumPasses

public void setMaxNumPasses(int num)
Set the maximum number of generations to search
Parameters:
num - the maximum number of generations to create

getMaxNumPasses

public int getMaxNumPasses()
Get the maximum number of passes to search
Returns:
the maximum number of passes

setFitnessThreshold

public void setFitnessThreshold(double thresh)
Set the raw fitness threshold This is used to halt the search if the raw fitness value exceeds this threshold
Parameters:
thresh - the fitness threshold

getFitnessThreshold

public double getFitnessThreshold()
Get the raw fitness threshold value

setCrossoverRate

public void setCrossoverRate(double rate)
Set the crossoverRate , used when a crossover operator is selected to determine whether a crossover will actually be performed

getCrossoverRate

public double getCrossoverRate()
Get the crossover rate

setMutationRate

public void setMutationRate(double rate)
Set the mutationRate, used when a mutate operator is selected this value is used to determine whether each bit is mutated or not mutation can be to any other value in the vocabulary

getMutationRate

public double getMutationRate()
Get the current mutation rate

getAvgFitness

public double getAvgFitness()
Get the average raw fitness value for the current population

getMinFitness

public double getMinFitness()
Get the minimum raw fitness value for the current population

getMaxFitness

public double getMaxFitness()
Get the maximum raw fitness value for the current population

getChromosomeLength

public int getChromosomeLength()
Get the length of the chromsome used by the current genetic objects

setAutoEvolve

public void setAutoEvolve(boolean state)

getAutoEvolve

public boolean getAutoEvolve()

setNoDuplicatesAllowed

public void setNoDuplicatesAllowed(boolean state)
Set a boolean flag indicating whether members with duplicate chromosomes are allowed in the population or not. Default is false (duplicates allowed)
Parameters:
state - whether duplicates should be allowed (false) or not (true)

isNoDuplicatesAllowed

public boolean isNoDuplicatesAllowed()
Get the boolean flag indicating whether duplicate members are allowed or not

setUseNormalizedFitness

public void setUseNormalizedFitness(boolean state)
Set the boolean flag indicating whether raw or normalized fitness values should be used for selecting members for reproduction. Default is false. If set to true, the raw fitness values are normalized using linear normalization where the max fitness value is linearly scaled to be 2 times the avg fitness value

isUseNormalizedFitness

public boolean isUseNormalizedFitness()
Get the boolean flag indicating whether raw or normalized fitness is used.

setOperatorFitness

public void setOperatorFitness(java.util.Hashtable opFitness)
Set a hashtable of operators and their fitness values These values are used to select operators for application during reproduction Fitness values should sum to 100

getOperatorFitness

public java.util.Hashtable getOperatorFitness()
Get the supported operators and their fitness (selection probability) values

setMode

public void setMode(int mode)
set the internal config for either 0 = training from an external file or 1 = running (with network locked) from data placed in the input buffer

createChildren

public AbleGeneticObject[] createChildren(java.lang.Object[] chromosome)
given a newly derived chromosome(s), create a new population member(s) and initialize it/them Note: could be zero, one or two (depending on operators and if no dups allowed)
Parameters:
one - or two chromosome objects
Returns:
zero, one or two population members

createChild

public AbleGeneticObject createChild(java.lang.Object chromosome)
Given a prospective chromosome a) see if dups are allowed and if it is unique b) if ok, create a child genetic object from the chromsome and initialize the associated bean (if any)
Parameters:
chromosome - - the chromosome defining the child
Returns:
the fully initialized child population member or null

evaluatePopulation

protected void evaluatePopulation()
evaluate each population member based on fitness first process the AbleBeans contained in this SearchAgent if an evaluationAgent bean exists, process() it compute min, max, avg, and total fitness if normalization is specified, then normalize the raw fitness values

normalizeFitness

protected void normalizeFitness()
perform linear normalization of the raw fitness values also pre-compute the summed fitness values for roulette wheel selection where the normalizedFitness of the best population member is equal to 2 times the average fitness

createNewMembers

protected java.util.Vector createNewMembers()
Generate replacementSize population members through application of genetic operators. Note: if replacementSize = populationSize we use elitism, the best member (highest fitness) is always carried over.
Returns:
a vector of new population members

integratePopulation

protected void integratePopulation(java.util.Vector newPopulation)
                            throws AbleException
add the new members to the population reduce the population by removing lowest fitness members of current population
Parameters:
a - vector of new genetic objects to add to the population

insertIntoPopulation

protected void insertIntoPopulation(AbleGeneticObject newMember,
                                    java.util.Vector list)
Insert a member into the population vector sorted by raw fitness update the min and max fitness values
Parameters:
newMember - -- the genetic object to insert into the population
list - -- the population vector

removeLastNFromPopulation

protected void removeLastNFromPopulation(int n)
                                  throws AbleException
remove the last N members (with lowest fitness) from the population
Parameters:
n - the number of population members to remove

selectParents

public AbleGeneticObject[] selectParents()
choose two population members to reproduce using rouletteWheel selection technique
Returns:
the two population members

selectOperator

public java.lang.String selectOperator()
randomly select an operator to be applied to the parents using a roulette wheel selection technique Note: total operator fitness must be equal to 100
Returns:
the name of the selected operator (user-defined function)

rouletteWheelSelection

public AbleGeneticObject rouletteWheelSelection()
Select a member of the population using the roulette wheel algorithm
Returns:
a single member of the population chosen at random (based on fitness)

isEvolving

public boolean isEvolving()
                   throws AbleException
Check to see if the agent is in the process of evolving.

evolve

public void evolve()
automatically evolve the population by turning the evolving boolean on create and start the async thread if it is not already running

startEvolving

public void startEvolving()
                   throws AbleException
start automatically evolving from the external data

stopEvolving

public void stopEvolving()
                  throws AbleException
stop automatically training the model from the external data

Copyright

public static java.lang.String Copyright()
Determine the copyright of this class.
Returns:
A String containing this class's copyright statement.

ABLE 2.0.0 07/02/2003 10:25:01

(C) Copyright IBM Corporation 1999, 2003