Print

Print


No, the tutorial4 doesn't work, it was an error of mine, now this is the 
cleanest version I've found from the problem, it is exactly the 
tutorial4 experiment, but with this evaluate(...) method. It is maybe 
that there is parallel evaluation or something?

Alberto

-----------------------------------------------------------------------------------------------------------------------------------------------------------

    public void evaluate(final EvolutionState state,
                         final Individual ind,
                         final int threadnum)
        {
        if (!ind.evaluated)  // don't bother reevaluating
            {
            int hits = 0;
            double sum = 0.0;
            double result;
            currentY = 0.0;
            for (int ts=0; ts<100; ts++)
                {
                currentX = state.random[threadnum].nextFloat();
                ((GPIndividual)ind).trees[0].child.eval(
                    state,threadnum,input,stack,((GPIndividual)ind),this);

                if(Double.POSITIVE_INFINITY == 
input.x)state.output.fatal("Infinite at input.value\n");
                if(Double.isNaN(input.x))state.output.fatal("NaN!!!");
               
                result = Math.abs((2*currentX - 0.5*currentY) - input.x);
                if (result <= 0.01) hits++;
                sum += result;
               
                currentY = input.x;
                }

            // the fitness better be KozaFitness!
            KozaFitness f = ((KozaFitness)ind.fitness);
            f.setStandardizedFitness(state,(float)sum);
            f.hits = hits;
            ind.evaluated = true;
            }
        }