def test_ProjGradient_quadraticBounded(self): PG = Optimization.ProjectedGradient(debug=True) PG.lower, PG.upper = -2, 2 xopt = PG.minimize(getQuadratic(self.A, self.b), np.array([0, 0])) x_true = np.array([2., 2.]) print('xopt: ', xopt) print('x_true: ', x_true) self.assertTrue(np.linalg.norm(xopt - x_true, 2) < TOL, True)
def test_ProjGradient_quadratic1Bound(self): myB = np.array([-5, 1]) PG = Optimization.ProjectedGradient() PG.lower, PG.upper = -2, 2 xopt = PG.minimize(getQuadratic(self.A, myB), np.array([0, 0])) x_true = np.array([2., -1.]) print('xopt: ', xopt) print('x_true: ', x_true) self.assertTrue(np.linalg.norm(xopt - x_true, 2) < TOL, True)