josejimenezluna / pyGPGO

Bayesian optimization for Python
http://pygpgo.readthedocs.io
MIT License
241 stars 61 forks source link

Error when running #24

Closed RemiDav closed 4 years ago

RemiDav commented 5 years ago

I get the following error randomly when running with ExpectedImprovement acquisition: gpgo.run(max_iter=32, resume=True)

Error:

C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\GPGO.py:109: RuntimeWarning: invalid value encountered in sqrt
  new_std = np.sqrt(new_var + 1e-6)
C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\covfunc.py:51: RuntimeWarning: invalid value encountered in less
  return cdist(X, Xstar) < np.finfo(np.float32).eps
Traceback (most recent call last):
  File "D:\Dropbox\Dev\Python\MultiDDM\TeaLab\run_MultiDDM.py", line 243, in <module>
    gpgo.run(max_iter=explore_schedule[sched], resume=True)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\GPGO.py", line 191, in run
    self._optimizeAcq()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\GPGO.py", line 131, in _optimizeAcq
    bounds=self.parameter_range)
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 601, in minimize
    callback=callback, **options)
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\lbfgsb.py", line 335, in _minimize_lbfgsb
    f, g = func_and_grad(x)
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\lbfgsb.py", line 280, in func_and_grad
    f = fun(x, *args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\optimize.py", line 300, in function_wrapper
    return function(*(wrapper_args + args))
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\GPGO.py", line 108, in _acqWrapper
    new_mean, new_var = self.GP.predict(xnew, return_std=True)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyGPGO\surrogates\GaussianProcess.py", line 222, in predict
    v = solve(self.L, kstar.T)
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\linalg\basic.py", line 140, in solve
    b1 = atleast_1d(_asarray_validated(b, check_finite=check_finite))
  File "C:\ProgramData\Anaconda3\lib\site-packages\scipy\_lib\_util.py", line 239, in _asarray_validated
    a = toarray(a)
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\function_base.py", line 498, in asarray_chkfinite
    "array must not contain infs or NaNs")

I do not know how to reproduce the behavior since it works fine most of the time.

RemiDav commented 5 years ago

I am trying to modify the _acqWrapper function to return the maximum float value if the result of the sqrt is nan. We will see what happens.

def _acqWrapper(self, xnew):
    new_mean, new_var = self.GP.predict(xnew, return_std=True)
    new_std = np.sqrt(new_var + 1e-6)
    if np.isnan(new_std).any():
        return sys.float_info[0]
    else:
        return -self.A.eval(self.tau, new_mean, new_std)