  Print

```Seems that I can't go without help, these days. I'm trying to make a GP
symbolic regression problem, this is the equation:

y(n) = 2x(n) - 0.5y(n-1) + 0.4y(n-2) + 3x(n-1)2

The data comes from a communication channel, being a double for each
time step, that is represented by the x array, so x(n) is the current
value in the channel, and x(n-1) is the value in the channel 1ms ago.
Similarly, y represents the output of the function, so y(n-1) is the
value the gp tree gave 1 timestep ago and y(n-2) the output 2 timesteps ago.

Seems not very difficult, I implemented two arrays in the Problem class,
one which hold the input, and another one that hold the output, so when
evaluating the nodes would access to them. I attach at the end the code.

The problem is that I keep having problems, the tree gets evaluated to
Infinite, or to NaN, without apparent reason. In fact I check the values
that every node keeps, and they are always right, but at the end I

Has anybody made this before? there is anything that I'm missing? How
should I code it?

Alberto

P.D: Code explanation: Only 3 node types, Add, X and Y, all of them
extend GPNode, they only implement toString(), checkConstraints(...) and
eval(...). If I take out Y and run the experiment with X and Add no
errors are produced, but I've been unable to find the error in Y. I
suppose that is some pointer thing I don't see.
------------------------------------------------------------------------------------------------------------------------------------------

public class NodeData extends GPData{
public static final long serialVersionUID = 789456151;
public double value;

public GPData copyTo(final GPData gpData){
((NodeData)gpData).value = value;
return pGPData;
}
}

------------------------------------------------------------------------------------------------------------------------------------------
(In TestProblem.java)

public void evaluate(final EvolutionState state,
final Individual individual,
if (individual.evaluated) return;
y = 0d; // Defined as static Double
x = 0d; // Idem

float error = 0;
for(int i = 0; i < inputSamples.length; i++){
x = inputSamples[i];
((GPIndividual)individual).trees.child.eval(state,
if(Double.POSITIVE_INFINITY ==
error)state.output.fatal("Infinite at input.value\n");     // This is
the one which fails
if(Double.isNaN(Math.abs(error)))state.output.fatal("NaN!!!");
y = input.value;
error += Math.abs(goalSamples[i] - input.value);
}

((SimpleFitness)individual.fitness).setFitness(state,
1/(1+error), false);
individual.evaluated = true;
}

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

public void eval(final EvolutionState state,
final GPData input,
final GPIndividual individual,
final Problem problem){
double tmp;

children.eval(state, thread, input, stack, individual, problem);
tmp = ((NodeData)input).value;

children.eval(state, thread, input, stack, individual, problem);
((NodeData)input).value += tmp;

if(Double.isNaN(((NodeData)input).value))state.output.fatal("NaN
at input.value\n" + toStringForHumans());
if(Double.POSITIVE_INFINITY ==
((NodeData)input).value)state.output.fatal("Infinite at input.value\n" +
toStringForHumans()); // Never fails
}
---------------------------------------------------------------------------------------------------------------------------------------

(In X.java)
public void eval(final EvolutionState state,
final GPData input,
final GPIndividual individual,
final Problem problem){
((NodeData)input).value = ((GPTestProblem)problem).x;

if(Double.isNaN(((NodeData)input).value))state.output.fatal("NaN
at input.value\n" + toStringForHumans());
if(Double.POSITIVE_INFINITY ==
((NodeData)input).value)state.output.fatal("Infinite at input.value\n" +
toStringForHumans()); // Never fails
}

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

(In Y.java)

public void eval(final EvolutionState state,