/** Function which selects the elements of the population */ public void Select() { int i, j; for (i = 0; i < Popsize; i++) for (j = i + 1; j < POPSIZE; j++) if (Better(Poblacion[j].perf(), Poblacion[i].perf())) INTERCAMBIAR(i, j); if (Poblacion[0].perf() < BEST_CROM.perf()) { for (j = 0; j < Genes; j++) BEST_CROM.set_gene(j, Poblacion[0].gene(j)); for (j = 0; j < GenesA; j++) BEST_CROM.set_geneA(j, Poblacion[0].geneA(j)); for (j = 0; j < n_reglas_total; j++) BEST_CROM.set_geneR(j, Poblacion[0].geneR(j)); BEST_CROM.set_perf(Poblacion[0].perf()); BEST_CROM.set_entrado(1); } }
/** * It initialize the population * * @param tam1 It contains the size of the table of training * @param v1 It contains the training input values * @param s1 It contains the training output values * @param tam2 It contains the size of the table of test * @param v2 It contains the test input values * @param s2 It contains the test output values * @param n_variables It contains the number of variables * @param reglas It contains the number of rules * @param var It contains the number of state variables * @param sal It contains the exit value * @param v It contains the values of data base * @param semilla It contains the value of the seed */ public void Initialize( int tam1, double[][] v1, double[] s1, int tam2, double[][] v2, double[] s2, int n_variables, int reglas, int var, double sal, double[] v, long semilla) { /* INICIALIZAR VARIABLES */ int i, j; Genes = 0; contador = contador2 = 0; Reiniciado = 0; Randomize.setSeed(semilla); E = new Ecm(tam1, v1, s1, tam2, v2, s2, n_variables, reglas, var, sal, v); Poblacion = new Cromosoma[2 * Popsize]; Trials = 0; for (i = 0; i < n_variables; i++) { Genes += E.base().getN_etiquetas(i); } Ajuste = 1; Gene = new Gen[Genes]; GenesA = Genes - E.base().getN_etiquetas(E.base().getN_var_estado()); THRESHOLD = (double) ((Genes + GenesA) * BITS_GEN / 4.0); reduccionIni = THRESHOLD * 0.001; n_reglas_total = reglas; Gen aux = new Gen(); aux.set_min(0.0); aux.set_max(1.0); for (i = 0; i < Genes; i++) { Gene[i] = aux; } for (i = 0; i < 2 * Popsize; i++) { Poblacion[i] = new Cromosoma(Genes, GenesA, n_reglas_total); } sample = new int[Popsize]; BEST_CROM = new Cromosoma(Genes, Genes, n_reglas_total); for (j = 0; j < Genes; j++) { BEST_CROM.set_gene(j, Gene[j].min() + (Gene[j].max() - Gene[j].min()) / 2.); Poblacion[0].set_gene(j, BEST_CROM.gene(j)); } for (j = 0; j < GenesA; j++) { BEST_CROM.set_geneA(j, Gene[j].min() + (Gene[j].max() - Gene[j].min()) / 2.); Poblacion[0].set_geneA(j, BEST_CROM.gene(j)); } for (j = 0; j < n_reglas_total; j++) { BEST_CROM.set_geneR(j, (char) 1); Poblacion[0].set_geneR(j, (char) 1); } for (i = 1; i < Popsize; i++) { for (j = 0; j < Genes; j++) Poblacion[i].set_gene( j, Gene[j].min() + (Gene[j].max() - Gene[j].min()) * Randomize.Rand()); for (j = 0; j < GenesA; j++) Poblacion[i].set_geneA( j, Gene[j].min() + (Gene[j].max() - Gene[j].min()) * Randomize.Rand()); for (j = 0; j < n_reglas_total; j++) Poblacion[i].set_geneR(j, (char) 1); } F = new Funciones(); }