/** Calculates the necessary statistical data and creates KEEL out-put files */ private void generaSalida() { Fichero f = new Fichero(); String cad = ""; String miSalida = new String(""); miSalida = train.copiaCabeceraTest(); // System.out.println("\n Estas son las reglas encontradas:"); // conjReglasFinal.print(); conjunto_reglas.adjuntaNombreClases(clases); conjunto_reglas.adjuntaNombreClase(nombre_atributos[train.getnentradas()]); cad = conjunto_reglas.printString(); /*cad += "\n\n" + evReg.printString() + "\n\n Time (seconds); " + (tiempo / 1000);*/ f.escribeFichero(ficheroSalida, cad); f.escribeFichero(ficheroSalidaTr, miSalida + evReg.salida(datosTrain)); f.escribeFichero(ficheroSalidaTst, miSalida + evReg.salida(datosTest)); }
/** * 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 data containing integer identifiers of nominal values * @param classData containing integer identifiers of classes * @param infoAttr containing number of values for each attribute * @param contenedor containing all the interesting rules * @param nClasses indicates number of classes */ private void doOutput( myDataset dataset, String filename, int data[][], int classData[], int infoAttr[], Vector<Rule> contenedor, int nClases) { String output = new String(""); 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: output += dataset.getOutputAsString(i) + " " + this.classificationOutput( dataset, i, data, classData, infoAttr, contenedor, nClasses) + "\n"; } Fichero.escribeFichero(filename, output); }
public static void main(String[] args) { String cadena = ""; StringTokenizer lineas, tokens, tokensT; String linea, dato1, dato2, token, timesplit[]; boolean algorithms = true; Vector<String> algoritmos; Vector<String> datasets; Vector<Integer> saltos; int i, j, k, l, m, n; double accuracyAv[][]; double accuracySD[][]; double reductionAv[][]; double reductionSD[][]; double kappaAv[][]; double kappaSD[][]; double accredAv[][]; double kapredAv[][]; double time[][]; int runs[][]; String alAct, alAnterior; int configAct; String datAct; int salAct; double acc, red, kappa; int aciertos, total; double accV[], redV[], kappaV[]; Vector<String> valoresClase; int confusionMatrix[][]; int sumKappa, sumi, sumj; double accSD, redSD, kapSD; String tiempos; int postime; if (args.length != 1) { System.err.println("Error. Hace falta un parámetro: Fichero de algoritmos y datasets."); System.exit(1); } algoritmos = new Vector<String>(); datasets = new Vector<String>(); saltos = new Vector<Integer>(); /*Lectura del fichero de configuración*/ cadena = Fichero.leeFichero(args[0]); lineas = new StringTokenizer(cadena, "\n\r"); while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (linea.equalsIgnoreCase("----")) algorithms = false; else { if (algorithms) { algoritmos.addElement(new String(linea)); } else { tokens = new StringTokenizer(linea, " "); token = tokens.nextToken(); datasets.addElement(new String(token)); token = tokens.nextToken(); saltos.addElement(new Integer(token)); } } } accuracyAv = new double[datasets.size()][algoritmos.size()]; accuracySD = new double[datasets.size()][algoritmos.size()]; reductionAv = new double[datasets.size()][algoritmos.size()]; reductionSD = new double[datasets.size()][algoritmos.size()]; kappaAv = new double[datasets.size()][algoritmos.size()]; kappaSD = new double[datasets.size()][algoritmos.size()]; accredAv = new double[datasets.size()][algoritmos.size()]; kapredAv = new double[datasets.size()][algoritmos.size()]; time = new double[datasets.size()][algoritmos.size()]; runs = new int[datasets.size()][algoritmos.size()]; accV = new double[10]; redV = new double[10]; kappaV = new double[10]; // tiempos = Fichero.leeFichero("tiempos.txt"); tiempos = Fichero.leeFichero("tiempos.txt"); tokensT = new StringTokenizer(tiempos, "=\n\r"); System.out.println("Numbero de algoritmos " + algoritmos.size()); System.out.println("Dataset Size = " + datasets.size()); /*Cálculo del accuracy, kappa y reducción en KNN (TRAIN)*/ configAct = 0; for (j = 0; j < datasets.size(); j++) { System.out.println("Processing dataset: " + datasets.elementAt(j)); for (i = 0; i < algoritmos.size(); i++) { alAct = (String) algoritmos.elementAt(i); configAct = i; datAct = (String) datasets.elementAt(j); salAct = ((Integer) saltos.elementAt(j)).intValue(); acc = red = kappa = 0.0; for (k = 0; k < 10; k++) { /*Accuracy Computation*/ int result = (j + salAct) * algoritmos.size() * 10 + i * 10 + k; // Calculo el result correspondiente. // System.out.println("results//Clas-KNN//"+alAct+"//result"+Integer.toString((j+salAct)*datasets.size()+i*10+k)+".tra"); cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tra"); lineas = new StringTokenizer(cadena, "\n\r"); aciertos = total = 0; while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); dato2 = tokens.nextToken(); if (dato1.equalsIgnoreCase(dato2)) { aciertos++; total++; } else { total++; } } } accV[k] = (double) aciertos / (double) total; // System.out.println(accV[k]); /*Reduction Computation*/ cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + "e0.txt"); tokens = new StringTokenizer(cadena, "=\n\r"); tokens.nextToken(); dato1 = tokens.nextToken(); redV[k] = Double.parseDouble(dato1.substring(1)) / 100.0; /*Kappa Computation*/ cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tra"); System.out.println("Result" + result); ; lineas = new StringTokenizer(cadena, "\n\r"); aciertos = total = 0; valoresClase = new Vector<String>(); while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); if (!valoresClase.contains(dato1)) { valoresClase.addElement(dato1); } } } confusionMatrix = new int[valoresClase.size()][valoresClase.size()]; lineas = new StringTokenizer(cadena, "\n\r"); total = 0; while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); dato2 = tokens.nextToken(); try { confusionMatrix[valoresClase.indexOf(dato1)][valoresClase.indexOf(dato2)]++; } catch (ArrayIndexOutOfBoundsException e) { confusionMatrix[valoresClase.indexOf(dato1)][0]++; } total++; } } sumKappa = 0; for (l = 0; l < valoresClase.size(); l++) { sumKappa += confusionMatrix[l][l]; } kappa = total * sumKappa; sumKappa = 0; for (l = 0; l < valoresClase.size(); l++) { sumi = 0; for (m = 0; m < valoresClase.size(); m++) { sumi += confusionMatrix[l][m]; } sumj = 0; for (m = 0; m < valoresClase.size(); m++) { sumj += confusionMatrix[m][l]; } sumKappa += sumi * sumj; } kappaV[k] = (double) (kappa - sumKappa) / (double) (total * total - sumKappa); // System.out.println(accV[k]); } acc = 0; for (l = 0; l < accV.length; l++) { acc += accV[l]; } acc /= (double) accV.length; red = 0; for (l = 0; l < redV.length; l++) { red += redV[l]; } red /= (double) redV.length; kappa = 0; for (l = 0; l < kappaV.length; l++) { kappa += kappaV[l]; } kappa /= (double) kappaV.length; accSD = redSD = kapSD = 0; for (l = 0; l < accV.length; l++) { accSD += (acc - accV[l]) * (acc - accV[l]); } accSD = Math.sqrt(accSD / (double) accV.length); for (l = 0; l < redV.length; l++) { redSD += (red - redV[l]) * (red - redV[l]); } redSD = Math.sqrt(redSD / (double) redV.length); for (l = 0; l < kappaV.length; l++) { kapSD += (kappa - kappaV[l]) * (kappa - kappaV[l]); } kapSD = Math.sqrt(kapSD / (double) kappaV.length); /*Store the values in the main matrixes*/ accuracyAv[j][i] = acc; accuracySD[j][i] = accSD; reductionAv[j][i] = red; reductionSD[j][i] = redSD; kappaAv[j][i] = kappa; kappaSD[j][i] = kapSD; accredAv[j][i] = acc * red; kapredAv[j][i] = kappa * red; // System.out.println("Acc =" +acc); /*Time processing*/ /* for( k=0; k< 10 ;k++){ dato1 = tokensT.nextToken(); time[j][i] += Double.parseDouble(dato1) ; runs[j][i]++; //System.out.println(dato1); }*/ } } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaAccuracyTRA.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", accuracyAv[i][j]) + "\t" + String.format("%6.4f", accuracySD[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaAccuracyTRA.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaReduction.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", reductionAv[i][j]) + "\t" + String.format("%6.4f", reductionSD[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaReduction.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t"; } cadena += "\n"; Fichero.escribeFichero("tablaTime.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", time[i][j] / (double) runs[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaTime.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaKappaTRA.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", kappaAv[i][j]) + "\t" + String.format("%6.4f", kappaSD[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaKappaTRA.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaAccRedTRA.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", accredAv[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaAccRedTRA.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaKappaRedTRA.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", kapredAv[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaKappaRedTRA.txt", cadena); } configAct = 0; /*Cálculo del accuracy, kappa y reducción en KNN (TST)*/ for (j = 0; j < datasets.size(); j++) { for (i = 0; i < algoritmos.size(); i++) { alAct = (String) algoritmos.elementAt(i); // System.out.println("Processing algorithm: " + alAct); salAct = ((Integer) saltos.elementAt(j)).intValue(); acc = red = kappa = 0.0; for (k = 0; k < 10; k++) { /*Accuracy Computation*/ int result = (j + salAct) * algoritmos.size() * 10 + i * 10 + k; // Calculo el result correspondiente. cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tst"); lineas = new StringTokenizer(cadena, "\n\r"); aciertos = total = 0; while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); dato2 = tokens.nextToken(); if (dato1.equalsIgnoreCase(dato2)) { aciertos++; total++; } else { total++; } } } accV[k] = (double) aciertos / (double) total; /*Reduction Computation*/ cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + "e0.txt"); tokens = new StringTokenizer(cadena, "=\n\r"); tokens.nextToken(); dato1 = tokens.nextToken(); redV[k] = Double.parseDouble(dato1.substring(1)) / 100.0; /*Kappa Computation*/ cadena = Fichero.leeFichero( "results//Clas-KNN//" + alAct + "//result" + Integer.toString(result) + ".tst"); lineas = new StringTokenizer(cadena, "\n\r"); aciertos = total = 0; valoresClase = new Vector<String>(); while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); if (!valoresClase.contains(dato1)) { valoresClase.addElement(dato1); } } } confusionMatrix = new int[valoresClase.size()][valoresClase.size()]; lineas = new StringTokenizer(cadena, "\n\r"); total = 0; while (lineas.hasMoreTokens()) { linea = lineas.nextToken(); if (!(linea.startsWith("@"))) { tokens = new StringTokenizer(linea, " "); dato1 = tokens.nextToken(); dato2 = tokens.nextToken(); try { confusionMatrix[valoresClase.indexOf(dato1)][valoresClase.indexOf(dato2)]++; } catch (ArrayIndexOutOfBoundsException e) { confusionMatrix[valoresClase.indexOf(dato1)][0]++; } total++; } } sumKappa = 0; for (l = 0; l < valoresClase.size(); l++) { sumKappa += confusionMatrix[l][l]; } kappa = total * sumKappa; sumKappa = 0; for (l = 0; l < valoresClase.size(); l++) { sumi = 0; for (m = 0; m < valoresClase.size(); m++) { sumi += confusionMatrix[l][m]; } sumj = 0; for (m = 0; m < valoresClase.size(); m++) { sumj += confusionMatrix[m][l]; } sumKappa += sumi * sumj; } kappaV[k] = (double) (kappa - sumKappa) / (double) (total * total - sumKappa); } acc = 0; for (l = 0; l < accV.length; l++) { acc += accV[l]; } acc /= (double) accV.length; red = 0; for (l = 0; l < redV.length; l++) { red += redV[l]; } red /= (double) redV.length; kappa = 0; for (l = 0; l < kappaV.length; l++) { kappa += kappaV[l]; } kappa /= (double) kappaV.length; accSD = redSD = kapSD = 0; for (l = 0; l < accV.length; l++) { accSD += (acc - accV[l]) * (acc - accV[l]); } accSD = Math.sqrt(accSD / (double) accV.length); for (l = 0; l < redV.length; l++) { redSD += (red - redV[l]) * (red - redV[l]); } redSD = Math.sqrt(redSD / (double) redV.length); for (l = 0; l < kappaV.length; l++) { kapSD += (kappa - kappaV[l]) * (kappa - kappaV[l]); } kapSD = Math.sqrt(kapSD / (double) kappaV.length); /*Store the values in the main matrixes*/ accuracyAv[j][i] = acc; accuracySD[j][i] = accSD; reductionAv[j][i] = red; reductionSD[j][i] = redSD; kappaAv[j][i] = kappa; kappaSD[j][i] = kapSD; accredAv[j][i] = acc * red; kapredAv[j][i] = kappa * red; } } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaAccuracyTST.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", accuracyAv[i][j]) + "\t" + String.format("%6.4f", accuracySD[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaAccuracyTST.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaKappaTST.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", kappaAv[i][j]) + "\t" + String.format("%6.4f", kappaSD[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaKappaTST.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaAccRedTST.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", accredAv[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaAccRedTST.txt", cadena); } /*Print the results*/ cadena = "Datasets\t\t"; for (i = 0; i < algoritmos.size(); i++) { cadena += algoritmos.elementAt(i) + "\t\t"; } cadena += "\n"; Fichero.escribeFichero("tablaKappaRedTST.txt", cadena); for (i = 0; i < datasets.size(); i++) { cadena = datasets.elementAt(i) + "\t\t"; for (j = 0; j < algoritmos.size(); j++) { cadena += String.format("%6.4f", kapredAv[i][j]) + "\t"; } cadena += "\n"; Fichero.AnadirtoFichero("tablaKappaRedTST.txt", cadena); } System.out.println("FIN"); }
public void run() { int i, j; double ec, el, ec_tst, el_tst; /* We read the configutate file and we initialize the structures and variables */ leer_conf(); if (tabla.salir == false) { Gen = 0; /* Generation of the initial population */ alg_gen.Initialize(); /* Evaluation of the initial population */ alg_gen.Evaluate(); Gen++; /* Main of the genetic algorithm */ do { /* Interchange of the new and old population */ alg_gen.Intercambio(); /* Selection by means of Baker */ alg_gen.Select(); /* Crossover */ if (tipoc > 0) alg_gen.Max_Min_Crossover(); else alg_gen.Cruce_Multipunto(); /* Mutation */ alg_gen.Mutacion(); /* Elitist selection */ alg_gen.Elitist(); /* Evaluation of the current population */ alg_gen.Evaluate(); /* we increment the counter */ Gen++; } while (Gen <= n_generaciones); /* we calcule the MSEs */ fun_adap.Decodifica(alg_gen.solucion()); fun_adap.Error_tra(); ec = fun_adap.EC; el = fun_adap.EL; tabla_tst = new MiDataset(fich_datos_tst, false); fun_adap.Error_tst(tabla_tst); ec_tst = fun_adap.EC; el_tst = fun_adap.EL; fun_adap.Cubrimientos_Base(); /* we write the RB */ cadenaReglas = base_reglas.BRtoString(); cadenaReglas += "\nMSEtra: " + ec + " MSEtst: " + ec_tst + "\nAverage covering degree: " + fun_adap.medcb + " Minimum covering degree: " + fun_adap.mincb; Fichero.escribeFichero(fichero_reglas, cadenaReglas); /* we write the obligatory output files*/ String salida_tra = tabla.getCabecera(); salida_tra += fun_adap.getSalidaObli(tabla); Fichero.escribeFichero(fich_tra_obli, salida_tra); String salida_tst = tabla_tst.getCabecera(); salida_tst += fun_adap.getSalidaObli(tabla_tst); Fichero.escribeFichero(fich_tst_obli, salida_tst); /* we write the MSEs in specific files */ Fichero.AnadirtoFichero(ruta_salida + "PcomunR.txt", "" + base_reglas.n_reglas + "\n"); Fichero.AnadirtoFichero(ruta_salida + "PcomunTRA.txt", "" + ec + "\n"); Fichero.AnadirtoFichero(ruta_salida + "PcomunTST.txt", "" + ec_tst + "\n"); } }
/** * It stores the rule base in a given file * * @param filename Name for the rulebase file */ public void saveFile(String filename) { String stringOut = new String(""); stringOut = printString(); Fichero.escribeFichero(filename, stringOut); }
public void run() { int i, j, k, etiqueta, pos; double pert_act, grado_act, ec, el, ec_tst, el_tst; /* We read the configutate file and we initialize the structures and variables */ leer_conf(); if (tabla.salir == false) { /* we generate the semantics of the linguistic variables */ base_datos.Semantica(); /* we store the DB in the report file */ informe = "\n\nInitial Data Base: \n\n"; for (i = 0; i < tabla.n_variables; i++) { informe += " Variable " + (i + 1) + ":\n"; for (j = 0; j < base_datos.n_etiquetas[i]; j++) { informe += " Label " + (j + 1) + ": (" + base_datos.BaseDatos[i][j].x0 + "," + base_datos.BaseDatos[i][j].x1 + "," + base_datos.BaseDatos[i][j].x3 + ")\n"; } informe += "\n"; } informe += "\n"; Fichero.escribeFichero(fichero_inf, informe); /* Inicialization of the counter of uncovered examples */ base_reglas.n_reglas = 0; /* Iterative Rule Learning */ for (i = 0; i < tabla.long_tabla; i++) { /* Generation of the best rule for the current example */ for (j = 0; j < tabla.n_variables; j++) { /* Determination of the best label for each variable */ grado_pertenencia[j] = 0.0; etiqueta = 0; for (k = 0; k < base_datos.n_etiquetas[j]; k++) { pert_act = base_reglas.Fuzzifica(tabla.datos[i].ejemplo[j], base_datos.BaseDatos[j][k]); if (pert_act > grado_pertenencia[j]) { grado_pertenencia[j] = pert_act; etiqueta = k; } } Regla_act[j] = etiqueta; } /* we calculate the covered degree */ grado_act = 1.0; for (j = 0; j < tabla.n_variables; j++) { grado_act *= grado_pertenencia[j]; } /* we insert the new rule in the RB */ pos = Pertenece(Regla_act, Conjunto_Reglas, base_reglas.n_reglas); /* if the rule didn't exist */ if (pos == -1) { for (j = 0; j < tabla.n_variables; j++) { Conjunto_Reglas[base_reglas.n_reglas].Regla[j] = Regla_act[j]; } Conjunto_Reglas[base_reglas.n_reglas].grado = grado_act; base_reglas.n_reglas++; } /* if a rule with equal antecedet exist in the RB and the covered degree of the current rule is better, the consequent is replaced */ else if (Conjunto_Reglas[pos].grado < grado_act) { Conjunto_Reglas[pos].grado = grado_act; if (Conjunto_Reglas[pos].Regla[tabla.n_var_estado] != Regla_act[tabla.n_var_estado]) { Conjunto_Reglas[pos].Regla[tabla.n_var_estado] = Regla_act[tabla.n_var_estado]; } } } /* we decode the generated rules */ base_reglas.decodifica(Conjunto_Reglas); /* we calcule the MSEs */ fun_adap.Error_tra(); ec = fun_adap.EC; el = fun_adap.EL; fun_adap.Error_tst(); ec_tst = fun_adap.EC; el_tst = fun_adap.EL; /* we write the RB */ cadenaReglas = base_reglas.BRtoString(peso); cadenaReglas += "\nECMtra: " + ec + " ECMtst: " + ec_tst + "\n"; Fichero.escribeFichero(fichero_reglas, cadenaReglas); /* we write the obligatory output files*/ String salida_tra = tabla.getCabecera(); salida_tra += fun_adap.getSalidaObli(tabla); Fichero.escribeFichero(fich_tra_obli, salida_tra); String salida_tst = tabla_tst.getCabecera(); salida_tst += fun_adap.getSalidaObli(tabla_tst); Fichero.escribeFichero(fich_tst_obli, salida_tst); /* we write the MSEs in specific files */ Fichero.AnadirtoFichero(ruta_salida + "WMcomunR.txt", "" + base_reglas.n_reglas + "\n"); Fichero.AnadirtoFichero(ruta_salida + "WMcomunTRA.txt", "" + ec + "\n"); Fichero.AnadirtoFichero(ruta_salida + "WMcomunTST.txt", "" + ec_tst + "\n"); } }