public Individual run(
      EvolutionState state,
      SimpleProblemForm p,
      Individual x,
      int maxIter,
      ClusWrapperNonStatic objectClus)
      throws Exception { // talvez passe um individuo já com o genoma e score

    Random rand = new Random();

    // IntegerVectorIndividual mutatedX = (IntegerVectorIndividual) deepClone(x);
    IntegerVectorIndividual mutatedX = (IntegerVectorIndividual) x.clone();

    mutatedX.evaluated = false;

    double alpha = 0.95; // cálculo do alpha, percentual de diminuição da temperatura
    double t_final = 1;
    double t0 = Math.pow(alpha, maxIter + Math.log(t_final)); // estimar a temperatura inicial
    double temp_atual = t0; // tf = temperatura da vez

    int iter = 0;
    maxIter *= 2;

    while (iter < maxIter) {

      int[] genome = mutatedX.genome;
      genome = mutate(genome, 1 - iter / maxIter); // mutar o vetor

      mutatedX.setGenome(genome);

      ((ec.Problem) p).prepareToEvaluate(state, 0);
      System.out.print("Mutated Genoma: " + mutatedX.genome[0]);
      for (int i = 0; i < mutatedX.genomeLength(); i++) System.out.print("," + mutatedX.genome[i]);
      System.out.println();

      p.evaluate(state, mutatedX, 0, 0, objectClus);
      ((ec.Problem) p).finishEvaluating(state, 0);

      double newF = mutatedX.fitness.fitness();
      // adequar para minimizar o fitness
      float delta = (float) (x.fitness.fitness() - newF);

      if (delta < 0 || rand.nextDouble() < Math.exp(-(delta) / temp_atual)) {
        ((IntegerVectorIndividual) x).setGenome(mutatedX.getGenome());
        x.evaluated = false;
        ((ec.Problem) p).prepareToEvaluate(state, 0);
        p.evaluate(state, x, 0, 0, objectClus);
        ((ec.Problem) p).finishEvaluating(state, 0);
      }

      iter += 1;
      temp_atual = temp_atual * alpha;
    }
    return x;
  }
  public void evaluate(
      final EvolutionState state,
      final Individual ind,
      final int subpopulation,
      final int threadnum) {
    if (!ind.evaluated) // don't bother reevaluating
    {
      // trees[0].child is the root
      double score = fitness(((GPIndividual) ind).trees[0].child, state);

      SimpleFitness f = ((SimpleFitness) ind.fitness);
      f.setFitness(state, score, false);
      ind.evaluated = true;
    }
  }
Example #3
0
  public void evaluate(
      final EvolutionState state,
      final Individual ind,
      final int subpopulation,
      final int threadnum) {
    float accuracy = (float) 0.0;
    int i;
    double total_correct = 0;

    if (!ind.evaluated) // don't bother reevaluating
    {
      SVM_GP.setInd(ind);
      SVM_GP.setInput(input);
      SVM_GP.setProblem(this);
      SVM_GP.setStack(stack);
      SVM_GP.setState(state);
      SVM_GP.setSubpopulation(subpopulation);
      SVM_GP.setThreadnum(threadnum);

      double[] target = new double[prob.l];
      SVM_GP.svm_cross_validation(prob, param, nr_fold, target);

      /*((GPIndividual)ind).trees[0].child.eval(
      state,threadnum,input,stack,((GPIndividual)ind),this);*/

      //              result = Math.abs(expectedResult - input.x);

      for (i = 0; i < prob.l; i++) if (target[i] == prob.y[i]) ++total_correct;
      accuracy = (float) (total_correct / prob.l);
      System.out.print("Cross Validation Accuracy = " + 100.0 * accuracy + "%\n");
    }
    SimpleFitness f = ((SimpleFitness) ind.fitness);
    f.setFitness(state, accuracy, accuracy == 1.0);
    // the fitness better be KozaFitness!

    // KozaFitness f = ((KozaFitness)ind.fitness);
    // f.setStandardizedFitness(state,(float)accuracy);
    // f.hits = hits;
    ind.evaluated = true;
  }
Example #4
0
  public void evaluate(
      final EvolutionState state,
      final Individual ind,
      final int subpopulation,
      final int threadnum) {
    if (ca == null) ca = new CA(CA_WIDTH, NEIGHBORHOOD);

    // we always reevaluate
    // if (!ind.evaluated)  // don't bother reevaluating
    {
      MajorityData input = (MajorityData) (this.input);

      int sum = 0;

      // extract the rule
      ((GPIndividual) ind)
          .trees[0].child.eval(state, threadnum, input, stack, ((GPIndividual) ind), this);

      int[] rule = ca.getRule();
      for (int i = 0; i < 64; i++) rule[i] = (int) (((input.data0) >> i) & 0x1);
      for (int i = 64; i < 128; i++) rule[i] = (int) (((input.data1) >> (i - 64)) & 0x1);
      ca.setRule(rule); // for good measure though it doesn't matter

      for (int i = 0; i < NUM_TRIALS; i++) {
        // set up and run the CA
        ca.setVals(trials[i]);
        ca.step(STEPS, true);

        // extract the fitness
        if (all(ca.getVals(), majorities[i])) sum++;
      }

      SimpleFitness f = ((SimpleFitness) ind.fitness);
      f.setFitness(state, sum / (double) NUM_TRIALS, (sum == NUM_TRIALS));
      ind.evaluated = true;
    }
  }