Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pybads/bads/gaussian_process_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ def _robust_gp_fit_(
X = X[~idx_drop_out]
Y = Y[~idx_drop_out]
# Remove also user specified noise
if tmp_gp.s2 is not None and tmp_gp.s2.size > 0:
tmp_gp.s2 = tmp_gp.s2[~idx_drop_out]
if s2 is not None and s2.size > 0:
s2 = s2[~idx_drop_out]

# Retry with random sample prior
old_hyp_gp = (
Expand Down
34 changes: 33 additions & 1 deletion pybads/testing/bads/test_bads_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def run_bads(fun, x0, LB, UB, PLB, PUB, tol_errs, f_min,
if uncertainty_handling > 0:
options["uncertainty_handling"] = True
options["max_fun_evals"] = 200 if max_fun_evals is None else max_fun_evals
options["specify_target_noise"] = True
if uncertainty_handling > 1:
options["specify_target_noise"] = True
else:
Expand Down Expand Up @@ -114,6 +113,38 @@ def test_noisy_sphere_opt():
oracle_fun = lambda x: np.sum(np.atleast_2d(x)**2, axis=1) # True objective function
run_bads(fun, x0, LB, UB, PLB, PUB, tol_errs, f_min=0.0, oracle_fun=oracle_fun, assert_flag=True)

def test_small_noisy_func():
np.random.seed(42343)
def noisy_sphere(x, sigma=1.0):
"""Simple quadratic function with added noise."""
x_2d = np.atleast_2d(x)
f = np.sum(x_2d**2, axis=1)
noise = 1e-4 * sigma * np.random.normal(size=x_2d.shape[0])
return f + noise

x0 = np.array([-3, -3, -3])
LB = np.array([-5, -5, -5])
UB = np.array([5, 5, 5])
PLB = np.array([-2, -2, -2])
PUB = np.array([2, 2, 2])
tol_errs = np.array([0.1, 0.1, 0.1])

oracle_fun = lambda x: np.sum(np.atleast_2d(x)**2, axis=1)
run_bads(
noisy_sphere,
x0,
LB,
UB,
PLB,
PUB,
tol_errs,
f_min=0.0,
oracle_fun=oracle_fun,
uncertainty_handling=1,
assert_flag=True,
max_fun_evals=300
)

def he_noisy_sphere(x):
y = np.sum(np.atleast_2d(x)**2, axis=1)
s = 2 + 1*np.sqrt(y)
Expand All @@ -125,3 +156,4 @@ def test_he_noisy_sphere_opt():
fun = he_noisy_sphere
oracle_fun = lambda x: np.sum(np.atleast_2d(x)**2, axis=1) # True objective function
run_bads(fun, x0, LB, UB, PLB, PUB, tol_errs, f_min=0.0, oracle_fun=oracle_fun, uncertainty_handling=2, assert_flag=True)