public class Population
extends java.lang.Object
This class is a classifier set. It is used to create the folowing sets: match set [P], action set [A] and the population P, where all the classifiers belong to. There are three different constructors, one for each set. There are a lot of access methods to the population parameters, such as the numerosities sums, get and set classifiers, etc. Moreover, there are specific methods used by XCS, like methods that insert, insert subsuming, insert deleting, deletes, subsumes new classifiers in the population.
Modifier and Type | Field and Description |
---|---|
static int |
numAplicacions
This class is a classifier set.
|
Constructor and Description |
---|
Population(double[] envState,
Population pop,
int tStamp,
boolean isExploreExecution)
This constructor creates the match set of the population.
|
Population(int numCl)
It creates a new empty population (it's used in the beginning of each
experiment to initialize the population).
|
Population(Population matchSet,
int action)
It creates the action set using the match set and the chosen action.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassifier(Classifier cl)
Adds a classifier in the population.
|
Population |
createMCompPopulation(Environment env)
It creates the D population defined by Wilson 2002.
|
Classifier |
deleteClassifier()
Deletes a classifier from this population.
|
void |
deleteClassifier(int pos)
This method means that the classifer has to be definetely removed from
the population because its numerosity has decreased to 0.
|
Classifier |
deleteClFromPopulation(Population aSet)
Deletes one classifier from the population.
|
Population |
deleteNotExpClassifiers(double maxReward)
It creates a new Population with only the sufficiently experienced
classifiers.
|
void |
doActionSetSubsumption()
This method applies the action set subsumption
|
void |
drawPopulationToFile(java.io.PrintWriter fout)
It draws the population to a file.
|
double |
getAverageClTime()
Returns the average time of classifiers in the population.
|
double |
getAverageCompTime()
Returns the average reduction time of classifiers in the population.
|
Classifier |
getClassifier(int i)
Returns the classifier in the given position.
|
double |
getExperienceAverage()
Returns the experience average of the population.
|
double |
getGeneralityAverage()
Returns the generalization average of the classifiers
in the population.
|
int |
getMacroClSum()
Returns the number of macro classifiers in the set.
|
int |
getMicroClSum()
Returns the number of micro classifiers in the set.
|
Population |
getParentRef()
Returns a reference of the parent set.
|
double |
getPredErrorAverage()
It is used by specify.
|
void |
increaseMicroClSum(int mCl)
Increases the number of micro classifiers in the set.
|
void |
insertInPopulation(Classifier cl,
Population ASet)
Inserts the classifier in the population.
|
void |
insertInPSubsumingCl(Classifier cl,
Population ASet)
Inserts the classifier into the population.
|
int |
isThereClassifier(Classifier cl)
Returns the position of the classifier in the set.
|
int |
numberOfNotUseful()
Returns the number of non useful classifiers in the population.
|
double |
optimalPopulationPercentage(Population optimalPop)
Looks for the percentage of optimal classifiers present in the
current population.
|
void |
print()
Prints on standard output the population representation.
|
void |
printNotNormPopToFile(java.io.PrintWriter fout)
Prints the desnormalized population into the specified file.
|
void |
printPopulationToFile(java.io.PrintWriter fout)
Prints the population into the file specified.
|
void |
printPopulationToFile(java.lang.String fileName)
Prints the population into the specified file.
|
void |
readPopulationFromFile(java.lang.String fileName)
Reads the population from a file.
|
void |
removeNonUsefulClassifiers()
It removes all classifiers in population that are
not useful (the useful parameter is set to false)
|
void |
runGA(int tStamp,
double[] envState)
Runs the GA if the time since the last application of the GA is greater than
the threshold.
|
void |
runReduction(int tStamp)
Runs the compactation algorithm if the time since the last application of
the algorithm is greater than the threshold.
|
void |
setMacroClSum(int mCl)
Sets the number of macro classifiers in the set.
|
void |
setMicroClSum(int mCl)
Sets the number of micro classifiers in the set.
|
void |
setTCompOfClassifiers(int tStamp)
Initializes the classifiers' reduction time stamp to the tStamp value
|
void |
setTimeOfClassifiers(int tStamp)
Initializes the classifiers' time stamp to the tStamp value
|
void |
setUseful(boolean value)
It initialitzes all the useful params of the population.
|
void |
sortPopulation(int i,
int j,
int typeOfSort)
Sorts the population with a quicksort algorithm.
|
void |
updateParametersSet(double reward,
double maxPA,
double[] envState,
int tStamp)
Updates the XCS parameters of the set.
|
public static int numAplicacions
This class is a classifier set. It is used to create the folowing sets: match set [P], action set [A] and the population P, where all the classifiers belong to. There are three different constructors, one for each set. There are a lot of access methods to the population parameters, such as the numerosities sums, get and set classifiers, etc. Moreover, there are specific methods used by XCS, like methods that insert, insert subsuming, insert deleting, deletes, subsumes new classifiers in the population.
public Population(int numCl)
It creates a new empty population (it's used in the beginning of each experiment to initialize the population).
numCl
- is the number of classifiers in the population. It is defined in the configuration parameters.public Population(double[] envState, Population pop, int tStamp, boolean isExploreExecution)
This constructor creates the match set of the population. It has to cover the uncovered actions while, at least, the theta_mna actions aren't covered. It uses the actionCovered variable to do this.
envState
- is the state of the input (it has to take the classifiers that match with it).pop
- is the population of the system (it contains all the classifiers).tStamp
- it's the actual time. It's needed to create the new classifiers).isExploreExecution
- indicates if the current step is an explore or an exploit trail,
because the covering operator will be applied or not.public Population(Population matchSet, int action)
It creates the action set using the match set and the chosen action.
matchSet
- is the match set of the populationaction
- is the action chosen.public void updateParametersSet(double reward, double maxPA, double[] envState, int tStamp)
Updates the XCS parameters of the set. It updates all prediction, prediction error, fitness and action set size parameters. After that, it applies action set subsumption if it's required.
reward
- is the reward given by the environment.maxPA
- is the maximum prediction obtained in the prediction array.
* @param envState is the input exampletStamp
- is the current time stamppublic void doActionSetSubsumption()
This method applies the action set subsumption
public void deleteClassifier(int pos)
This method means that the classifer has to be definetely removed from the population because its numerosity has decreased to 0.
pos
- is the position of the population from where the classifier has to be deleted.public void addClassifier(Classifier cl)
Adds a classifier in the population.
cl
- is the new classifier to be added.public void insertInPopulation(Classifier cl, Population ASet)
Inserts the classifier in the population. Before that, it looks if there is a classifier in the population with the same action and condition (in this case, increments its numerosity). After, it checks that the number of micro classifiers is less than the maximum population size. If it isn't, it deletes one classifier from the population calling the deleteClassifier function. It inserts the classifier in the population and in the action set if it's not null.
cl
- is the classifier that has to be inserted in the population.ASet
- Population where the classifier will be inserted.public void insertInPSubsumingCl(Classifier cl, Population ASet)
Inserts the classifier into the population. Before, it looks if there is a classifier in the population that can subsume the new one (in this case, increments its numerosity). After, it checks that the number of micro classifiers is less than the maximum population size. If it isn't, it deletes one classifier of the population calling the deleteClassifier function. It inserts the classifier in the population and in the action set if it's not null.
cl
- is the classifier that has to be inserted in the population.ASet
- Population where the classifier will be inserted.public Classifier deleteClFromPopulation(Population aSet)
Deletes one classifier from the population. After that, if the population passed as a parameter is not null, it looks for the deleted classifier. If it is in the second population, it will delete it too.
aSet
- is the population where the deleted classifier has to be searched.public Classifier deleteClassifier()
Deletes a classifier from this population. It chooses the classifier to be deleted.
public double getPredErrorAverage()
It is used by specify. Returns the prediction error average.
public double getExperienceAverage()
Returns the experience average of the population. It is used by specify.
public int getMacroClSum()
Returns the number of macro classifiers in the set.
public int getMicroClSum()
Returns the number of micro classifiers in the set.
public double getGeneralityAverage()
Returns the generalization average of the classifiers in the population.
public Population getParentRef()
Returns a reference of the parent set.
public void setMacroClSum(int mCl)
Sets the number of macro classifiers in the set.
mCl
- is the number of macro classifiers.public void setMicroClSum(int mCl)
Sets the number of micro classifiers in the set.
mCl
- is the number of micro classifiers.public void increaseMicroClSum(int mCl)
Increases the number of micro classifiers in the set.
mCl
- is the number that the microClSum has to be increased.public int isThereClassifier(Classifier cl)
Returns the position of the classifier in the set. If it is not in the set, it returns -1.
cl
- is the classifier to be searched in the setpublic Classifier getClassifier(int i)
Returns the classifier in the given position.
i
- is the position of the classifier.public void runGA(int tStamp, double[] envState)
Runs the GA if the time since the last application of the GA is greater than the threshold.
tStamp
- is the actual timeenvState
- is the environment state.public void runReduction(int tStamp)
Runs the compactation algorithm if the time since the last application of the algorithm is greater than the threshold.
tStamp
- is the actual timepublic void setTimeOfClassifiers(int tStamp)
Initializes the classifiers' time stamp to the tStamp value
tStamp
- time to be set.public void setTCompOfClassifiers(int tStamp)
Initializes the classifiers' reduction time stamp to the tStamp value
tStamp
- is the time stamppublic double getAverageClTime()
Returns the average time of classifiers in the population.
public double getAverageCompTime()
Returns the average reduction time of classifiers in the population.
public Population createMCompPopulation(Environment env)
It creates the D population defined by Wilson 2002. It creates a population with the minimum number of classifiers that cover all the input examples.
env
- Environment to be set in the new population.public void sortPopulation(int i, int j, int typeOfSort)
Sorts the population with a quicksort algorithm. Its criteria is to sort the population by the numerosity or the experience.
i
- is the position where the sort algorithm has to start.j
- is the position where the sort algorithm has to finish.typeOfSort
- is to indicate if the parameter to sort the population is the numerosity (0 value) or the experience (1 value)public Population deleteNotExpClassifiers(double maxReward)
It creates a new Population with only the sufficiently experienced classifiers.
maxReward
- is the maximum reward of the environment.public void setUseful(boolean value)
It initialitzes all the useful params of the population.
value
- boolean to be set.public int numberOfNotUseful()
Returns the number of non useful classifiers in the population.
public void removeNonUsefulClassifiers()
It removes all classifiers in population that are not useful (the useful parameter is set to false)
public double optimalPopulationPercentage(Population optimalPop)
Looks for the percentage of optimal classifiers present in the current population.
optimalPop
- is the optimal population.public void printPopulationToFile(java.lang.String fileName)
Prints the population into the specified file.
fileName
- is the file name where the classifiers have to be printed.public void drawPopulationToFile(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, it 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 is obtained from Wilson-2000 XCSR
fout
- is the file where the population has to be drawn.public void printPopulationToFile(java.io.PrintWriter fout)
Prints the population into the file specified.
fout
- is the file where the population has to be printed.public void printNotNormPopToFile(java.io.PrintWriter fout)
Prints the desnormalized population into the specified file.
fout
- is the file where the population has to be printed.public void readPopulationFromFile(java.lang.String fileName)
Reads the population from a file.
fileName
- is the file name where the classifiers have to be read.public void print()