guofei9987 / guofei9987/scikit-opt

Trying to optimize parameters with another genetic algo error

Open
#87 2 comments 0 reactions 0 assignees View on GitHub
question resolved
Dominant language
Python
Stars
6.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

```
import numpy as np

def schaffer(p):

x1, x2, x3 = p
x = np.square(x1) + np.square(x2)
return -(2*x1+x2+x3)

def second_level(z):
z1 =z[0]
z2=z[1]
omg = GA(func=schaffer, n_dim=3, size_pop=z1, max_iter=z2, lb=[-5, -5, -5], ub=[5,5,5], precision=1e-2)
best_x, best_y = omg.run()
result=float(best_y[0])
print(result)
return result

from sko.GA import GA

ga = GA(func=second_level, n_dim=2, size_pop=10, max_iter=20, lb=[10, 10], ub=[20, 20], precision=1e-2)
best_x, best_y= ga.run()

print('best_x:', best_x, '\n', 'best_y:', best_y)

```

gives File "mtrand.pyx", line 741, in numpy.random.mtrand.RandomState.randint
File "_bounded_integers.pyx", line 1362, in numpy.random._bounded_integers._rand_int32
TypeError: 'numpy.float64' object cannot be interpreted as an integer
no matter what i try to do.

I want to make this recursive up to level n(ga3 to optimize level 2 and ga4 to optimze ga4 and so on).
Please help

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.