Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pySOT/surrogate/surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ def add_points(self, xx, fx):
:param xx: Points to add
:type xx: numpy.ndarray
:param fx: The function values of the point to add
:type fx: numpy.array or float
:type fx: array-like or scalar
"""
xx = np.atleast_2d(xx)
if isinstance(fx, float):
fx = np.array([fx])
fx = np.asarray(fx)
if fx.ndim == 0:
fx = np.expand_dims(fx, axis=0)
if fx.ndim == 1:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_surrogates.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ def test_rbf():
assert la.norm(df(np.atleast_2d(X[0, :])) - dfhx) < 1e-1


def test_add_points_accepts_integer_function_value():
rbf = RBFInterpolant(dim=2, lb=np.zeros(2), ub=np.ones(2))

rbf.add_points(np.array([0.25, 0.75]), 1)

assert rbf.fX.shape == (1, 1)
np.testing.assert_allclose(rbf.fX, np.array([[1.0]]))


def test_gp():
X = make_grid(30) # Make uniform grid with 30 x 30 points
gp = GPRegressor(dim=2, lb=np.zeros(2), ub=np.ones(2))
Expand Down