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;
    }
  }
  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;
  }
Exemple #3
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;
    }
  }