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

Modifying the number of genes in GEP code produces error #51

Open
sarmedwahab opened this issue Jan 30, 2024 · 0 comments
Open

Modifying the number of genes in GEP code produces error #51

sarmedwahab opened this issue Jan 30, 2024 · 0 comments

Comments

@sarmedwahab
Copy link

sarmedwahab commented Jan 30, 2024

I am using this code for developing an expression in my research, but I have experienced one issue, that I can't change the n_genes to value other than 2.

I havenot modified anything in the code except my data and the parameters of head size and generations.

Please have a look on it, that how can we increase number of genes in this code and what necessary modifications are required in code to make it work.

I have tried using 3 but it throws following error:


TypeError Traceback (most recent call last)
Cell In[325], line 9
6 hof = tools.HallOfFame(3) # only record the best three individuals ever found in all generations
8 # start evolution
----> 9 pop, log = gep.gep_simple(pop, toolbox, n_generations=n_gen, n_elites=1,
10 stats=stats, hall_of_fame=hof, verbose=True)

File c:\programs\python\python39\lib\site-packages\geppy\algorithms\basic.py:100, in gep_simple(population, toolbox, n_generations, n_elites, stats, hall_of_fame, verbose)
98 invalid_individuals = [ind for ind in population if not ind.fitness.valid]
99 fitnesses = toolbox.map(toolbox.evaluate, invalid_individuals)
--> 100 for ind, fit in zip(invalid_individuals, fitnesses):
101 ind.fitness.values = fit
103 # record statistics and log

Cell In[321], line 5, in evaluate_linear_scaling(individual)
2 """Evaluate the fitness of an individual with linearly scaled MSE.
3 Get a and b by minimizing (a*Yp + b - Y)"""
4 func = toolbox.compile(individual)
----> 5 Yp = np.array(list(map(func, bc, fc, ef, tf, bf, lf)))
7 # special cases: (1) individual has only a terminal
8 # (2) individual returns the same value for all test cases, like 'x - x + 10'. np.linalg.lstsq will fail in such cases.
10 if isinstance(Yp, np.ndarray):

File c:\programs\python\python39\lib\site-packages\geppy\tools\parser.py:50, in compile_..(*x)
48 else:
49 return lambda *x: tuple((f(*x) for f in fs))
---> 50 return lambda x: linker((f(*x) for f in fs))

TypeError: add expected 2 arguments, got 3

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

1 participant