Skip to content

Commit

Permalink
add tests that actually hit optimization boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
FFroehlich committed Nov 12, 2020
1 parent b0e6611 commit b1ce8d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fides/hessian_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, dim, hess_init: Optional[np.ndarray] = None):
self._hess = hess_init.copy()

def update(self, s, y):
raise NotImplementedError()
raise NotImplementedError() # pragma : no cover

def get_mat(self) -> np.ndarray:
return self._hess
Expand Down
22 changes: 16 additions & 6 deletions tests/test_minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ def rosenboth(x):
return f, g, h


def finite_bounds_and_init():
def finite_bounds_include_optimum():
lb = np.array([-2, -1.5])
ub = np.array([1.5, 2])

x0 = np.zeros(lb.shape)
x0 = (lb + ub) / 2
return lb, ub, x0


def finite_bounds_exlude_optimum():
lb = np.array([-2, -1.5])
ub = np.array([0.99, 0.99])

x0 = (lb + ub) / 2
return lb, ub, x0


Expand All @@ -42,8 +50,9 @@ def unbounded_and_init():

@pytest.mark.parametrize("subspace_dim", [SubSpaceDim.FULL,
SubSpaceDim.TWO])
@pytest.mark.parametrize("bounds_and_init", [finite_bounds_and_init(),
unbounded_and_init()])
@pytest.mark.parametrize("bounds_and_init", [finite_bounds_include_optimum(),
unbounded_and_init(),
finite_bounds_exlude_optimum()])
@pytest.mark.parametrize("fun, happ", [
(rosenboth, None),
(rosenboth, None),
Expand All @@ -61,5 +70,6 @@ def test_minimize_hess_approx(bounds_and_init, fun, happ, subspace_dim):
fides.Options.SUBSPACE_DIM: subspace_dim}
)
opt.minimize(x0)
assert np.isclose(opt.x, [1, 1]).all()
assert np.isclose(opt.grad, np.zeros(opt.x.shape), atol=1e-6).all()
if np.all(ub > 1):
assert np.isclose(opt.x, [1, 1]).all()
assert np.isclose(opt.grad, np.zeros(opt.x.shape), atol=1e-6).all()

0 comments on commit b1ce8d8

Please sign in to comment.