ShuhuaGao / geppy

A framework for gene expression programming (an evolutionary algorithm) in Python
https://geppy.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
207 stars 76 forks source link

Input contains NaN, infinity or a value too large for dtype('float64') #26

Closed juanantoniobellido closed 4 years ago

juanantoniobellido commented 4 years ago

Hello.

I have the following error when running the evolution: "ValueError: Input contains NaN, infinity or a value too large for dtype('float64')." (I upload the whole text in "error.txt")

The input data do not have any NaN value, and the format is 'float64'. The problem may be in 'y_pred', because when I delete the functions pow, sqrt and log, everything works fine (using any of them, the problem arises):

_pset = gep.PrimitiveSet('Main', input_names=inputs[:-1]) pset.add_function(operator.add, 2) pset.add_function(operator.sub, 2) pset.add_function(operator.mul, 2) pset.add_function(protected_div, 2) pset.add_function(operator.pow, 2) pset.add_function(np.sqrt, 1) pset.add_function(np.log, 1) pset.add_rncterminal()

I also upload the implementation file in the .zip

Thank you very much in advance

error_and_py.zip

ShuhuaGao commented 4 years ago

This is not a rare case in genetic programming. Even if all your inputs are regular numbers, a randomly generated GP expression may still produce a very huge number. For example, supposing your input is a=100, b=0.01, pow(a / b, a) is an extremely large number.

However, I think you should pay special attention to pset.add_function(np.sqrt, 1) and pset.add_function(np.log, 1) , and you better provide a protected version for them. E.g., both np.sqrt(-1) and np.log(-1) leads to nan.