Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I add functions such as SQRT, EXP, X^2, POW, INV, LN in my code of Gene Expression Programming #28

Closed
Afifa-Tamanna opened this issue Oct 3, 2020 · 3 comments

Comments

@Afifa-Tamanna
Copy link

Hi, I cannot add the above mentioned functions functions. If I add function such as
pset.add_function(operator.pow,2)

then the following things return;
:1: RuntimeWarning: overflow encountered in double_scalars
Traceback (most recent call last):
File "G:/My Drive/Afifa Tamanna/PhD/AI/GEP/Diffn_Analysis_GEP_model/Analysis/testviscosity.py", line 198, in
pop, log = gep.gep_simple(pop, toolbox, n_generations=n_gen, n_elites=1,
File "C:\Program Files (x86)\Python38-32\lib\site-packages\geppy\algorithms\basic.py", line 100, in gep_simple
for ind, fit in zip(invalid_individuals, fitnesses):
File "<array_function internals>", line 5, in lstsq
File "C:\Users\atam0001\AppData\Roaming\Python\Python38\site-packages\numpy\linalg\linalg.py", line 2259, in lstsq
x, resids, rank, s = gufunc(a, b, rcond, signature=signature, extobj=extobj)
File "C:\Users\atam0001\AppData\Roaming\Python\Python38\site-packages\numpy\linalg\linalg.py", line 109, in _raise_linalgerror_lstsq
raise LinAlgError("SVD did not converge in Linear Least Squares")
numpy.linalg.LinAlgError: SVD did not converge in Linear Least Squares

Please assist me in solving the issue. Many Thanks.

@ShuhuaGao
Copy link
Owner

The main reason is that many functions you mentioned are some kind of dangerous. That is, it is easy to generate unreasonably large (such as pow(13, 50)) and even nan or errors (like sqrt(-1.2)).

Just like we usually define a protected version for div, you should also do that for these functions. A common way is to

  • limit the output value range, e.g., min(y, 1e6) (you should adjust the threshold accordingly)
  • if an exception or nan is generated, then output a default value like 0.0

Since evolution is always random, you cannot assume reasonable inputs or outputs for a given function. Instead, protect it.
See this example for protected_div.

@Afifa-Tamanna
Copy link
Author

Thank you for your quick response and the clarification!

@adnanhama
Copy link

Hi Shuhua;
Thank you for the useful examples you provided in your page.
in regard to the example:

(Numerical expression inference problem: numerical constant finding with ephemeral numerical constant (ENC))

There is only the single input 'x' and random numerical constants (RNC).
I just wondering if I have three inputs as the following:

x ( date from 2.3 to 6.5)
y (from 0.25 to 3)
z (from 1 to 99)

How to implement the code and do I need to change the code to be like this:

n_cases = 100
X1 = np.random.uniform(-10, 10, size=n_cases) # random numbers in range [-10, 10)
X2 = np.random.uniform(-10, 10, size=n_cases)
X3 = np.random.uniform(-10, 10, size=n_cases)

Y = f(X1,X2,X3) + np.random.normal(size=n_cases) # Gaussian noise

Also, do I need to change the random range to be (2.3 to 6.5), (0.25 to 3) and (1 to 99)

regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants