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
67 stars 2 forks source link

Can't have input vector longer than 32 #37

Closed mohammalmokdad13 closed 1 year ago

mohammalmokdad13 commented 1 year ago

My objective function can accept vectors of different sizes. Using a size of 60:

Initial starting point is invalid or not provided. Initial point randomly sampled uniformly from plausible box

Beginning optimization of a DETERMINISTIC objective function

 Iteration    f-count         f(x)           MeshScale          Method             Actions
     0           2         211.912               1                                 Uncertainty test
     0          66         109.632               1         Initial mesh            Initial points
     0          67         103.554               1       Successful poll           Train
Traceback (most recent call last):
  File "c:\Users\Mokdad\Desktop\Code\Optm.py", line 191, in <module>
    result2=bads.optimize()
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\bads\bads.py", line 1233, in optimize
    ) = self._search_step_(gp)
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\bads\bads.py", line 1580, in _search_step_
    u_search_set, z = self.search_es_hedge(
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\search\search_hedge.py", line 78, in __call__
    us, z = search(
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\search\es_search.py", line 118, in __call__
    self.sqrt_sigma = self._initialize_(u, gp, optim_state, sum_rule)
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\search\es_search.py", line 239, in _initialize_
    C = ucov(
  File "C:\Users\Mokdad\AppData\Roaming\Python\Python39\site-packages\pybads\search\es_search.py", line 313, in ucov
    weights = w.reshape(
ValueError: maximum supported dimension for an ndarray is 32, found 61

Using a length of 32 works, anything greater does not. This is due to the limitation in numpy array dimension not exceeding 32.

GurjeetSinghSangra commented 1 year ago

Hi,

First of all, thank you for reaching out and raising the issue from GitHub. Thank you also for providing the detailed information, it made the issue easy to replicate.

Indeed, we found a bug/issue due to a wrong reshape when broadcasting a matrix operation for high-dimension problems (when $D>32$). So thank you for highlighting the issue! We already fixed it, and in a few days, the new patch version of PyBADS will be available on PyPI (pip) and conda. So you will be able to upgrade your package.

As a side note - from the information you provided, it seems you are testing PyBADS on some high-dimensional optimization problems ($D > 20$). Keep in mind that PyBADS has been designed for problems where the number of input parameters is up to about D = 20 or so, so PyBADS might not be very effective in higher dimensions (see this page of the documentation, and for more practical recommendations you can also follow this FAQ for the usage of (Py)BADS algorithm (including both Matlab and Python versions).