Пример #1
0
  /**
   * Performs a roulette selection process
   *
   * @return Individual selected
   */
  public int rouletteSelection() {

    int selected;
    double uniform;
    double sum[];

    if (fitness[0] == -1.0) {
      return Randomize.RandintClosed(0, size - 1);
    }

    sum = new double[size];

    sum[0] = fitness[0];

    for (int i = 1; i < size; i++) {
      sum[i] = sum[i - 1] + fitness[i];
    }

    uniform = Randomize.Randdouble(0.0, sum[size - 1]);
    selected = 0;

    while (uniform > sum[selected]) {
      selected++;
    }

    // selected is the method. We must return its ID

    return getKey(selected);
  }
Пример #2
0
  /**
   * PMX cross operator
   *
   * @param poblacion Population of chromosomes
   * @param newPob New population
   * @param sel1 First parent
   * @param sel2 Second parent
   */
  public void crucePMX(Cromosoma poblacion[], Cromosoma newPob[], int sel1, int sel2) {

    int e1, e2;
    int limSup, limInf;
    int i;
    boolean temp[];

    temp = new boolean[datosTrain.length];
    e1 = Randomize.Randint(0, datosTrain.length - 1);
    e2 = Randomize.Randint(0, datosTrain.length - 1);
    if (e1 > e2) {
      limSup = e1;
      limInf = e2;
    } else {
      limSup = e2;
      limInf = e1;
    }

    for (i = 0; i < datosTrain.length; i++) {
      if (i < limInf || i > limSup) temp[i] = poblacion[sel1].getGen(i);
      else temp[i] = poblacion[sel2].getGen(i);
    }
    newPob[0] = new Cromosoma(temp);

    for (i = 0; i < datosTrain.length; i++) {
      if (i < limInf || i > limSup) temp[i] = poblacion[sel2].getGen(i);
      else temp[i] = poblacion[sel1].getGen(i);
    }
    newPob[1] = new Cromosoma(temp);
  } // end-method
Пример #3
0
  /* Multipoint Crossover */
  void Cruce_Multipunto() {
    int mom, dad, xpoint1, xpoint2, i, j;
    char temp;

    for (mom = 0; mom < last; mom += 2) {
      dad = mom + 1;

      /* we generate the 2 crossing points */
      xpoint1 = Randomize.RandintClosed(0, n_genes - 1);

      if (xpoint1 != n_genes - 1) {
        xpoint2 = Randomize.RandintClosed(xpoint1 + 1, n_genes - 1);
      } else {
        xpoint2 = n_genes - 1;
      }

      /* we cross the individuals between xpoint1 and xpoint2 */
      for (i = xpoint1; i <= xpoint2; i++) {
        temp = New[mom].GeneSel[i];
        New[mom].GeneSel[i] = New[dad].GeneSel[i];
        New[dad].GeneSel[i] = temp;
      }

      New[mom].n_e = 1;
      New[dad].n_e = 1;
    }
  }
Пример #4
0
  /** Inicialization of the population */
  public void Initialize() {
    int i, j;

    last = (int) ((prob_cruce * long_poblacion) - 0.5);

    Trials = 0;

    if (prob_mutacion < 1.0) {
      Mu_next = (int) (Math.log(Randomize.Rand()) / Math.log(1.0 - prob_mutacion));
      Mu_next++;
    } else {
      Mu_next = 1;
    }

    for (j = 0; j < n_genes; j++) {
      New[0].GeneSel[j] = '1';
    }
    New[0].n_e = 1;

    for (i = 1; i < long_poblacion; i++) {
      for (j = 0; j < n_genes; j++) {
        if (Randomize.RandintClosed(0, 1) == 0) {
          New[i].GeneSel[j] = '0';
        } else {
          New[i].GeneSel[j] = '1';
        }
      }

      New[i].n_e = 1;
    }
  }
Пример #5
0
  /** Applies a tournament selection, with tournament size of 2 */
  public void tournament_selection() {
    int i, j, k, mejor_torneo;

    int tam_torneo = 2;
    int Torneo[] = new int[tam_torneo];
    boolean repetido;
    RuleSet sample[] = new RuleSet[long_poblacion];

    for (i = 0; i < long_poblacion; i++) {

      Torneo[0] = Randomize.Randint(0, long_poblacion);
      mejor_torneo = Torneo[0];

      for (j = 1; j < tam_torneo; j++) {
        do {
          Torneo[j] = Randomize.Randint(0, long_poblacion);
          repetido = false;
          k = 0;
          while ((k < j) && (!repetido)) {
            if (Torneo[j] == Torneo[k]) repetido = true;
            else k++;
          }
        } while (repetido);

        if (poblacion[Torneo[j]].fitness > poblacion[mejor_torneo].fitness)
          mejor_torneo = Torneo[j];
      }

      sample[i] = new RuleSet(poblacion[mejor_torneo]);
    }
    previousPob = poblacion;
    poblacion = sample;
  }
Пример #6
0
 /**
  * Parameter constructor
  *
  * @param attribute variable position
  * @param train full training set
  */
 public Selector(int attribute, myDataset train) {
   this.train = train;
   this.attribute = attribute;
   adjuntaNombres(train.names());
   if (train.getTipo(attribute) == train.NOMINAL) {
     this.operator = EQUAL;
     int totalNominales = train.totalNominals(attribute);
     int nominalesEscogidos = Randomize.RandintClosed(1, totalNominales);
     nominalValues = new String[nominalesEscogidos];
     values = new double[nominalesEscogidos];
     int[] noSeleccionados = new int[totalNominales];
     for (int i = 0; i < totalNominales; i++) {
       noSeleccionados[i] = i;
     }
     for (int i = 0; i < nominalValues.length; i++) {
       int seleccion = Randomize.RandintClosed(0, totalNominales - 1);
       values[i] = 1.0 * noSeleccionados[seleccion];
       nominalValues[i] = train.nominalValue(attribute, values[i]);
       noSeleccionados[seleccion] = noSeleccionados[totalNominales - 1];
       totalNominales--;
     }
   } else {
     nominalValues = new String[1];
     values = new double[1];
     this.operator = Randomize.RandintClosed(this.LESS_EQUAL, this.GREATER);
     int ejemplo = Randomize.RandintClosed(0, train.size() - 1);
     this.value = train.getExample(ejemplo)[attribute];
   }
 }
Пример #7
0
  /**
   * Function that determines the cromosomes who have to be crossed and the other ones who have to
   * be removed It returns the number of remaining cromosomes in the poblation
   */
  private int recombinar(Chromosome C[], int d, int nNeg, int nPos, boolean majSelection) {

    int i, j;
    int distHamming;
    int tamC = 0;
    int n;

    if (majSelection) n = nNeg;
    else n = nNeg + nPos;

    for (i = 0; i < C.length / 2; i++) {
      distHamming = 0;
      for (j = 0; j < n; j++) if (C[i * 2].getGen(j) != C[i * 2 + 1].getGen(j)) distHamming++;
      if ((distHamming / 2) > d) {
        for (j = 0; j < n; j++) {
          if ((C[i * 2].getGen(j) != C[i * 2 + 1].getGen(j)) && Randomize.Rand() < 0.5) {
            if (C[i * 2].getGen(j)) C[i * 2].setGen(j, false);
            else if (Randomize.Rand() < prob0to1Rec) C[i * 2].setGen(j, true);
            if (C[i * 2 + 1].getGen(j)) C[i * 2 + 1].setGen(j, false);
            else if (Randomize.Rand() < prob0to1Rec) C[i * 2 + 1].setGen(j, true);
          }
        }
        tamC += 2;
      } else {
        C[i * 2].borrar();
        C[i * 2 + 1].borrar();
      }
    }

    return tamC;
  }
Пример #8
0
  /* Selection based on the Baker's Estocastic Universal Sampling */
  void Select() {
    double expected, factor, perf, ptr, sum, rank_max, rank_min;
    int i, j, k, best, temp;

    rank_min = 0.75;

    /* we assign the ranking to each element:
       The best: ranking = long_poblacion-1
    The worse: ranking = 0 */
    for (i = 0; i < long_poblacion; i++) Old[i].n_e = 0;

    /* we look for the best ordered non element */
    for (i = 0; i < long_poblacion - 1; i++) {
      best = -1;
      perf = 0.0;
      for (j = 0; j < long_poblacion; j++) {
        if ((Old[j].n_e == 0) && (best == -1 || Old[j].Perf < perf)) {
          perf = Old[j].Perf;
          best = j;
        }
      }

      /* we assign the ranking */
      Old[best].n_e = long_poblacion - 1 - i;
    }

    /* we normalize the ranking */
    rank_max = 2.0 - rank_min;
    factor = (rank_max - rank_min) / (double) (long_poblacion - 1);

    /* we assign the number of replicas of each chormosome according to the select probability */
    k = 0;
    ptr = Randomize.Rand();
    for (sum = i = 0; i < long_poblacion; i++) {
      expected = rank_min + Old[i].n_e * factor;
      for (sum += expected; sum >= ptr; ptr++) sample[k++] = i;
    }

    /* we complete the population if necessary */
    if (k != long_poblacion) {
      for (; k < long_poblacion; k++) sample[k] = Randomize.RandintClosed(0, long_poblacion - 1);
    }

    /* we shuffle the selected chromosomes */
    for (i = 0; i < long_poblacion; i++) {
      j = Randomize.RandintClosed(i, long_poblacion - 1);
      temp = sample[j];
      sample[j] = sample[i];
      sample[i] = temp;
    }

    /* we create the new population */
    for (i = 0; i < long_poblacion; i++) {
      k = sample[i];
      for (j = 0; j < n_genes; j++) New[i].Gene[j] = Old[k].Gene[j];

      New[i].Perf = Old[k].Perf;
      New[i].n_e = 0;
    }
  }
Пример #9
0
  private void interpola(
      double ra[],
      double rb[],
      int na[],
      int nb[],
      boolean ma[],
      boolean mb[],
      double resS[],
      double resR[],
      int resN[],
      boolean resM[]) {

    int i;
    double diff;
    double gap;
    int suerte;

    for (i = 0; i < ra.length; i++) {
      if (ma[i] == true && mb[i] == true) {
        resM[i] = true;
        resS[i] = 0;
      } else {
        resM[i] = false;
        if (entradas[i].getType() == Attribute.REAL) {
          diff = rb[i] - ra[i];
          gap = Randomize.Rand();
          resR[i] = ra[i] + gap * diff;
          resS[i] =
              (ra[i] + entradas[i].getMinAttribute())
                  / (entradas[i].getMaxAttribute() - entradas[i].getMinAttribute());
        } else if (entradas[i].getType() == Attribute.INTEGER) {
          diff = rb[i] - ra[i];
          gap = Randomize.Rand();
          resR[i] = Math.round(ra[i] + gap * diff);
          resS[i] =
              (ra[i] + entradas[i].getMinAttribute())
                  / (entradas[i].getMaxAttribute() - entradas[i].getMinAttribute());
        } else {
          suerte = Randomize.Randint(0, 2);
          if (suerte == 0) {
            resN[i] = na[i];
          } else {
            resN[i] = nb[i];
          }
          resS[i] = (double) resN[i] / (double) (entradas[i].getNominalValuesList().size() - 1);
        }
      }
    }
  }
Пример #10
0
 private void selection() {
   hijos.clear();
   int aleatorio1, aleatorio2, i, inicio;
   inicio = 0;
   for (i = inicio;
       i < cromosomas.size();
       i++) { // Generamos la otra mitad por los operadores geneticos, Cojo numIndividuos nuevos
              // individuos...
     aleatorio1 = Randomize.RandintClosed(0, cromosomas.size() - 1); // Elijo uno aleatoriamente
     do {
       aleatorio2 = Randomize.RandintClosed(0, cromosomas.size() - 1); // Elijo otro aleatoriamente
     } while (aleatorio1 == aleatorio2); // pero que no coincida con el anterior
     torneo(i, aleatorio1, aleatorio2); // Inserto en la posicion 'i' el mejor de los 2
   }
 }
Пример #11
0
  /**
   * It reads the data from the input files and parse all the parameters from the parameters array.
   *
   * @param parameters parseParameters It contains the input files, output files and parameters
   */
  public Alcalaetal(parseParameters parameters) {

    this.rulesFilename = parameters.getAssociationRulesFile();
    this.adjustedFuzzyAttributesFilename = parameters.getOutputFile(0);
    this.valuesFilename = parameters.getOutputFile(1);
    this.uniformFuzzyAttributesFilename = parameters.getOutputFile(2);
    this.geneticLearningLogFilename = parameters.getOutputFile(3);

    try {
      System.out.println("\nReading the transaction set: " + parameters.getTransactionsInputFile());

      this.trans = new myDataset();
      this.trans.readDataSet(parameters.getTransactionsInputFile());
    } catch (IOException e) {
      System.err.println("There was a problem while reading the input transaction set: " + e);
      somethingWrong = true;
    }

    long seed = Long.parseLong(parameters.getParameter(0));

    this.nEvaluations = Integer.parseInt(parameters.getParameter(1));
    this.popSize = Integer.parseInt(parameters.getParameter(2));
    this.nBitsGene = Integer.parseInt(parameters.getParameter(3));
    this.phi = Double.parseDouble(parameters.getParameter(4));
    this.d = Double.parseDouble(parameters.getParameter(5));
    this.nFuzzyRegionsForNumericAttributes = Integer.parseInt(parameters.getParameter(6));
    this.useMaxForOneFrequentItemsets = Boolean.parseBoolean(parameters.getParameter(7));
    this.minSupport = Double.parseDouble(parameters.getParameter(8));
    this.minConfidence = Double.parseDouble(parameters.getParameter(9));

    Randomize.setSeed(seed);
  }
Пример #12
0
  /** Applies a roulette wheel selection */
  public void selection() {
    RuleSet temp[];
    double probability[] = new double[long_poblacion];
    double total;
    double prob;
    int sel;

    temp = new RuleSet[long_poblacion];
    // sort the poblation in order of fitness
    Arrays.sort(poblacion, Collections.reverseOrder());

    probability[0] = poblacion[0].getFitness();
    for (int i = 1; i < long_poblacion; i++) {
      probability[i] = probability[i - 1] + poblacion[i].getFitness();
    }
    total = probability[long_poblacion - 1];
    for (int i = 0; i < long_poblacion; i++) {
      probability[i] /= total;
    }

    for (int i = 0; i < long_poblacion; i++) {
      prob = Randomize.Rand();
      sel = -1;
      for (int j = 0; j < long_poblacion && sel == -1; j++) {
        if (probability[j] > prob) sel = j;
      }
      temp[i] = new RuleSet(poblacion[sel]);
    }

    previousPob = poblacion;
    poblacion = temp;
  }
Пример #13
0
  /** Applies mutation in the new poblation */
  public void mutate() {
    int posiciones, i, j;
    double m;

    posiciones = n_genes * long_poblacion;

    if (prob_mutacion > 0)
      while (Mu_next < posiciones) {
        /* Se determina el cromosoma y el gen que corresponden a la posicion que
        se va a mutar */
        i = Mu_next / n_genes;
        j = Mu_next % n_genes;

        /* Se efectua la mutacion sobre ese gen */
        poblacion[i].mutate(j);

        /* Se marca el cromosoma mutado para su posterior evaluacion */
        poblacion[i].setEvaluated(false);

        /* Se calcula la siguiente posicion a mutar */
        if (prob_mutacion < 1) {
          m = Randomize.Rand();
          Mu_next += Math.ceil(Math.log(m) / Math.log(1.0 - prob_mutacion));
        } else Mu_next += 1;
      }

    Mu_next -= posiciones;
  }
Пример #14
0
  /**
   * It calculates the cross HUX
   *
   * @param Padre1 it is a father to cross
   * @param Padre2 it is the other father to do the cross
   * @param Hijo1 the son obtained
   * @param Hijo2 the other obtained
   */
  void HUX(char[] Padre1, char[] Padre2, char[] Hijo1, char[] Hijo2) {

    int j, distintos, pos, intercambios;
    char px, py, temp;

    if (flag3 == 1) {
      posiciones = new int[n_reglas_total];
      flag3 = 0;
    }

    distintos = 0;
    for (j = 0; j < n_reglas_total; j++) {
      px = Padre1[j];
      py = Padre2[j];
      Hijo1[j] = px;
      Hijo2[j] = py;
      if (px != py) {
        posiciones[distintos] = j;
        distintos++;
      }
    }
    intercambios = distintos / 2;
    if (distintos > 0 && intercambios == 0) intercambios = 1;
    for (j = 0; j < intercambios; j++) {
      pos = Randomize.Randint(0, --distintos);
      temp = Hijo1[posiciones[pos]];
      Hijo1[posiciones[pos]] = Hijo2[posiciones[pos]];
      Hijo2[posiciones[pos]] = temp;
      posiciones[pos] = posiciones[distintos];
    }
  }
Пример #15
0
  public void crossover() {

    int j, countCross = 0;

    Sampling samp = new Sampling(popSize);
    int p1 = -1;

    for (j = 0; j < popSize; j++) {

      if (Randomize.Rand() < Parameters.crossoverProbability) {

        if (p1 == -1) {
          p1 = samp.getSample();
        } else {
          int p2 = samp.getSample();
          crossTwoParents(p1, p2, countCross, countCross + 1);
          countCross += 2;
          p1 = -1;
        }
      } else {
        crossOneParent(samp.getSample(), countCross++);
      }
    }

    if (p1 != -1) {
      crossOneParent(p1, countCross++);
    }
  }
Пример #16
0
  /* Operador de Mutacion Uniforme */
  void Mutacion_Uniforme() {
    int posiciones, i, j;
    double m;

    posiciones = n_genes * long_poblacion;

    if (prob_mutacion > 0) {
      while (Mu_next < posiciones) {
        /* we determinate the chromosome and the gene */
        i = Mu_next / n_genes;
        j = Mu_next % n_genes;

        /* we mutate the gene */
        if (New[i].Gene[j] == '0') New[i].Gene[j] = '1';
        else New[i].Gene[j] = '0';

        New[i].n_e = 1;

        /* we calculate the next position */
        if (prob_mutacion < 1) {
          m = Randomize.Rand();
          Mu_next += (int) (Math.log(m) / Math.log(1.0 - prob_mutacion)) + 1;
        } else Mu_next += 1;
      }
    }

    Mu_next -= posiciones;
  }
Пример #17
0
  /**
   * KMeans constructor: the cluster centroids are obtained for the given dataset. Firstly, the
   * cluster's centroids are randomly chosen. Then the centroids are updated as the mean vlaue of
   * nearest examples in the dataset. The updating is carried out until no changes in the centroids
   * is achieved.
   *
   * @param X The dataset to be clusterized
   * @param nclusters The desired number of clusters
   * @param vrand The Randomize object to be used
   */
  public KMeans(double[][] X, int nclusters, Randomize vrand) {

    rand = vrand;
    train = X;
    clusters = nclusters;
    cclusters = new double[nclusters][X[0].length];

    for (int i = 0; i < nclusters; i++) {
      int pos = (int) (rand.Rand() * X.length);
      for (int j = 0; j < cclusters[i].length; j++) cclusters[i][j] = X[pos][j];
    }

    int[] C = new int[X.length];
    int[] C_old = new int[X.length];
    for (int i = 0; i < X.length; i++) {
      C_old[i] = nearestCentroid(X[i]);
    }
    centroidsUpdating(C_old);

    int cambios = 0, iteracion = 0;
    do {

      iteracion++;
      System.out.println("Iter=" + iteracion + " changes=" + cambios);
      cambios = 0;
      for (int i = 0; i < X.length; i++) {
        C[i] = nearestCentroid(X[i]);
        if (C[i] != C_old[i]) cambios++;
        C_old[i] = C[i];
      }
      centroidsUpdating(C);
    } while (cambios > 0);
  }
Пример #18
0
 /**
  * It performs a one point crossover in the new poblation, using adjacent chromosomes as parents
  */
 public void crossOver() {
   int parentspreserved = (int) (long_poblacion * survivorsPercent);
   for (int i = 0; i < long_poblacion; i = i + 2) {
     if (Randomize.Rand() < this.crossoverRate && i + 1 < long_poblacion)
       onePointCrossover(i, i + 1);
   }
 }
Пример #19
0
  /**
   * It selects one parent to participate in the evolutionary process (by binary tournament
   * selection).
   *
   * @param int The position in the population for the selected parent
   */
  int Selection() {
    int result;
    int[] indiv = new int[2];

    indiv[0] = Randomize.RandintClosed(0, ((tamPoblacion / 2) - 2));
    do {
      indiv[1] = Randomize.RandintClosed(0, ((tamPoblacion / 2) - 2));
    } while (indiv[0] == indiv[1]);

    if (Poblacion2.get(indiv[0]).fitness > Poblacion2.get(indiv[1]).fitness) {
      result = indiv[0];
    } else {
      result = indiv[1];
    }

    return (result);
  }
Пример #20
0
  /**
   * Reinitializes the chromosome by using CHC diverge procedure
   *
   * @param r R factor of diverge
   * @param mejor Best chromosome found so far
   * @param prob Probability of setting a gen to 1
   */
  public void divergeCHC(double r, Cromosoma mejor, double prob) {

    int i;

    for (i = 0; i < cuerpo.length; i++) {
      if (Randomize.Rand() < r) {
        if (Randomize.Rand() < prob) {
          cuerpo[i] = true;
        } else {
          cuerpo[i] = false;
        }
      } else {
        cuerpo[i] = mejor.getGen(i);
      }
    }
    cruzado = true;
  } // end-method
Пример #21
0
 public void individualMutation() {
   int i;
   for (i = 0; i < popSize; i++) {
     if (Randomize.Rand() < Parameters.mutationProbability) {
       offspringPopulation[i].mutation();
     }
   }
 }
Пример #22
0
  /**
   * Mutation operator
   *
   * @param pMutacion1to0 Probability of change 1 to 0
   * @param pMutacion0to1 Probability of change 0 to 1
   */
  public void mutacion(double pMutacion1to0, double pMutacion0to1) {

    int i;

    for (i = 0; i < cuerpo.length; i++) {
      if (cuerpo[i]) {
        if (Randomize.Rand() < pMutacion1to0) {
          cuerpo[i] = false;
          cruzado = true;
        }
      } else {
        if (Randomize.Rand() < pMutacion0to1) {
          cuerpo[i] = true;
          cruzado = true;
        }
      }
    }
  } // end-method
Пример #23
0
  /**
   * Builder. Generates a new subpopulation from a subset of the entire training set
   *
   * @param id Identifier of the population
   * @param train Subset of training data
   * @param out Output attribute of the subset of training data
   */
  public Subpopulation(int id, double train[][], int out[]) {

    // identify it
    ID = id;

    IDs = new int[size];

    for (int i = 0; i < size; i++) {
      IDs[i] = i;
    }

    // set data
    trainData = new double[train.length][train[0].length];
    trainOutput = new int[out.length];

    for (int i = 0; i < trainData.length; i++) {

      for (int j = 0; j < trainData[0].length; j++) {
        trainData[i][j] = train[i][j];
      }
      trainOutput[i] = out[i];
    }

    // Getting the number of different classes
    nClasses = 0;
    for (int i = 0; i < trainOutput.length; i++) {
      if (trainOutput[i] > nClasses) {
        nClasses = trainOutput[i];
      }
    }
    nClasses++;

    // create population
    population = new int[size][trainData.length];

    for (int i = 0; i < size; i++) {
      for (int j = 0; j < trainData.length; j++) {
        if (Randomize.Rand() < 0.5) {
          population[i][j] = 1;
        } else {
          population[i][j] = 0;
        }
      }
    }

    fitness = new double[size];
    Arrays.fill(fitness, -1.0);

    // initialize cache of distances
    generateCache();

    // initialize structures
    ISSelection = new int[trainData.length];
    selectedClasses = new int[nClasses];
    nearestN = new int[K];
    minDist = new double[K];
  } // end-method
Пример #24
0
  public void TournamentSelection() {

    int i, j, winner, candidate;

    for (i = 0; i < popSize; i++) {
      // There can be only one
      winner = Randomize.Randint(0, popSize);

      for (j = 1; j < tournamentSize; j++) {
        candidate = Randomize.Randint(0, popSize);
        if (population[candidate].compareToIndividual(
                population[winner], Parameters.optimizationMethod)
            > 0) {
          winner = candidate;
        }
      }

      offspringPopulation[i] = cf.cloneClassifier(population[winner]);
    }
  }
Пример #25
0
 private void crossoverPoint() {
   for (int i = 0; i < selectos.length / 2; i++) {
     Individuo padre = cromosomas.get(selectos[i]);
     Individuo madre = cromosomas.get(selectos[i + 1]);
     int puntoCorte = Randomize.RandintClosed(1, padre.size() - 2);
     Individuo hijo1 = new Individuo(padre, madre, puntoCorte);
     Individuo hijo2 = new Individuo(madre, padre, puntoCorte);
     hijos.add(hijo1);
     hijos.add(hijo2);
   }
 }
Пример #26
0
  /**
   * Shuffles a vector of differences
   *
   * @param diff Vector of differences
   * @param index Final position of the vector
   */
  private void shuffleDiff(int diff[], int index) {

    int pos, tmp;

    for (int i = 0; i < index; i++) {

      pos = Randomize.Randint(0, index);
      tmp = diff[i];
      diff[i] = diff[pos];
      diff[pos] = tmp;
    }
  } // end-method
Пример #27
0
  /**
   * This public static method runs the algorithm that this class concerns with.
   *
   * @param args Array of strings to sent parameters to the main program. The path of the
   *     algorithm's parameters file must be given.
   */
  public static void main(String args[]) {

    boolean tty = false;
    ProcessConfig pc = new ProcessConfig();
    System.out.println("Reading configuration file: " + args[0]);
    if (pc.fileProcess(args[0]) < 0) return;
    int algo = pc.parAlgorithmType;
    rand = new Randomize();
    rand.setSeed(pc.parSeed);
    ClusterKMeans km = new ClusterKMeans();
    km.clustering_kmeans(tty, pc);
  }
  /**
   * Returns a vector with the discretized values.
   *
   * @param attribute
   * @param values
   * @param begin
   * @param end
   * @return vector with the discretized values
   */
  protected Vector discretizeAttribute(int attribute, int[] values, int begin, int end) {
    double quota = (end - begin + 1) / numInt;
    double dBound = 0.0;
    int i;
    int oldBound = 0;

    Vector cp = new Vector();

    for (i = 0; i < numInt - 1; i++) {
      dBound += quota;
      int iBound = (int) Math.round(dBound);
      if (iBound <= oldBound) continue;
      if (realValues[attribute][values[iBound - 1]] != realValues[attribute][values[iBound]]) {
        double cutPoint =
            (realValues[attribute][values[iBound - 1]] + realValues[attribute][values[iBound]])
                / 2.0;
        cp.addElement(new Double(cutPoint));
      } else {
        double val = realValues[attribute][values[iBound]];
        int numFW = 1;
        while (iBound + numFW <= end && realValues[attribute][values[iBound + numFW]] == val)
          numFW++;
        if (iBound + numFW > end) numFW = end - begin + 2;
        int numBW = 1;
        while (iBound - numBW > oldBound && realValues[attribute][values[iBound - numBW]] == val)
          numBW++;
        if (iBound - numBW == oldBound) numBW = end - begin + 2;

        if (numFW < numBW) {
          iBound += numFW;
        } else if (numBW < numFW) {
          iBound -= numBW;
        } else {
          if (numFW == end - begin + 2) {
            return cp;
          }
          if (Randomize.Rand() < 0.5) {
            iBound += numFW;
          } else {
            iBound -= numBW;
            iBound++;
          }
        }
        double cutPoint =
            (realValues[attribute][values[iBound - 1]] + realValues[attribute][values[iBound]])
                / 2.0;
        cp.addElement(new Double(cutPoint));
      }
      oldBound = iBound;
    }

    return cp;
  }
Пример #29
0
  /**
   * This public static method runs the algorithm that this class concerns with.
   *
   * @param args Array of strings to sent parameters to the main program. The path of the
   *     algorithm's parameters file must be given.
   */
  public static void main(String args[]) {

    boolean tty = false;
    ProcessConfig pc = new ProcessConfig();
    System.out.println("Reading configuration file: " + args[0]);
    if (pc.fileProcess(args[0]) < 0) return;
    int algo = pc.parAlgorithmType;
    rand = new Randomize();
    rand.setSeed(pc.parSeed);
    ModelFuzzyPittsBurgh pi = new ModelFuzzyPittsBurgh();
    pi.fuzzyPittsburghModelling(tty, pc);
  }
Пример #30
0
 private void elitist() {
   Collections.sort(cromosomas);
   Individuo mejor = cromosomas.get(0).clone();
   cromosomas.clear();
   cromosomas.add(mejor);
   int posicion = Randomize.RandintClosed(0, hijos.size() - 1);
   hijos.remove(posicion);
   for (int i = 0; i < hijos.size(); i++) {
     Individuo nuevo = hijos.get(i).clone();
     cromosomas.add(nuevo);
   }
 }