public class XCS
extends java.lang.Object
This is the main class of the XCS. The input parameters to run the aplication are: IN THE TRAIN MODE: java XCS train type_of_problem configuration_file [descriptorFile]* [examplesFile]* .The configuration_file is the file that contains all the initial values for XCS parameters, and it has to be parsed by the application. .The type_of_problem parameter indicates the problem to be executed. For each type of problem, an environment has to be implemented. .The []* parameters are only necessary in single step file problems. In the descriptor file, the type of attributes are specified, while all the examples are in the examples file. IN THE TEST MODE: java XCS test input_file type_of_problem configuration_file [descriptorFile]* [examplesFile]* . The input_file is the file where the classifiers of a train execution have been stored. So, first of all, the aplication will read all the classifiers in the file, and then will start the test execution. IN THE REDUCTION MODE: java XCS reduction input_rules_file configuration_file In case of being a reduction, the rules are read from a file, and the reduction chosen in the configuration file is made. . The input_rules_file is the file that contains the input rules that have to be reduced. . The configuration_file is the file that contains all the inital values for XCS parameters, and it has to be parsed by the application.
This class contains the XCS itself. It has the population, the prediction array, and the test, train and reduction environments, and objects of statistics and reduction classes. It is highly configurable, so, using a configuration file, usally with the extension ".kcf" (keel configuration), almost any possible configuration can be defined.
Constructor and Description |
---|
XCS(java.lang.String configFile)
Initializes an XCS object.
|
Modifier and Type | Method and Description |
---|---|
int[] |
createAndInitArray(int N)
Creates and initializes an integer vector of size N
|
Population |
doOneReductionExecution(Environment reductionEnv)
Runs a reduction of the population and returns the reduced population.
|
void |
doOneSingleStepExploit(Environment tEnv,
double[] envState,
int acTime,
int[] windowExecutionResults,
double[] sysError,
boolean isTest,
int typeOfTest,
boolean writeExpOut)
Performs one single step exploit.
|
void |
doOneSingleStepExplore(double[] envState,
int acTime)
Performs one explore iteration.
|
void |
doOneTestExperiment(Environment tEnv,
int typeOfTest,
int[] globalResults,
boolean writeExpOut)
Performs a test experiment.
|
void |
doOneTrainExperiment(int[] globalResults)
Runs one train XCS experiment.
|
void |
doScreenStatistics(int tStamp,
int exploitNum,
double[] sysError,
int[] statisticVector,
int[] globalResults)
It computes the statistics
|
void |
doTestScreenStatistics(int tStamp,
int[] globalResults,
double[] sysError,
int numProblems)
It does test screen statistics
|
void |
finishXCS(long iTime)
It makes the last things to do after closing the program.
|
void |
print(java.io.BufferedReader r)
Does print the population and stops the execution.
|
void |
run()
Execute the algorithm XCS
|
void |
startReductXCS()
Applies the reduction choosen by the user.
|
void |
startTestXCS()
Runs one test XCS experiment.
|
void |
startTrainXCS()
Runs one XCS train experiment.
|
public XCS(java.lang.String configFile)
Initializes an XCS object. It configures the XCS run reading the configuration file.
configFile
- is the name of the config file.public void run()
public void startTrainXCS()
Runs one XCS train experiment. It creates a new population and calls the function doOneTrainExperiment. It makes explore and exploit iterations. It also updates time statistics.
public void startTestXCS()
Runs one test XCS experiment. The diference between test and train is that in the test experiment only exploit trials are made, and the parameters of the classifiers are not updated. In addition, the covering operator is not applied, so, we can have some unclassified examples.
public void doOneTrainExperiment(int[] globalResults)
Runs one train XCS experiment. Now, in the train run, one exploit is done between N explores (where N is a parameter defined by the user). So, the operators of covering, the GA and the update parameters routines are called in the explore runs.
globalResults
- contains the addition of all classified, not classified
and correct and wrong classified examples of the exploit executions in the train.public void doOneTestExperiment(Environment tEnv, int typeOfTest, int[] globalResults, boolean writeExpOut)
Performs a test experiment. It does not apply the covering operator, the GA and the update parameters routines. It only creates the match set and the prediction array, choosing the best action. If there are more than one action with the same probability, it chooses one of them randomly. For the moment, the examples are chosen sequentially from the environment if it's a file single step environment, to be sure that all the examples will participate in the test run.
tEnv
- is the environment to do the test. It can be the same or different from
the train environment.typeOfTest
- is a parameter that indicates the kind of test: testing with the test
set (0) or testing with the train set (1)globalResults
- contains the addition of all classified, not classified and correct
and wrong classified examples of the exploit executions in the train.writeExpOut
- true if it is wanted to write out the experiment.public void doOneSingleStepExplore(double[] envState, int acTime)
Performs one explore iteration. It applies the covering operator, the GA and the update parameters routines if it is necessary.
envState
- is the new example that has to be classified.acTime
- is the current time stamp of the system. It is used to decide
if the GA has to be applied, and to create new classifiers.public void doOneSingleStepExploit(Environment tEnv, double[] envState, int acTime, int[] windowExecutionResults, double[] sysError, boolean isTest, int typeOfTest, boolean writeExpOut)
Performs one single step exploit. It only chooses the best prediction from the prediction array (it is not stochastic)
tEnv
- is the environment to do the test. It can be the same or different from
the train environment.envState
- is the new example that has to be classified.acTime
- is the current time stamp of the system. It's used to
decide if the GA has to be applied, and to create new classifiers.windowExecutionResults
- is an array where the results are set
down to make statistics.sysError
- is an array where the errors in the predictions are
set down to make posterior statistics.isTest
- indicates if the envariment is a test one.typeOfTest
- indicates the test set kind (if is the test set (0) or the train
set (1) ) of the run.writeExpOut
- determines is an output file with expected-real
output has to be writen.public void doScreenStatistics(int tStamp, int exploitNum, double[] sysError, int[] statisticVector, int[] globalResults)
It computes the statistics
tStamp
- is the time of the XCS.exploitNum
- is the number of exploits that XCS has made.sysError
- is the error sum of XCS.statisticVector
- is the vector that contains all the statisticsglobalResults
- is a vector with the global results statistics.public void doTestScreenStatistics(int tStamp, int[] globalResults, double[] sysError, int numProblems)
It does test screen statistics
tStamp
- is the system time.globalResults
- is the sum of all statistics done in the system.sysError
- is the error sum of XCS.numProblems
- is the number of examples done in the run.public void startReductXCS()
Applies the reduction choosen by the user. First of all, the population is read from a file. Then, it distinguishes between the Wilson reduction and the two versions of Dixon's alternative reduction algorithm.
public Population doOneReductionExecution(Environment reductionEnv)
Runs a reduction of the population and returns the reduced population.
reductionEnv
- is the environment that has to be used to do the reductionpublic int[] createAndInitArray(int N)
N
- is the size of the vector that has to be createdpublic void finishXCS(long iTime)
It makes the last things to do after closing the program. It upgrades the times, print the last statistics and close all opened files.
iTime
- is the actual time.public void print(java.io.BufferedReader r)
r
- is the bufferedReader where to read.