Class XClassifier

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

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

Each instance of this class represents one classifier. The class provides different constructors for generating

It handles classifier mutation and crossover and provides, sets, and updates parameters.Moreover, it handles all types of comparisons between different classifiers.

Since:
JDK 1.3
See Also:
Serialized Form

Field Summary
private  int action
          The action of this classifier.
private  double actionSetSize
          The action set size estimate of the classifier.
private  java.lang.String condition
          The condition of this classifier.
private static XCSConstants cons
          An instance of the learning parameters in XCSJava.
private  int experience
          The experience of the classifier.
private  double fitness
          The fitness of the classifier in terms of the macro-classifier.
private  int numerosity
          The numerosity of the classifier.
private  double prediction
          The reward prediction value of this classifier.
private  double predictionError
          The reward prediction error of this classifier.
private  int timeStamp
          The time the last GA application took place in this classifier.
 
Constructor Summary
XClassifier(double setSize, int time, int condLength, int numberOfActions)
          Construct a classifier with random condition and random action.
XClassifier(double setSize, int time, int numberOfActions, java.lang.String situation)
          Construct matching classifier with random action.
XClassifier(double setSize, int time, java.lang.String situation, int act)
          Constructs a classifier with matching condition and specified action.
XClassifier(XClassifier clOld)
          Constructs an identical XClassifier.
 
Method Summary
 void addNumerosity(int num)
          Adds to the numerosity of the classifier.
 boolean applyMutation(java.lang.String state, int numberOfActions)
          Applies a niche mutation to the classifier.
private  void classifierSetVariables(double setSize, int time)
          Sets the initial variables of a new classifier.
private  void createMatchingCondition(java.lang.String cond)
          Creates a matching condition considering the constant P_dontcare<\code>.
private  void createRandomAction(int numberOfActions)
          Creates a random action.
private  void createRandomCondition(int condLength)
          Creates a condition randomly considering the constant P_dontcare<\code>.
 boolean equals(XClassifier cl)
          Returns if the two classifiers are identical in condition and action.
 double getAccuracy()
          Returns the accuracy of the classifier.
 int getAction()
          Returns the action of the classifier.
 double getActionSetSize()
          Returns the size of the action set
 java.lang.String getCondition()
          Returns the condition part of the classifier
 double getDelProp(double meanFitness)
          Returns the vote for deletion of the classifier.
 double getDelProp(double meanFitness, double meanPrediction)
          Returns the vote for deletion of the classifier (second method).
 int getExperience()
          Returns the age of the classifier
 double getFitness()
          Returns the fitness of the classifier.
 int getNumerosity()
          Returns the numerosity of the classifier.
 double getPrediction()
          Returns the prediction of the classifier.
 double getPredictionError()
          Returns the prediction error of the classifier.
 int getTimeStamp()
          Returns the time stamp of the classifier.
 void increaseExperience()
          Increases the Experience of the classifier by one.
 boolean isMoreGeneral(XClassifier cl)
          Returns if the classifier is more general than cl.
 boolean isSubsumer()
          Returns if the classifier is a possible subsumer.
 boolean match(java.lang.String state)
          Returns if the classifier matches in the current situation.
private  boolean mutateAction(int numberOfActions)
          Mutates the action of the classifier.
private  boolean mutateCondition(java.lang.String state)
          Mutates the condition of the classifier.
 void printXClassifier()
          Prints the classifier to the control panel.
 void printXClassifier(java.io.PrintWriter pW)
          Prints the classifier to the print writer (normally referencing a file).
 void setActionSetSize(int as)
          Sets the size of the action set
 void setExperience(int exp)
          Sets the experience of the classifier
 void setFitness(double fit)
          Sets the fitness of the classifier.
 void setNumerosity(int nm)
          Sets the numerosity of the classifier
 void setPrediction(double pre)
          Sets the prediction of the classifier.
 void setPredictionError(double preE)
          Sets the prediction error of the classifier.
 void setTimeStamp(int ts)
          Sets the time stamp of the classifier.
 boolean subsumes(XClassifier cl)
          Returns if the classifier subsumes cl.
 boolean test(java.lang.String question)
          test if a given classifier can match as an answer to the question posed.
 boolean twoPointCrossover(XClassifier cl)
          Applies two point crossover and returns if the classifiers changed.
 double updateActionSetSize(double numerositySum)
          Updates the action set size.
 double updateFitness(double accSum, double accuracy)
          Updates the fitness of the classifier according to the relative accuracy.
 double updatePrediction(double P)
          Updates the prediction of the classifier according to P.
 double updatePreError(double P)
          Updates the prediction error of the classifier according to P.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

condition

private java.lang.String condition
The condition of this classifier.


action

private int action
The action of this classifier.


prediction

private double prediction
The reward prediction value of this classifier.


predictionError

private double predictionError
The reward prediction error of this classifier.


fitness

private double fitness
The fitness of the classifier in terms of the macro-classifier.


numerosity

private int numerosity
The numerosity of the classifier. This is the number of micro-classifier this macro-classifier represents.


experience

private int experience
The experience of the classifier. This is the number of problems the classifier learned from so far.


actionSetSize

private double actionSetSize
The action set size estimate of the classifier.


timeStamp

private int timeStamp
The time the last GA application took place in this classifier.


cons

private static XCSConstants cons
An instance of the learning parameters in XCSJava. Static assures that the Constants are not generated for each classifier separately.

Constructor Detail

XClassifier

public XClassifier(double setSize,
                   int time,
                   java.lang.String situation,
                   int act)
Constructs a classifier with matching condition and specified action.

Parameters:
setSize - The size of the current set which the new classifier matches.
time - The actual number of instances the XCS learned from so far.
situation - The current problem instance/perception.
act - The action of the new classifier.
See Also:
createMatchingCondition(String), classifierSetVariables(double, int)

XClassifier

public XClassifier(double setSize,
                   int time,
                   int numberOfActions,
                   java.lang.String situation)
Construct matching classifier with random action.

Parameters:
setSize - The size of the current set which the new classifier matches.
time - The actual number of instances the XCS learned from so far.
numberOfActions - The number of different actions to chose from (This should be set to the number of actions possible in the problem).
situation - The current problem instance/perception.
See Also:
createMatchingCondition(String), createRandomAction(int), classifierSetVariables(double, int)

XClassifier

public XClassifier(double setSize,
                   int time,
                   int condLength,
                   int numberOfActions)
Construct a classifier with random condition and random action.

Parameters:
setSize - The size of the current set which the new classifier matches.
time - The actual number of instances the XCS learned from so far.
condLength - The length of the condition of the new classifier.
numberOfActions - The number of different actions to chose from
See Also:
createRandomCondition(int), createRandomAction(int), classifierSetVariables(double, int)

XClassifier

public XClassifier(XClassifier clOld)
Constructs an identical XClassifier. However, the experience of the copy is set to 0 and the numerosity is set to 1 since this is indeed a new individual in a population.

Parameters:
clOld - The to be copied classifier.
Method Detail

createRandomCondition

private void createRandomCondition(int condLength)
Creates a condition randomly considering the constant P_dontcare<\code>.

Parameters:
condLength - the length of the condition part
See Also:
XCSConstants.P_dontcare

createMatchingCondition

private void createMatchingCondition(java.lang.String cond)
Creates a matching condition considering the constant P_dontcare<\code>.

Parameters:
cond - the string to be matched by the condition part
See Also:
XCSConstants.P_dontcare

createRandomAction

private void createRandomAction(int numberOfActions)
Creates a random action.

Parameters:
numberOfActions - The number of actions to chose from.

classifierSetVariables

private void classifierSetVariables(double setSize,
                                    int time)
Sets the initial variables of a new classifier.

Parameters:
setSize - The size of the set the classifier is created in.
time - The actual number of instances the XCS learned from so far.
See Also:
XCSConstants.predictionIni, XCSConstants.predictionErrorIni, XCSConstants.fitnessIni

match

public boolean match(java.lang.String state)
Returns if the classifier matches in the current situation.

Parameters:
state - The current situation which can be the current state or problem instance.

twoPointCrossover

public boolean twoPointCrossover(XClassifier cl)
Applies two point crossover and returns if the classifiers changed.

Parameters:
cl - The second classifier for the crossover application.
See Also:
XCSConstants.pX

applyMutation

public boolean applyMutation(java.lang.String state,
                             int numberOfActions)
Applies a niche mutation to the classifier. This method calls mutateCondition(state) and mutateAction(numberOfActions) and returns if at least one bit or the action was mutated.

Parameters:
state - The current situation/problem instance
numberOfActions - The maximal number of actions possible in the environment.

mutateCondition

private boolean mutateCondition(java.lang.String state)
Mutates the condition of the classifier. If one allele is mutated depends on the constant pM. This mutation is a niche mutation. It assures that the resulting classifier still matches the current situation.

Parameters:
state - The current situation/problem instance.
See Also:
XCSConstants.pM

mutateAction

private boolean mutateAction(int numberOfActions)
Mutates the action of the classifier.

Parameters:
numberOfActions - The number of actions/classifications possible in the environment.
See Also:
XCSConstants.pM

equals

public boolean equals(XClassifier cl)
Returns if the two classifiers are identical in condition and action.

Parameters:
cl - The classifier to be compared.

subsumes

public boolean subsumes(XClassifier cl)
Returns if the classifier subsumes cl.


isSubsumer

public boolean isSubsumer()
Returns if the classifier is a possible subsumer. It is affirmed if the classifier has a sufficient experience and if its reward prediction error is sufficiently low.

See Also:
XCSConstants.theta_sub, XCSConstants.epsilon_0

isMoreGeneral

public boolean isMoreGeneral(XClassifier cl)
Returns if the classifier is more general than cl. It is made sure that the classifier is indeed more general and not equally general as well as that the more specific classifier is completely included in the more general one (do not specify overlapping regions)

Parameters:
cl - The classifier that is tested to be more specific.

getDelProp

public double getDelProp(double meanFitness)
Returns the vote for deletion of the classifier.

Parameters:
meanFitness - The mean fitness in the population.
See Also:
XCSConstants.delta, XCSConstants.theta_del

updatePrediction

public double updatePrediction(double P)
Updates the prediction of the classifier according to P.

Parameters:
P - The actual Q-payoff value (actual reward + max of predicted reward in the following situation).
See Also:
XCSConstants.beta

updatePreError

public double updatePreError(double P)
Updates the prediction error of the classifier according to P.

Parameters:
P - The actual Q-payoff value (actual reward + max of predicted reward in the following situation).
See Also:
XCSConstants.beta

getAccuracy

public double getAccuracy()
Returns the accuracy of the classifier. The accuracy is determined from the prediction error of the classifier using Wilson's power function as published in 'Get Real! XCS with continuous-valued inputs' (1999)

See Also:
XCSConstants.epsilon_0, XCSConstants.alpha, XCSConstants.nu

updateFitness

public double updateFitness(double accSum,
                            double accuracy)
Updates the fitness of the classifier according to the relative accuracy.

Parameters:
accSum - The sum of all the accuracies in the action set
accuracy - The accuracy of the classifier.
See Also:
XCSConstants.beta

updateActionSetSize

public double updateActionSetSize(double numerositySum)
Updates the action set size.

See Also:
XCSConstants.beta

getAction

public int getAction()
Returns the action of the classifier.


getActionSetSize

public double getActionSetSize()
Returns the size of the action set


getExperience

public int getExperience()
Returns the age of the classifier


increaseExperience

public void increaseExperience()
Increases the Experience of the classifier by one.


getPrediction

public double getPrediction()
Returns the prediction of the classifier.


setPrediction

public void setPrediction(double pre)
Sets the prediction of the classifier.

Parameters:
pre - The new prediction of the classifier.

getPredictionError

public double getPredictionError()
Returns the prediction error of the classifier.


setPredictionError

public void setPredictionError(double preE)
Sets the prediction error of the classifier.

Parameters:
preE - The new prediction error of the classifier.

getCondition

public java.lang.String getCondition()
Returns the condition part of the classifier


getFitness

public double getFitness()
Returns the fitness of the classifier.


setFitness

public void setFitness(double fit)
Sets the fitness of the classifier.

Parameters:
fit - The new fitness of the classifier.

getNumerosity

public int getNumerosity()
Returns the numerosity of the classifier.


addNumerosity

public void addNumerosity(int num)
Adds to the numerosity of the classifier.

Parameters:
num - The added numerosity (can be negative!).

getTimeStamp

public int getTimeStamp()
Returns the time stamp of the classifier.


setTimeStamp

public void setTimeStamp(int ts)
Sets the time stamp of the classifier.

Parameters:
ts - The new time stamp of the classifier.

setNumerosity

public void setNumerosity(int nm)
Sets the numerosity of the classifier

Parameters:
nm - the new numerosity of the classifier

setExperience

public void setExperience(int exp)
Sets the experience of the classifier

Parameters:
exp - The experience of the classifier

setActionSetSize

public void setActionSetSize(int as)
Sets the size of the action set

Parameters:
as - The size of the set

test

public boolean test(java.lang.String question)
test if a given classifier can match as an answer to the question posed. The classifier's condition has to match exactly the question's condition (e.g. not to be more general or more specific)

Parameters:
question - in the communication process, the condition passed between XCSs

printXClassifier

public void printXClassifier()
Prints the classifier to the control panel. The method prints condition action prediction predictionError fitness numerosity experience actionSetSize timeStamp.


printXClassifier

public void printXClassifier(java.io.PrintWriter pW)
Prints the classifier to the print writer (normally referencing a file). The method prints condition action prediction predictionError fitness numerosity experience actionSetSize timeStamp.

Parameters:
pW - The writer to which the classifier is written.

getDelProp

public double getDelProp(double meanFitness,
                         double meanPrediction)
Returns the vote for deletion of the classifier (second method).

Parameters:
meanFitness - The mean fitness in the population.
meanPrediction - The mean prediction in the population.
See Also:
XCSConstants.delta, XCSConstants.theta_del