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

res.fun[0] not subscriptable #8

Open
yusramoni opened this issue Mar 7, 2024 · 1 comment
Open

res.fun[0] not subscriptable #8

yusramoni opened this issue Mar 7, 2024 · 1 comment

Comments

@yusramoni
Copy link

Hello,

I'm trying to follow the github readme for testing out the interactive optimization feature of the GPro package.

Everything as it is mentioned in the front page:

from GPro.kernels import Matern
from GPro.posterior import Laplace
from GPro.acquisitions import UCB
from GPro.optimization import ProbitBayesianOptimization
import numpy as np

3D example. Initialization.

X = np.random.sample(size=(2, 3)) * 10
M = np.array([0, 1]).reshape(-1, 2)

GP_params = {'kernel': Matern(length_scale=1, nu=2.5),
'post_approx': Laplace(s_eval=1e-5, max_iter=1000,
eta=0.01, tol=1e-3),
'acquisition': UCB(kappa=2.576),
'alpha': 1e-5,
'random_state': None}

gpr_opt = ProbitBayesianOptimization(X, M, GP_params)

bounds = {'x0': (0, 10), 'x1': (0, 10), 'x2': (0, 10)}

console_opt = gpr_opt.interactive_optimization(bounds=bounds, n_init=100, n_solve=1)
optimal_values, suggestion, X_post, M_post, f_post = console_opt
print('optimal values: ', optimal_values)

console_opt = gpr_opt.interactive_optimization(bounds=bounds, n_init=100, n_solve=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/GPro/optimization.py", line 118, in interactive_optimization
x_optim = self.bayesopt(bounds, method, n_init, n_solve)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/GPro/preference.py", line 358, in bayesopt
if max_acq is None or -res.fun[0] >= max_acq:
~~~~~~~^^^
TypeError: 'float' object is not subscriptable

Is there something wrong in the example?

@burcia1711
Copy link

burcia1711 commented Mar 21, 2024

Hello, I have the same problem. Seems like the res.fun returned by scipy.optimize.minimize is a float representing the minimum value of the function being optimised, not an array, so we cannot index it with [0]. I don't know how it compiled in the first place.

Hope to solve this soon!

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

2 participants