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; }