Пример #1
0
 /**
  * Function which evaluates the population
  *
  * @param inicio it contains the beginning of the evaluation
  * @param fin it contains the end of the evaluation
  */
 public void Evaluate(int inicio, int fin) {
   int i;
   double performance = 0.;
   for (i = inicio; i < fin; i++) {
     Poblacion[i].set_perf(
         E.eval_EC(
             Poblacion[i].Gene(),
             Poblacion[i].GeneA(),
             Poblacion[i].GeneR(),
             n_reglas_total)); // eval(Poblacion.elementAt(i).Gene);
     performance = Poblacion[i].perf();
     Trials++;
     if (Trials == 1) this.Best = this.Worst = performance;
     if (Better(performance, Best)) this.Best = performance;
     if (Better(Worst, performance)) this.Worst = performance;
   }
 }
Пример #2
0
  /**
   * 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();
  }