trevorstephens / gplearn

Genetic Programming in Python, with a scikit-learn inspired API
http://gplearn.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.56k stars 274 forks source link

POWER function still overflows #292

Closed OrangeJCQ closed 1 year ago

OrangeJCQ commented 1 year ago

I am trying to customize the power function for regression problems, and the following is the code:

def _pow(x1,x2):

with np.errstate(over='ignore', invalid='ignore'):

return np.where(abs(x1.all()) < 1.0 and abs(x2.all()) < 1.0, np.power(x1,x2), 1.)

I learned from issue #221 , the POWER function is very easy to overflow. As suggested, I tried to limit both X1 and X2. While the overflow problem still exists, and overflow can only be avoided when both X1 and X2 are less than 1.However, this closure make the prediction results unsatisfactory, my code is ineffective for the easier regression problems of POWER function:

np.random.seed(42)

X = np.random.rand(500, 1)

y = np.power(X[:, 0] , 0.6)

Could you please help me with this problem?

trevorstephens commented 1 year ago

Sorry I can't really help with user custom code problems