public class Classifier
extends java.lang.Object
The classifier contains two classes, the representation and the parameters. So, the metods of the class are: get and set fitness, action, etc.
Constructor and Description |
---|
Classifier(Classifier parent1,
Classifier parent2,
int tStamp)
It creates a new classifier making a crossover between the parents parametres.
|
Classifier(Classifier cl,
int tStamp)
It creates a new classifier copying the representation and the parameters of the
classifier passed as a parameter.
|
Classifier(double[] condition,
int action,
int size,
int tStamp)
It constructs a classifier with the condition and the action specified.
|
Classifier(java.util.StringTokenizer t)
It creates a new classifier with the parameters contained in the String.
|
Modifier and Type | Method and Description |
---|---|
void |
addUsefulTimes(int num)
Adds the value passed to the usefulTimes parameter of
the classifier
|
void |
calculateGenerality()
Computes the generality of the classifier.
|
boolean |
couldComp()
Indicates if the classifier is accurate and experienced enough
to not be removed from the population
|
boolean |
couldReduce(double maxReward)
Returns if the classifier is experienced,
and accurate enough to be in the reduction set.
|
boolean |
couldSubsume()
Returns if the classifier can subsume.
|
void |
crossAllele(int i,
Classifier parent1,
Classifier parent2)
It crosses a real allele within two parents.
|
double |
deletionVote(double avFitness)
Returns the probability of a classifier to be deleted.
|
boolean |
doesSubsume(Classifier cl)
Returns if the classifier of the class subsumes the classifier
passed as a parameter.
|
void |
draw(java.io.PrintWriter fout)
It draws the population to a file.
|
boolean |
equals(Classifier cl)
Returns if the classifier of the class is equal to the classifier
given as a parameter.
|
double |
getAccuracy()
Returns the accuracy of the classifier.
|
int |
getAction()
Returns the action of the classifier
|
double |
getASize()
Returns the estimated action set size.
|
int |
getCompTime()
Returns the time of the classifier.
|
int |
getExperience()
Returns the experience of the classifier.
|
double |
getFitness()
Returns the fitness of the classifier.
|
double |
getGenerality()
Gets the generality of the classifier.
|
int |
getNumberMatches()
Gets the number of matches of the classifier.
|
int |
getNumerosity()
Returns the numerosity of the classifier.
|
double |
getPredError()
Returns the prediction error of the classifier.
|
double |
getPrediction()
Returns the prediction of the classifier.
|
Representation |
getRep()
Returns the representation of the classifier.
|
int |
getTime()
Returns the time stamp of the classifier.
|
boolean |
getUseful()
Gets the useful parameter of the classifier.
|
int |
getUsefulTimes()
Gets the useful times parameter of the classifier.
|
void |
increaseNumberMatches(int num)
Increases the number of matches
|
void |
increaseNumerosity(int num)
Increases the numerosity of the classifier.
|
boolean |
isMoreGeneral(Classifier cl)
Indicates if the classifier is more general than
the classifier passed as a parameter.
|
void |
makeSpecify(double[] env)
Changes all the don't care symbols by the state in
the environment, with Pspecify probability
|
boolean |
match(double[] envState)
Indicates if the classifier matches with the environmental state
|
boolean |
mutate(double[] envState)
Mutates the classifier.
|
double |
numberOfDontCareSymbols()
Returns the number of don't care symbols in the
classifier.
|
void |
print()
Prints the classifier.
|
void |
print(java.io.PrintWriter fout)
Prints the classifier to the specified file.
|
void |
printNotNorm(java.io.PrintWriter fout)
Prints the desnormalized classifier to the specified file.
|
void |
setAction(int act)
Sets the action passed to the classifier
|
void |
setAllele(int i,
Classifier cl)
sets the allele value
|
void |
setAllele(int i,
double lowerValue,
double upperValue)
Sets the allele value
|
void |
setCompTime(int tStamp)
Sets the compactation time stamp for this classifier.
|
void |
setFitness(double fit)
Sets the fitness of the classifier at the value specified
|
void |
setNumberMatches(int num)
Sets the number of matches
|
void |
setNumerosity(int num)
Sets the numerosity of the classifier.
|
void |
setPredError(double predErr)
Sets the prediction error
|
void |
setPrediction(double pred)
Sets the prediction value.
|
void |
setTime(int tStamp)
Sets the time stamp for this classifier.
|
void |
setUseful(boolean value)
Sets the useful parameter
|
void |
setUseful(int value)
Sets the usefulTimes parameter
|
void |
updateFitness(double kSum,
double k)
Updates the fitness of a classifier
|
void |
updateParameters(double P,
double microClSum)
Updates the parameters of a classifier (reinforcement component)
|
public Classifier(double[] condition, int action, int size, int tStamp)
It constructs a classifier with the condition and the action specified. It's used by the covering operator.
condition
- is the environtment stateaction
- is the action chosensize
- is the size of the set.tStamp
- is the time
public Classifier(Classifier cl, int tStamp)
It creates a new classifier copying the representation and the parameters of the classifier passed as a parameter.
cl
- is the classifier to be copied to the new classifier.tStamp
- is the current time stamp.public Classifier(Classifier parent1, Classifier parent2, int tStamp)
It creates a new classifier making a crossover between the parents parametres. Any of the attributes representation are copied because it will be initialized by the GA.
parent1
- is the first parent.parent2
- is the second parent.tStamp
- is the current time stamp.public Classifier(java.util.StringTokenizer t)
It creates a new classifier with the parameters contained in the String. It is used when reading the classifiers from a file.
t
- StringTokenizer to get the parameterspublic boolean mutate(double[] envState)
Mutates the classifier. It mutates the action and the condition.
envState
- is the current environtment state. It is necessary for the niched mutation.public void updateParameters(double P, double microClSum)
Updates the parameters of a classifier (reinforcement component)
P
- is the payoff of the current iteration (P = reward + gamma * maxPrediction)microClSum
- is the numerosity of the action set (all the action set.).public void updateFitness(double kSum, double k)
Updates the fitness of a classifier
kSum
- is the sum of all accuracies.k
- is the accuracy of the classifier.public boolean match(double[] envState)
Indicates if the classifier matches with the environmental state
envState
- is the environment statepublic boolean equals(Classifier cl)
Returns if the classifier of the class is equal to the classifier given as a parameter.
cl
- is a classifier.public boolean doesSubsume(Classifier cl)
Returns if the classifier of the class subsumes the classifier passed as a parameter.
cl
- is the subsumed classifier.public double deletionVote(double avFitness)
Returns the probability of a classifier to be deleted.
avFitness
- is the average fitness of the set.public Representation getRep()
Returns the representation of the classifier.
public void crossAllele(int i, Classifier parent1, Classifier parent2)
It crosses a real allele within two parents. If the representation is a ternary representation, a crossover within intervals is not possible because there is only one gene in each position. So, in this case, the gene of the second parent will be copied. In case of being a real representation, a random number is generated to decide where to cross the interval. It it's crossed within the inteval, the crossAllele method will do it.
i
- position to cross.parent1
- is the first parent classifier.parent2
- is the second parent classifier.public void setAllele(int i, double lowerValue, double upperValue)
Sets the allele value
i
- is the position.lowerValue
- is the lower value that has to be set.upperValue
- is the upper value that has to be set.public void setAllele(int i, Classifier cl)
sets the allele value
i
- is the position.cl
- is the classifier that has to be copied.public int getAction()
Returns the action of the classifier
public double getAccuracy()
Returns the accuracy of the classifier.
public double getPrediction()
Returns the prediction of the classifier.
public double getPredError()
Returns the prediction error of the classifier.
public double getFitness()
Returns the fitness of the classifier.
public int getNumerosity()
Returns the numerosity of the classifier.
public int getTime()
Returns the time stamp of the classifier.
public int getCompTime()
Returns the time of the classifier. The difference between timeOfCl and tComp is that the last one is used to the "new reduction" algorithm, while "timeOfCl" is the usual time stamp of XCS
public double getASize()
Returns the estimated action set size.
public int getExperience()
Returns the experience of the classifier.
public double getGenerality()
Gets the generality of the classifier.
public int getNumberMatches()
Gets the number of matches of the classifier.
public boolean getUseful()
Gets the useful parameter of the classifier.
public int getUsefulTimes()
Gets the useful times parameter of the classifier.
public void setAction(int act)
Sets the action passed to the classifier
act
- is the action to be set.public void setTime(int tStamp)
Sets the time stamp for this classifier.
tStamp
- is the time stamppublic void setCompTime(int tStamp)
Sets the compactation time stamp for this classifier.
tStamp
- is the time stamppublic void setFitness(double fit)
Sets the fitness of the classifier at the value specified
fit
- is the fitness that has to take the classifier.public void setNumerosity(int num)
Sets the numerosity of the classifier.
num
- numerosity to set.public void setPrediction(double pred)
Sets the prediction value.
pred
- is the prediction to be setpublic void setPredError(double predErr)
Sets the prediction error
predErr
- is the prediction error value.public void setNumberMatches(int num)
Sets the number of matches
num
- is the number of matches to be set.public void setUseful(boolean value)
Sets the useful parameter
value
- is the value that the useful param has to be set.public void setUseful(int value)
Sets the usefulTimes parameter
value
- is the value that the useful param has to be set.public void increaseNumberMatches(int num)
Increases the number of matches
num
- is the number of matches to be increased.public void calculateGenerality()
Computes the generality of the classifier. Its result is stored in the generality parameter.
public void increaseNumerosity(int num)
Increases the numerosity of the classifier.
num
- is the number to increase the numerosity of the classifier.public void makeSpecify(double[] env)
Changes all the don't care symbols by the state in the environment, with Pspecify probability
env
- is the environment.public double numberOfDontCareSymbols()
Returns the number of don't care symbols in the classifier. It is used by the action set subsumption
public boolean isMoreGeneral(Classifier cl)
Indicates if the classifier is more general than the classifier passed as a parameter.
cl
- is the classifier to which the current classifier is compared.public boolean couldSubsume()
Returns if the classifier can subsume. The classifier has to be sufficiently accurate and sufficiently experienced to subsume another classifier.
public boolean couldReduce(double maxReward)
Returns if the classifier is experienced, and accurate enough to be in the reduction set. Otherwise, the classifier will not be included in the reduction
maxReward
- is the maximum reward of the environment.public void addUsefulTimes(int num)
num
- is the value that has to be addedpublic boolean couldComp()
public void print()
Prints the classifier.
public void print(java.io.PrintWriter fout)
Prints the classifier to the specified file.
fout
- is the file output where the classifier has to be printed.public void printNotNorm(java.io.PrintWriter fout)
Prints the desnormalized classifier to the specified file.
fout
- is the file output where the classifier has to be printed.public void draw(java.io.PrintWriter fout)
It draws the population to a file. A character allele is drawn as 1 o 0. Otherwise, a real allele is drawn in ten points, which represent the interval [0..1] divided in ten fragments. In each fragment, there can be three types of symbols: . --> The fragment is not covered by the classifier. o --> The fragment is partially covered by the classifier. O --> The fragment is totally covered by the classifier. This notation has been got from Wilson2000 XCSR
fout
- is the file where the population has to be drawn.