"function": inspect.currentframe().f_code.co_name}
// Check params
rng = check_random_state(random_state)
space = Space(dimensions)
if x0 is None:
x0 = []
elif not isinstance(x0[0], list):
x0 = [x0]
if not isinstance(x0, list):
raise ValueError("`x0` should be a list, got %s" % type(x0))
if len(x0) > 0 and y0 is not None:
if isinstance(y0, Iterable):
y0 = list(y0)
elif isinstance(y0, numbers.Number):
y0 = [y0]
else:
raise ValueError("`y0` should be an iterable or a scalar, got %s"
% type(y0))
if len(x0) != len(y0):
raise ValueError("`x0` and `y0` should have the same length")
if not all(map(np.isscalar, y0)):
raise ValueError("`y0` elements should be scalars")
elif len(x0) > 0 and y0 is None:
y0 = []
n_calls -= len(x0)
elif len(x0) == 0 and y0 is not None:
raise ValueError("`x0`cannot be `None` when `y0` is provided")
else: // len(x0) == 0 and y0 is None
y0 = []
X = x0
y = y0
// Random search
X = X + space.rvs(n_samples=n_calls, random_state=rng)
first = True
for i in range(len(y0), len(X)):
if verbose:
print("Function evaluation no: %d started" % (i + 1))
t = time()
y_i = func(X[i])
if first:
first = False
if not np.isscalar(y_i):
raise ValueError("`func` should return a scalar")
if verbose:
print("Function evaluation no: %d ended" % (i + 1))
print("Time taken: %0.4f" % (time() - t))
print("Function value obtained: %0.4f" % y_i)
y.append(y_i)
if callback is not None:
callback(pack_optimize_result(X[: i + 1], y, space, rng, specs))
y = np.array(y)
return pack_optimize_result(X, y, space, rng, specs)