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"); } }