/** * Parameters Constructor * * @param dataBase Set of training data which is necessary to generate a rule * @param train Training data set with information to construct the rule base (mainly, the * training examples) */ public RuleBase(DataBase dataBase, myDataset train) { this.ruleBase = new ArrayList<Rule>(); this.dataBase = dataBase; this.train = train; this.n_variables = dataBase.numVariables(); this.fitness = 0; this.totalLabels = new int[this.n_variables]; for (int i = 0; i < this.n_variables; i++) this.totalLabels[i] = dataBase.numLabels(i); }
/** It launches the algorithm */ public void execute() { if (somethingWrong) { // We do not execute the program System.err.println("An error was found, either the data-set has missing values."); System.err.println( "Please remove the examples with missing data or apply a MV preprocessing."); System.err.println("Aborting the program"); // We should not use the statement: System.exit(-1); } else { // We do here the algorithm's operations nClasses = train.getnClasses(); dataBase = new DataBase( train.getnInputs(), train.getRanges(), train.varNames(), train.getNominals()); Population pobl = new Population( train, dataBase, populationSize, nRules, crossProb, ruleWeight, combinationType, inferenceType, p_DC, michProb); pobl.Generation(this.nGenerations); dataBase.writeFile(this.fileDB); ruleBase = pobl.bestRB(); ruleBase.writeFile(this.fileBR); // Finally we should fill the training and test output files double accTra = doOutput(this.val, this.outputTr); double accTst = doOutput(this.test, this.outputTst); System.out.println("Accuracy obtained in training: " + accTra); System.out.println("Accuracy obtained in test: " + accTst); System.out.println("Algorithm Finished"); } }