BayesianOptimization icon indicating copy to clipboard operation
BayesianOptimization copied to clipboard

Error when running maximize() on custom objective function

Open justinlent opened this issue 8 years ago • 2 comments

When running maximize() I run into this error:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-173-36ce80c380cc> in <module>()
     36 #bo_strat.explore( strat_params_explore )
     37 
---> 38 bo_strat.maximize(init_points=3, n_iter=15, kappa=2)

~/python/anaconda3510/anaconda3/envs/quant_py364/lib/python3.6/site-packages/bayes_opt/bayesian_optimization.py in maximize(self, init_points, n_iter, acq, kappa, xi, **gp_params)
    257                         bounds=self.space.bounds,
    258                         random_state=self.random_state,
--> 259                         **self._acqkw)
    260 
    261         # Print new header

~/python/anaconda3510/anaconda3/envs/quant_py364/lib/python3.6/site-packages/bayes_opt/helpers.py in acq_max(ac, gp, y_max, bounds, random_state, n_warmup, n_iter)
     61 
     62         # Store it if better than previous minimum(maximum).
---> 63         if max_acq is None or -res.fun[0] >= max_acq:
     64             x_max = res.x
     65             max_acq = -res.fun[0]

IndexError: too many indices for array

justinlent avatar May 14 '18 22:05 justinlent

I should note that the 3 init_points objective function evaluations do in fact work and the results are printed to the screen prior to the above error message

justinlent avatar May 15 '18 01:05 justinlent

Closing. i figured it out. Not all of my variables' range tuples were of the form (min, max) Some were (max, min). Once I made them all (min, max) it now works.

justinlent avatar May 15 '18 03:05 justinlent