xcseco
Class XClassifier

java.lang.Object
  |
  +--xcseco.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:
JDK1.1
Version:
XCSJava 1.0
Author:
Martin V. Butz
See Also:
Serialized Form

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.
 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 getDelProp(double meanFitness)
          Returns the vote for deletion 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.
 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 setFitness(double fit)
          Sets the fitness 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 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
 

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.

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.

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

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

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.

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.
Parameters:
The - new classifier that possibly is subsumed.

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:
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.
Parameters:
numeriositySum - The number of micro-classifiers in the population
See Also:
XCSConstants.beta

getAction

public int getAction()
Returns the action 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.

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.

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.