private void calculateRightNWrongN() { int i, j, nData, evaClass; boolean stop; Rule rule; nData = this.train.size(); for (j = 0; j < this.ruleBase.size(); j++) { rule = this.ruleBase.get(j); rule.setIni(); } this.WrongNDefault = 0; for (i = 0; i < nData; i++) { for (j = 0; j < this.ruleBase.size(); j++) { rule = this.ruleBase.get(j); rule.matching(train.getExample(i)); } this.sort(); stop = false; for (j = 0; j < this.ruleBase.size() && !stop; j++) { rule = this.ruleBase.get(j); if (train.getOutputAsInteger(i) == rule.getClas()) { rule.incrRightN(); stop = true; } else rule.incrWrongN(); } } }
/** This function calculates the number of errors */ private void rateError() { int n_errores, Prediction; n_errores = 0; for (int j = 0; j < train.size(); j++) { Prediction = this.FRM_WR(train.getExample(j)); if (train.getOutputAsInteger(j) != Prediction) n_errores++; } this.fitness = n_errores; }
/** Function to evaluate the whole rule base by using the training dataset */ public void evalua() { int n_clasificados, Prediction; n_clasificados = 0; for (int j = 0; j < train.size(); j++) { Prediction = this.FRM_WR(train.getExample(j)); if (train.getOutputAsInteger(j) == Prediction) n_clasificados++; } this.fitness = n_clasificados; }
/** * It generates the output file from a given dataset and stores it in a file * * @param dataset myDataset input dataset * @param filename String the name of the file * @param lanzar Chc the algorithm class */ private void doOutput(myDataset dataset, String filename, Chc lanzar) { String output = new String(""); output = dataset.copyHeader(); // we insert the header in the outputa file // We write the output for each example for (int i = 0; i < dataset.getnData(); i++) { // for regression: output += dataset.getOutputAsReal(i) + " " + (double) this.regressionOutput(dataset.getExample(i), lanzar) + "\n"; } Fichero.escribeFichero(filename, output); }
/** * It generates the output file from a given dataset and stores it in a file * * @param dataset myDataset input dataset * @param filename String the name of the file */ private void doOutput(myDataset dataset, String filename) { int i; double fuerza; String output = new String(""); output = dataset.copyHeader(); // we insert the header in the output file for (i = 0; i < dataset.getnData(); i++) { fuerza = Output_fuzzy_system(dataset.getExample(i)); output += (dataset.getOutputAsReal(i) + " " + fuerza + " " + "\n"); } Files.writeFile(filename, output); }
/** * It generates the output file from a given dataset and stores it in a file * * @param dataset myDataset input dataset * @param filename String the name of the file * @return The classification accuracy */ private double doOutput(myDataset dataset, String filename) { String output = new String(""); int hits = 0; output = dataset.copyHeader(); // we insert the header in the output file // We write the output for each example for (int i = 0; i < dataset.getnData(); i++) { // for classification: String classOut = this.classificationOutput(dataset.getExample(i)); output += dataset.getOutputAsString(i) + " " + classOut + "\n"; if (dataset.getOutputAsString(i).equalsIgnoreCase(classOut)) { hits++; } } Files.writeFile(filename, output); return (1.0 * hits / dataset.size()); }
/** * It Evaluates the performance of the fuzzy system. The Mean Square Error (MSE) by training is * used */ public double Evaluate_fuzzy_system() { int i; double result, suma, fuerza; suma = 0.0; for (i = 0; i < train.getnData(); i++) { fuerza = Output_fuzzy_system(train.getExample(i)); suma += Math.pow(train.getOutputAsReal(i) - fuerza, 2.0); } result = suma / train.getnData(); /* We want to have a maximization problem so, we invert the error */ if (result != 0.0) { result = 1.0 / result; } return (result); }
/** * It Evaluates the performance of the best evolved fuzzy system on test data. The Mean Square * Error (MSE) is used * * @return double The MSE error in test data */ public double Evaluate_best_fuzzy_system_in_test() { int i; double result, suma, fuerza; SistemaDifuso.clear(); for (i = 0; i < Nr; i++) { Individual indi = new Individual(BestSistemaDifuso.get(i)); SistemaDifuso.add(indi); } suma = 0.0; for (i = 0; i < test.getnData(); i++) { fuerza = Output_fuzzy_system(test.getExample(i)); suma += Math.pow(test.getOutputAsReal(i) - fuerza, 2.0); } result = suma / test.getnData(); return (result); }