Class XClassifierSetManager

java.lang.Object
  |
  +--XClassifierSetManager
All Implemented Interfaces:
java.io.Serializable

public class XClassifierSetManager
extends java.lang.Object
implements java.io.Serializable

This class handles the different sets of classifiers for the manager (identical as XClassifierSet for agents). It stores each set in an array. The array is initialized to a sufficient large size so that no changes in the size of the array will be necessary. The class provides constructors for constructing

It executes a GA in a set and updates classifier parameters of a set. Moreover, it provides all necessary different sums and averages of parameters in the set. Finally, it handles addition, deletion and subsumption of classifiers.

Since:
JDK 1.3
See Also:
Serialized Form

Field Summary
private  int cllSize
          The actual number of macro-classifiers in the list (which is in fact equal to the number of entries in the array).
private  XClassifierManager[] clSet
          The classifier list (in form of an array)
private static XCSConstantsManager cons
          The cons parameter is necessary for all kinds of calculations in the set.
private  int nbAnswers
          number of answers collected during the communication process
private  int numerositySum
          The Sum of the numerosity in one set is always kept up to date!
private  XClassifierSetManager parentSet
          Each set keeps a reference to the parent set out of which it was generated.
 
Constructor Summary
XClassifierSetManager(int numberOfActions)
          Creates a new, empty population initializing the population array to the maximal population size plus the number of possible actions.
XClassifierSetManager(int numberOfActions, int conLength)
          A new random population
XClassifierSetManager(java.lang.String state, XClassifierSetManager pop, int numberOfActions)
          Constructs a match set out of the population.
XClassifierSetManager(java.lang.String state, XClassifierSetManager pop, int numberOfActions, AgentsPopulations wholePop, int time)
          Constructs a match set out of the population.
XClassifierSetManager(java.lang.String state, XClassifierSetManager pop, int time, int numberOfActions)
          Constructs a match set out of the population.
XClassifierSetManager(XClassifierSetManager matchSet, int action)
          Constructs an action set out of the given match set.
XClassifierSetManager(XCSConstants cons)
          Construct the list of classifier candidate for answering a question
 
Method Summary
private  void addClassifier(XClassifierManager classifier)
          Adds a classifier to the set and increases the numerositySum value accordingly.
private  void addValues(XClassifierManager cl)
          Increases the numerositySum value with the numerosity of the classifier.
 void addXClassifierToPopulation(XClassifierManager cl)
          Adds the classifier to the population and checks if an identical classifier exists.
private  double computeDispersion()
          Computes the dispersion of classifiers in the population, that is the sum of variances along the X axis and variance along Y axis
private  double computeVariance(int[] listCoord)
          Computes variance along one dimension (X or Y)
 void confirmClassifiersInSet()
          Updates the numerositySum of the set and deletes all classifiers with numerosity 0.
private  int containsClassifier(XClassifierManager cl)
          Returns the position of the classifier in the set if it is present and -1 otherwise.
private  int decode(char[] binary, int size)
          Turns a binary string into an integer
 XClassifierManager deleteFromPopulation()
          Deletes one classifier in the population.
private  void doActionSetSubsumption()
          Executes action set subsumption.
 XClassifierManager elementAt(int i)
          Returns the classifier at the specified position.
 double getActionSetSizeSum()
          Returns the sum of the fitnesses of all classifiers in the set.
 XClassifierManager[] getAnswerSet()
          returns the array of answering classifiers
 double getAverageExperience()
          Returns the average experience of the classifier set
 double getAverageFitness()
          Returns the average Fitness of the classifier set
 double getAveragePerformance()
          Returns the average performance of the classifier set
 double getAveragePredictionError()
          Returns the average error of the classifier set
 XClassifierManager[] getClSet()
           
 int getCollAnsSize()
          returns the number of answers in the array used to pass the answers from one agent to another
private  double getExperienceSum()
          Returns the sum of experiences in the population of classifiers
 double getFitnessSum()
          Returns the sum of the fitnesses of all classifiers in the set.
private  XClassifierManager getIdenticalClassifier(XClassifierManager newCl)
          Looks for an identical classifier in the population.
 int getNumerositySum()
          Return the numerosity of the population of classifiers of one agent
private  double getPredictionErrorSum()
          Returns the sum of errors in the population of classifiers
private  double getPredictionSum()
          Returns the sum of the prediction values of all classifiers in the set.
 int getSize()
          Returns the number of macro-classifiers in the set.
 double getTimeStampAverage()
          Returns the average of the time stamps in the set.
private  double getTimeStampSum()
          Returns the sum of the time stamps of all classifiers in the set.
private  void increaseNumerositySum(int nr)
          Increases recursively all numerositySum values in the set and all parent sets.
 void increaseSize()
          update the size of the array of answers collected
private  void insertDiscoveredXClassifiersManager(XClassifierManager cl1, XClassifierManager cl2, XClassifierManager cl1P, XClassifierManager cl2P)
          Inserts both discovered classifiers keeping the maximal size of the population and possibly doing GA subsumption.
private  boolean isActionCovered(int action)
          Returns if the specified action is covered in this set.
 void printCharacteristics(java.io.PrintWriter pW)
          print characteristics into a file
 void printSet()
          Prints the classifier set to the control panel.
 void printSet(java.io.PrintWriter pW)
          Prints the classifier set to the specified print writer (which usually refers to a file).
private  boolean removeClassifier(int pos)
          Removes the (possible macro-) classifier at the specified array position from the population.
private  boolean removeClassifier(XClassifierManager classifier)
          Removes the specified (possible macro-) classifier from the population.
 void runGAManager(int time, java.lang.String state, int numberOfActions)
          The Genetic Discovery in XCS takes place here.
private  XClassifierManager selectXClassifierRW(double fitSum)
          Selects one classifier using roulette wheel selection according to the fitnesses of the classifiers.
private  void setTimeStamps(int time)
          Sets the time stamp of all classifiers in the set to the current time.
private  void subsumeXClassifier(XClassifierManager cl)
          Tries to subsume a classifier in the current set.
private  void subsumeXClassifier(XClassifierManager cl, XClassifierManager cl1P, XClassifierManager cl2P)
          Tries to subsume a classifier in the parents.
 boolean testFitness(double averFit)
          Tests if the fitness of a classifier is above the average performance of the population of classifiers
 boolean testPerformance(double averPerf)
          Tests if the performance of a classifier is above the average performance of the population of classifiers
private  void updateFitnessSet()
          Special function for updating the fitnesses of the classifiers in the set.
 void updateSet(double maxPrediction, double reward)
          Updates all parameters in the current set (should be the action set).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cons

private static XCSConstantsManager cons
The cons parameter is necessary for all kinds of calculations in the set. Note that it is static, so that it is not reconstructed each time a new set is created.

See Also:
XCSConstantsManager.XCSConstantsManager()

numerositySum

private int numerositySum
The Sum of the numerosity in one set is always kept up to date!


parentSet

private XClassifierSetManager parentSet
Each set keeps a reference to the parent set out of which it was generated. In the population itself this pointer is set to zero.


clSet

private XClassifierManager[] clSet
The classifier list (in form of an array)


cllSize

private int cllSize
The actual number of macro-classifiers in the list (which is in fact equal to the number of entries in the array).


nbAnswers

private int nbAnswers
number of answers collected during the communication process

Constructor Detail

XClassifierSetManager

public XClassifierSetManager(int numberOfActions)
Creates a new, empty population initializing the population array to the maximal population size plus the number of possible actions.

Parameters:
numberOfActions - The number of actions possible in the problem
See Also:
XCSConstantsManager.maxPopSize

XClassifierSetManager

public XClassifierSetManager(int numberOfActions,
                             int conLength)
A new random population

Parameters:
numberOfActions - The number of actions possible in the problem
conLength - The length of the condition part of classifiers
See Also:
XCSConstantsManager.maxPopSize, XClassifierManager.XClassifierManager(double, int, int, int)

XClassifierSetManager

public XClassifierSetManager(java.lang.String state,
                             XClassifierSetManager pop,
                             int numberOfActions)
Constructs a match set out of the population. After the creation, it is checked if the match set covers all possible actions in the environment.

Parameters:
state - The current situation/problem instance.
numberOfActions - The number of actions possible in the environment.
See Also:
XClassifierManager.XClassifierManager(double,int,String,int), XCSConstantsManager.maxPopSize, XClassifierManager#match(XClassifierManager), addClassifier(XClassifierManager)

XClassifierSetManager

public XClassifierSetManager(java.lang.String state,
                             XClassifierSetManager pop,
                             int numberOfActions,
                             AgentsPopulations wholePop,
                             int time)
Constructs a match set out of the population. After the creation, it is checked if the match set covers all possible actions in the environment. Here, the manager makes use of the getCloseState() routine of agents to determine their core competencies.

Parameters:
state - The current situation/problem instance.
numberOfActions - The number of actions possible in the environment.
wholePop - The total population of agents
time - The actual number of instances the XCS learned from so far.
See Also:
XClassifierManager.XClassifierManager(double,int,String,int), XCSConstantsManager.maxPopSize, Agent.getCloseState(String, AgentsPopulations), addClassifier(XClassifierManager)

XClassifierSetManager

public XClassifierSetManager(java.lang.String state,
                             XClassifierSetManager pop,
                             int time,
                             int numberOfActions)
Constructs a match set out of the population. After the creation, it is checked if the match set covers all possible actions in the environment. If one or more actions are not present, covering occurs, generating the missing action(s). If maximal population size is reached when covering, deletion occurs.

Parameters:
state - The current situation/problem instance.
time - The actual number of instances the XCS learned from so far.
numberOfActions - The number of actions possible in the environment.
See Also:
XClassifierManager.XClassifierManager(double,int,String,int), XCSConstantsManager.maxPopSize, XClassifierManager.match(String), addClassifier(XClassifierManager), deleteFromPopulation()

XClassifierSetManager

public XClassifierSetManager(XClassifierSetManager matchSet,
                             int action)
Constructs an action set out of the given match set.

Parameters:
matchSet - The current match set
action - The chosen action for the action set.

XClassifierSetManager

public XClassifierSetManager(XCSConstants cons)
Construct the list of classifier candidate for answering a question

Parameters:
cons - The set of constants used in the XCS
See Also:
XCSConstantsManager.maxPopSize
Method Detail

getCollAnsSize

public int getCollAnsSize()
returns the number of answers in the array used to pass the answers from one agent to another


getAnswerSet

public XClassifierManager[] getAnswerSet()
returns the array of answering classifiers


increaseSize

public void increaseSize()
update the size of the array of answers collected


containsClassifier

private int containsClassifier(XClassifierManager cl)
Returns the position of the classifier in the set if it is present and -1 otherwise.

Parameters:
cl - the considered classifier

isActionCovered

private boolean isActionCovered(int action)
Returns if the specified action is covered in this set.

Parameters:
action - The action of interest

updateSet

public void updateSet(double maxPrediction,
                      double reward)
Updates all parameters in the current set (should be the action set). Essentially, reinforcement Learning as well as the fitness evaluation takes place in this set. Moreover, the prediction error and the action set size estimate is updated. Also, action set subsumption takes place if selected. As in the algorithmic description, the fitness is updated after prediction and prediction error. However, in order to be more conservative the prediction error is updated before the prediction.

Parameters:
maxPrediction - The maximum prediction value in the successive prediction array (should be set to zero in single step environments).
reward - The actual resulting reward after the execution of an action.
See Also:
XCSConstantsManager.gamma, XClassifierManager.increaseExperience(), XClassifierManager.updatePreError(double), XClassifierManager.updatePrediction(double), XClassifierManager#updateActionSetSize(int), updateFitnessSet(), XCSConstantsManager.doActionSetSubsumption, doActionSetSubsumption()

updateFitnessSet

private void updateFitnessSet()
Special function for updating the fitnesses of the classifiers in the set.

See Also:
XClassifierManager.updateFitness(double, double)

runGAManager

public void runGAManager(int time,
                         java.lang.String state,
                         int numberOfActions)
The Genetic Discovery in XCS takes place here. If a GA takes place, two classifiers are selected by roulette wheel selection, possibly crossed and mutated and then inserted. This is the original routine of XCS that we use for our manager.the agents use a slightly modified routine.

Parameters:
time - The actual number of instances the XCS learned from so far.
state - The current situation/problem instance.
numberOfActions - The number of actions possible in the environment.
See Also:
XCSConstantsManager.theta_GA, selectXClassifierRW(double), XClassifierManager.twoPointCrossover(XClassifierManager), XClassifierManager.applyMutation(java.lang.String, int), XCSConstantsManager.predictionErrorReduction, XCSConstantsManager.fitnessReduction, #insertDiscoveredXClassifiers

selectXClassifierRW

private XClassifierManager selectXClassifierRW(double fitSum)
Selects one classifier using roulette wheel selection according to the fitnesses of the classifiers.

Parameters:
fitSum - the sum of the fitness of the classifiers in the set
See Also:
XCSConstantsManager.drand()

insertDiscoveredXClassifiersManager

private void insertDiscoveredXClassifiersManager(XClassifierManager cl1,
                                                 XClassifierManager cl2,
                                                 XClassifierManager cl1P,
                                                 XClassifierManager cl2P)
Inserts both discovered classifiers keeping the maximal size of the population and possibly doing GA subsumption. We use the original routine for the manager but a slightly modified routines for the agents.

Parameters:
cl1 - The first classifier generated by the GA.
cl2 - The second classifier generated by the GA.
cl1P - The first parent of the two new classifiers.
cl2P - The second classifier of the two new classifiers.
See Also:
XCSConstantsManager.doGASubsumption, subsumeXClassifier(XClassifierManager, XClassifierManager, XClassifierManager), addXClassifierToPopulation(XClassifierManager), XCSConstantsManager.maxPopSize, deleteFromPopulation()

subsumeXClassifier

private void subsumeXClassifier(XClassifierManager cl,
                                XClassifierManager cl1P,
                                XClassifierManager cl2P)
Tries to subsume a classifier in the parents. If no subsumption is possible it tries to subsume it in the current set.

Parameters:
cl - the newly generated classifier to be subsumed
cl1P - the first parent of the classifier
cl2P - the second parent of the classifier
See Also:
subsumeXClassifier(XClassifierManager)

subsumeXClassifier

private void subsumeXClassifier(XClassifierManager cl)
Tries to subsume a classifier in the current set. This method is normally called in an action set. If no subsumption is possible the classifier is simply added to the population considering the possibility that there exists an identical classifier.

Parameters:
cl - The classifier that may be subsumed.
See Also:
addXClassifierToPopulation(XClassifierManager)

doActionSetSubsumption

private void doActionSetSubsumption()
Executes action set subsumption. The action set subsumption looks for the most general subsumer classifier in the action set and subsumes all classifiers that are more specific than the selected one.

See Also:
XClassifierManager.isSubsumer(), XClassifierManager.isMoreGeneral(XClassifierManager)

addXClassifierToPopulation

public void addXClassifierToPopulation(XClassifierManager cl)
Adds the classifier to the population and checks if an identical classifier exists. If an identical classifier exists, its numerosity is increased.

Parameters:
cl - The to be added classifier.
See Also:
getIdenticalClassifier(XClassifierManager)

getNumerositySum

public int getNumerositySum()
Return the numerosity of the population of classifiers of one agent


getIdenticalClassifier

private XClassifierManager getIdenticalClassifier(XClassifierManager newCl)
Looks for an identical classifier in the population.

Parameters:
newCl - The new classifier.
Returns:
Returns the identical classifier if found, null otherwise.

deleteFromPopulation

public XClassifierManager deleteFromPopulation()
Deletes one classifier in the population. The classifier that will be deleted is chosen by roulette wheel selection considering the deletion vote. Returns the macro-classifier which got decreased by one micro-classifier.

See Also:
XClassifierManager.getDelProp(double, double)

confirmClassifiersInSet

public void confirmClassifiersInSet()
Updates the numerositySum of the set and deletes all classifiers with numerosity 0.


setTimeStamps

private void setTimeStamps(int time)
Sets the time stamp of all classifiers in the set to the current time. The current time is the number of exploration steps executed so far.

Parameters:
time - The actual number of instances the XCS learned from so far.

addClassifier

private void addClassifier(XClassifierManager classifier)
Adds a classifier to the set and increases the numerositySum value accordingly.

Parameters:
classifier - The to be added classifier.

addValues

private void addValues(XClassifierManager cl)
Increases the numerositySum value with the numerosity of the classifier.

Parameters:
cl - the considered classifier

increaseNumerositySum

private void increaseNumerositySum(int nr)
Increases recursively all numerositySum values in the set and all parent sets. This function should be called when the numerosity of a classifier in some set is increased in order to keep the numerosity sums of all sets and essentially the population up to date.

Parameters:
nr - the number by which numerosity should be increased

removeClassifier

private boolean removeClassifier(XClassifierManager classifier)
Removes the specified (possible macro-) classifier from the population. The function returns true when the classifier was found and removed and false otherwise. It does not update the numerosity sum of the set, neither recursively remove classifiers in the parent set. This must be done manually where required.

Parameters:
classifier - the considered classifier

removeClassifier

private boolean removeClassifier(int pos)
Removes the (possible macro-) classifier at the specified array position from the population. The function returns true when the classifier was found and removed and false otherwise. It does not update the numerosity of the set, neither recursively remove classifiers in the parent set. This must be done manually where required.

Parameters:
pos - the position of the classifier to be removed in the population array

getPredictionSum

private double getPredictionSum()
Returns the sum of the prediction values of all classifiers in the set.

See Also:
XClassifierManager.getPrediction(), XClassifierManager.getNumerosity()

getExperienceSum

private double getExperienceSum()
Returns the sum of experiences in the population of classifiers

See Also:
XClassifierManager.getExperience(), XClassifierManager.getNumerosity()

getPredictionErrorSum

private double getPredictionErrorSum()
Returns the sum of errors in the population of classifiers

See Also:
XClassifierManager.getPredictionError(), XClassifierManager.getNumerosity()

getFitnessSum

public double getFitnessSum()
Returns the sum of the fitnesses of all classifiers in the set.

See Also:
XClassifierManager.getFitness()

getActionSetSizeSum

public double getActionSetSizeSum()
Returns the sum of the fitnesses of all classifiers in the set.

See Also:
XClassifierManager#get()

getTimeStampSum

private double getTimeStampSum()
Returns the sum of the time stamps of all classifiers in the set.

See Also:
XClassifierManager.getTimeStamp(), XClassifierManager.getNumerosity()

elementAt

public XClassifierManager elementAt(int i)
Returns the classifier at the specified position.

Parameters:
i - The position specified

getSize

public int getSize()
Returns the number of macro-classifiers in the set.


getTimeStampAverage

public double getTimeStampAverage()
Returns the average of the time stamps in the set.


printSet

public void printSet()
Prints the classifier set to the control panel.

See Also:
XClassifierManager.printXClassifier()

printSet

public void printSet(java.io.PrintWriter pW)
Prints the classifier set to the specified print writer (which usually refers to a file).

Parameters:
pW - The print writer that normally refers to a file writer.
See Also:
XClassifierManager.printXClassifier(PrintWriter)

getAveragePerformance

public double getAveragePerformance()
Returns the average performance of the classifier set


getAverageFitness

public double getAverageFitness()
Returns the average Fitness of the classifier set


getAverageExperience

public double getAverageExperience()
Returns the average experience of the classifier set


getAveragePredictionError

public double getAveragePredictionError()
Returns the average error of the classifier set


testPerformance

public boolean testPerformance(double averPerf)
Tests if the performance of a classifier is above the average performance of the population of classifiers

Parameters:
averPerf - The average performance of the population

testFitness

public boolean testFitness(double averFit)
Tests if the fitness of a classifier is above the average performance of the population of classifiers

Parameters:
averFit - The average fitness of the population

computeDispersion

private double computeDispersion()
Computes the dispersion of classifiers in the population, that is the sum of variances along the X axis and variance along Y axis

See Also:
decode(char[], int), computeVariance(int[])

decode

private int decode(char[] binary,
                   int size)
Turns a binary string into an integer

Parameters:
binary - The binary string
size - The length of the string

computeVariance

private double computeVariance(int[] listCoord)
Computes variance along one dimension (X or Y)

Parameters:
listCoord - The list of coordinates of which variance is computed

printCharacteristics

public void printCharacteristics(java.io.PrintWriter pW)
print characteristics into a file

Parameters:
pW - The print writer that normally refers to a file writer
See Also:
computeDispersion()

getClSet

public XClassifierManager[] getClSet()