def runTest(self): xbase = np.array([0.0, 0.0]) + 1 g = np.array([1.0, -1.0]) a = np.array([-2.0, -2.0]) + 1 b = np.array([1.0, 2.0]) + 1 hess = Hessian(2) delta = 5.0 c = 3.0 # may want to max instead x = trsbox_geometry(xbase, c, g, hess, a, b, delta) xtrue = np.array([1.0, -2.0]) + 1 self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, 'Wrong step')
def runTest(self): xbase = np.array([0.0, 0.0]) g = np.array([1e-15, -1.0]) a = np.array([-2.0, -2.0]) b = np.array([1.0, 2.0]) hess = Hessian(2) delta = 5.0 c = 0.0 x = trsbox_geometry(xbase, c, g, hess, a, b, delta) xtrue = np.array([0.0, 2.0]) self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, 'Wrong step')
def runTest(self): xbase = np.array([0.0, 0.0]) g = np.array([1.0, -1.0]) a = np.array([-2.0, -2.0]) b = np.array([1.0, 2.0]) hess = np.zeros((2, 2)) delta = 2.0 c = -1.0 x = trsbox_geometry(xbase, c, g, hess, a, b, delta) xtrue = np.array([-sqrt(2.0), sqrt(2.0)]) self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, 'Wrong step')
def runTest(self): xbase = np.array([0.0, 0.0, 0.0]) g = np.array([-1.0, -1.0, -1.0]) a = np.array([-2.0, -2.0, -2.0]) b = np.array([0.9, 0.1, 5.0]) hess = Hessian(3) delta = sqrt(3.0) c = -1.0 # may want to max instead x = trsbox_geometry(xbase, c, g, hess, a, b, delta) xtrue = np.array([0.9, 0.1, sqrt(3.0 - 0.81 - 0.01)]) print(x) self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, 'Wrong step')
def runTest(self): xbase = np.array([0.0, 0.0]) g = np.array([-1.0, -1.0]) a = np.array([-2.0, -2.0]) b = np.array([0.1, 0.9]) hess = np.zeros((2, 2)) delta = sqrt(2.0) c = -1.0 # may want to max instead x = trsbox_geometry(xbase, c, g, hess, a, b, delta) xtrue = b # print(x) self.assertTrue(np.max(np.abs(x - xtrue)) < 1e-10, 'Wrong step')
def runTest(self): xbase = np.array([0.0, 0.0]) g = np.array([1e-15, 0.0]) a = np.array([-2.0, -2.0]) b = np.array([1.0, 2.0]) hess = Hessian(2) delta = 5.0 c = 0.0 x = trsbox_geometry(xbase, c, g, hess, a, b, delta) # Since objective is essentially zero, will accept any x within the defined region self.assertTrue(np.linalg.norm(x) <= delta) self.assertTrue(np.max(x - a) >= 0.0) self.assertTrue(np.max(x - b) <= 0.0)
def runTest(self): n = 3 c = 1.0 # changed this value to force max rather than min g = np.array([1.0, 0.0, 1.0]) H = np.array([[-2.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0]]) Delta = 5.0 / 12.0 xopt = np.zeros((n, )) sl = -1e20 * np.ones((n, )) su = 1e20 * np.ones((n, )) x = trsbox_geometry(xopt, c, g, H, sl, su, Delta) xtrue = np.array([0.25, 0.0, 1.0 / 3.0]) # max solution # print(x) # print(xtrue) self.assertTrue(np.allclose(x, xtrue, atol=1e-3), "Wrong step")
def runTest(self): n = 3 c = -1.0 g = np.array([1.0, 0.0, 1.0]) H = np.array([[-2.0, 0.0, 0.0], [0.0, -1.0, 0.0], [0.0, 0.0, -1.0]]) Delta = 5.0 / 12.0 xopt = np.zeros((n, )) sl = -1e20 * np.ones((n, )) su = 1e20 * np.ones((n, )) x = trsbox_geometry(xopt, c, g, H, sl, su, Delta) xtrue = np.array([-1.0 / 3.0, 0.0, -0.25]) # print(x) # print(xtrue) self.assertTrue(np.allclose(x, xtrue, atol=5e-2), "Wrong step")