acerbilab / pybads

PyBADS: Bayesian Adaptive Direct Search optimization algorithm for model fitting in Python
https://acerbilab.github.io/pybads/
BSD 3-Clause "New" or "Revised" License
70 stars 2 forks source link

Optimizer doesn't work with a single parameter #39

Closed sakimarquis closed 1 year ago

sakimarquis commented 1 year ago

Here is the code snippet that reproduces the issue:

    def foo(x):
        return x[0]**2

    x0 = np.array([1])
    lower_bounds = np.array([-10])
    upper_bounds = np.array([10])
    plausible_lower_bounds = np.array([-5])
    plausible_upper_bounds = np.array([5])
    bads = BADS(foo, x0, lower_bounds, upper_bounds, plausible_lower_bounds, plausible_upper_bounds)
Traceback (most recent call last):
  File "D:\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3505, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-41-0b496bbed19e>", line 9, in <module>
    bads = BADS(foo, x0, lower_bounds, upper_bounds, plausible_lower_bounds, plausible_upper_bounds)
  File "D:\Miniconda3\lib\site-packages\pybads\bads\bads.py", line 245, in __init__
    self.optim_state = self._init_optim_state_()
  File "D:\Miniconda3\lib\site-packages\pybads\bads\bads.py", line 602, in _init_optim_state_
    self.var_transf = VariableTransformer(
  File "D:\Miniconda3\lib\site-packages\pybads\variable_transformer\variables_transformer.py", line 117, in __init__
    ) = self.__create_hypercube_trans__()
  File "D:\Miniconda3\lib\site-packages\pybads\variable_transformer\variables_transformer.py", line 164, in __create_hypercube_trans__
    and (self.pub[:, i] / self.plb[:, i] >= 10).item()
ValueError: can only convert an array of size 1 to a Python scalar
lacerbi commented 1 year ago

Thanks for posting this, we will look into it.

GurjeetSinghSangra commented 1 year ago

Hello,

Thank you a lot for posting this issue. I would like to share with you that we released a new patch version of PyBADS, v1.0.2. It includes the fix to the single parameter optimization. You can update your environment or reinstall the library by following pypi or conda instructions, e.g. pip install --upgrade pybads.