From 58ab2ee130cbed81609b1385c8883b8f2c06d7cc Mon Sep 17 00:00:00 2001 From: Lindon Roberts Date: Thu, 8 Jul 2021 13:17:01 +1000 Subject: [PATCH] Bugfix: step calculation for linear models without box constraints --- trustregion/interface.py | 2 +- trustregion/tests/test_interface.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trustregion/interface.py b/trustregion/interface.py index a09ee90..2da851b 100644 --- a/trustregion/interface.py +++ b/trustregion/interface.py @@ -102,7 +102,7 @@ def solve(g, H, delta, sl=None, su=None, verbose_output=False): crvmin = 0.0 if delta <= ZERO_THRESH else -1.0 elif linear and not box_constrained: # Minimise linear function inside a ball - analytic solution - s = g * (delta / np.linalg.norm(g)) + s = -g * (delta / np.linalg.norm(g)) crvmin = 0.0 elif linear: # Linear with box constraints - TRSLIN diff --git a/trustregion/tests/test_interface.py b/trustregion/tests/test_interface.py index 5ed6e09..a141a51 100644 --- a/trustregion/tests/test_interface.py +++ b/trustregion/tests/test_interface.py @@ -375,7 +375,7 @@ def runTest(self): delta = 5.0 for H in [None, np.zeros((len(g), len(g)))]: x = trustregion.solve(g, H, delta) - xtrue = delta * g / np.linalg.norm(g) + xtrue = -delta * g / np.linalg.norm(g) self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, msg='Wrong step') self.assertTrue(np.linalg.norm(x) <= delta + BALL_EPS, msg='Ball constraint violated')