Hello,
working with the genetic programming part of JGAP I run into the
following problem:
Sometimes the fitness value stored for a program would not agree with
the value I would receive when letting the fitness function evaluate
the program again. I first thought it was a mistake in my
implementation, but then I ran the Math Problem, afterwards evaluating
all programs again (see code below), and in some cases there were
programs were the values were also different. However this never
happened if I set the mutation rate to 0. Am I doing something wrong or
is there a bug in the software?
Thanks in advance!
public static void main(String[] args)
throws Exception {
System.out.println("Formula to discover: X^4 + X^3 + X^2 - X");
// Setup the algorithm's parameters.
// ---------------------------------
GPConfiguration config = new GPConfiguration();
// We use a delta fitness evaluator because we compute a defect
rate, not
// a point score!
//
----------------------------------------------------------------------
config.setGPFitnessEvaluator(new DeltaGPFitnessEvaluator());
config.setMaxInitDepth(4);
config.setPopulationSize(1000);
config.setMaxCrossoverDepth(8);
MathProblem.FormulaFitnessFunction fit = new
MathProblem.FormulaFitnessFunction();
config.setFitnessFunction(fit);
config.setStrictProgramCreation(true);
GPProblem problem = new MathProblem(config);
// Create the genotype of the problem, i.e., define the GP commands
and
// terminals that can be used, and constrain the structure of the GP
// program.
//
--------------------------------------------------------------------
GPGenotype gp = problem.create();
//gp.setVerboseOutput(true);
// Start the computation with maximum 800 evolutions.
// if a satisfying result is found (fitness value almost 0), JGAP
stops
// earlier automatically.
//
--------------------------------------------------------------------
gp.evolve(5);
// Print the best solution so far to the console.
// ----------------------------------------------
//gp.outputSolution(gp.getAllTimeBest());
IGPProgram prog;
for (int i = 0; i < 1000; i++){
prog = gp.getGPPopulation().getGPProgram(i);
if (Math.abs(fit.computeRawFitness(prog) - prog.getFitnessValue())
> 0.01){
gp.outputSolution(prog);
System.out.println(fit.computeRawFitness(prog));
}
}
// Create a graphical tree of the best solution's program and write
it to
// a PNG file.
//
----------------------------------------------------------------------
problem.showTree(gp.getAllTimeBest(), "mathproblem_best.png");
}