public class Population
extends java.lang.Object
This class contains a rule-set. It is used to create the folowing sets: population [P], match set [M], and correct set [C]. 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 UCS, like methods that insert, insert subsuming, insert deleting, deletes, subsumes new classifiers in the population.
Constructor and Description |
---|
Population(int numCl)
Population constructor: it creates an empty population.
|
Population(Population pop,
double[] envState)
Math set [M] constructor.
|
Population(Population matchSet,
double[] envState,
int classOfExample,
int tStamp)
Correct set [C] constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addClassifier(Classifier cl)
Adds a classifier in the population.
|
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.
|
double |
getAverageClTime()
Returns the average 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.
|
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)
Inserts the classifier into the population.
|
int |
isThereClassifier(Classifier cl)
Returns the position of the classifier in the set.
|
void |
print()
Prints on standard output the population representation.
|
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 |
runGA(int tStamp,
double[] envState,
int classOfExample)
Runs the GA if the time since the last application of the GA 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 |
setTimeOfClassifiers(int tStamp)
Initializes the classifiers' time stamp to the tStamp value
|
void |
sortPopulation(int i,
int j,
int typeOfSort)
Sorts the population with a quicksort algorithm.
|
Classifier |
tournamentSelection()
It implements tournament selection.
|
void |
updateParametersSet(double microClInC,
double[] envState,
int classOfExample,
int tStamp)
Updates UCS' parameters.
|
public Population(int numCl)
Population constructor: it creates an empty population.
numCl
- is the number of classifiers in the population.
It is defined in the configuration parameters.public Population(Population pop, double[] envState)
Math set [M] constructor. It selects all the matching classifiers from [P] to create [M].
pop
- is the population [P].envState
- is the input example.public Population(Population matchSet, double[] envState, int classOfExample, int tStamp)
Correct set [C] constructor. It selects all the classifiers from [M] that advocate the class of the example.
matchSet
- is the match set of the populationenvState
- is the input example.classOfExample
- is the class of the input example.tStamp
- the time to count.public void updateParametersSet(double microClInC, double[] envState, int classOfExample, int tStamp)
Updates UCS' parameters.
microClInC
- is the number of microclassifiers in [C]envState
- is the input exampleclassOfExample
- is the class of the input exampletStamp
- is the current time stamppublic 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)
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.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 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, int classOfExample)
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.classOfExample
- example's class.public Classifier tournamentSelection()
public void setTimeOfClassifiers(int tStamp)
Initializes the classifiers' time stamp to the tStamp value
tStamp
- time to be set.public double getAverageClTime()
Returns the average time of classifiers in the 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 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 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 print()