simuLCS
Class ZClassifier

java.lang.Object
  extended bysimuLCS.Classifier
      extended bysimuLCS.ZClassifier
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class ZClassifier
extends Classifier
implements java.io.Serializable, java.lang.Comparable

Implements the ZClassifier, ie. a Classifier with a strength. A few lines of code (mutation, crossover) below draw inspiration from the freely available XCSJava by Martin V. Butz

Author:
Benoit, Martin V. Butz
See Also:
Serialized Form

Field Summary
private  double strength
          The Strength of the classifier.
 
Fields inherited from class simuLCS.Classifier
ACT_ALL, ACT_EXACT, action, COND_ALL, COND_EXACT, COND_MATCH, condition, name, PART_ACTION, PART_CONDITION
 
Constructor Summary
ZClassifier(double strength, java.lang.String state, java.lang.String act)
           
ZClassifier(int condLength, int actionLength)
          Construct a classifier with random condition and random action.
ZClassifier(int actionLength, java.lang.String situation)
          Construct matching classifier with random action.
ZClassifier(java.lang.String cond, java.lang.String act)
          Constructs a classifier with specified condition and specified action.
ZClassifier(ZClassifier clOld)
          Constructs an identical XClassifier.
 
Method Summary
 void addStrength(double d)
           
 boolean applyMutation(int actionLength)
          Applies a NON niche mutation to the classifier.
 boolean applyMutation(java.lang.String state, int actionLength)
          Applies a niche mutation to the classifier.
 int compareTo(java.lang.Object o)
          Used to build a Comparator to sort the Classifier in order to show them ranked to the user
private  void createMatchingCondition(java.lang.String situation)
          Creates a matching condition considering the constant P_dontcare<\code>.
private  void createRandomAction(int actionLength)
          Creates a random action.
private  void createRandomCondition(int condLength)
          Creates a condition randomly considering the constant P_dontcare<\code>.
 double getStrength()
           
 double getValue()
          Gives the "value" of this classifier to be plotted.
 boolean isIdentical(ZClassifier cl)
          Returns true if the two classifiers are identical in condition and action.
private  boolean mutateAction(int actionLength)
          Mutates the action of the classifier.
private  boolean mutateCondition()
          Mutates the condition of the classifier.
private  boolean mutateCondition(java.lang.String state)
          Mutates the condition of the classifier.
 boolean onePointCrossover(ZClassifier cl)
          Applies one point crossover and returns if the classifiers changed.
 void printClassifier()
          Prints the classifier to the control panel.
 void printClassifier(java.io.PrintWriter pW)
          Prints the classifier to the print writer (normally referencing a file).
 void setStrength(double d)
           
 java.lang.String toString()
          Return a String describing the XClassifier.
 
Methods inherited from class simuLCS.Classifier
createSharedClassifier, fromString, getAction, getBits, getBits, getBitsAction, getBitsCondition, getCondition, getName, match, match, removeSharedClassifier, setAction, setBits, setBitsAction, setBitsCondition, setCondition, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strength

private double strength
The Strength of the classifier.

Constructor Detail

ZClassifier

public ZClassifier(java.lang.String cond,
                   java.lang.String act)
Constructs a classifier with specified condition and specified action.

Parameters:
cond - The condition of the .
act - The action of the new classifier.

ZClassifier

public ZClassifier(int actionLength,
                   java.lang.String situation)
Construct matching classifier with random action.

Parameters:
situation - The current problem instance/perception.

ZClassifier

public ZClassifier(double strength,
                   java.lang.String state,
                   java.lang.String act)
Parameters:
strength -
state -
act -

ZClassifier

public ZClassifier(int condLength,
                   int actionLength)
Construct a classifier with random condition and random action.

Parameters:
condLength - The length of the condition of the new classifier.

ZClassifier

public ZClassifier(ZClassifier 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 number of bits in the condition to be created
See Also:
XCSConstants#P_dontcare

createMatchingCondition

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

Parameters:
situation - The situation which must satisfy the condition created.
See Also:
XCSConstants#P_dontcare

createRandomAction

private void createRandomAction(int actionLength)
Creates a random action. While XCSJava use an int to describe the action, my actions are described by a String which defines the vector of the response.

Parameters:
actionLength - The number of bits in the action to be created

onePointCrossover

public boolean onePointCrossover(ZClassifier cl)
Applies one 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 actionLength)
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

applyMutation

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


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

mutateCondition

private boolean mutateCondition()
Mutates the condition of the classifier. If one allele is mutated depends on the constant pM. This mutation is NOT a niche mutation. Once the allele is selected for mutation, a character (either '0','1',or '#') is selected randomly (using an uniform disctribution).

See Also:
XCSConstants#pM

mutateAction

private boolean mutateAction(int actionLength)
Mutates the action of the classifier. Since my actions are String, the mutation is applied for each allele depending on the constant pM.

See Also:
XCSConstants#pM

isIdentical

public boolean isIdentical(ZClassifier cl)
Returns true if the two classifiers are identical in condition and action.

Parameters:
cl - The classifier to be compared.

printClassifier

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


printClassifier

public void printClassifier(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.

toString

public java.lang.String toString()
Return a String describing the XClassifier. used to show the classifier in the listPanel.

Overrides:
toString in class Classifier

getStrength

public double getStrength()
Returns:

getValue

public double getValue()
Description copied from class: Classifier
Gives the "value" of this classifier to be plotted. Should be overriden by subclasses, depending on their implementation of the Classifiers (it could be strength, accuracy, fitness,...)

Overrides:
getValue in class Classifier
Returns:
A value of the Classifier

setStrength

public void setStrength(double d)
Parameters:
d -

addStrength

public void addStrength(double d)
Parameters:
d -

compareTo

public int compareTo(java.lang.Object o)
Used to build a Comparator to sort the Classifier in order to show them ranked to the user

Specified by:
compareTo in interface java.lang.Comparable