コード例 #1
0
ファイル: test_trust_region.py プロジェクト: mjhough/dfols
 def runTest(self):
     n = 3
     g = np.array([1.0, 0.0, 1.0])
     H = np.array([[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]])
     Delta = 5.0 / 12.0
     xopt = np.zeros((n,))
     sl = -1e20 * np.ones((n,))
     su = 1e20 * np.ones((n,))
     d, gnew, crvmin = trsbox(xopt, g, H, sl, su, Delta)
     true_d = np.array([-1.0 / 3.0, 0.0, -0.25])
     est_min = model_value(g, H, d)
     true_min = model_value(g, H, true_d)
     # Hope to get actual correct answer
     # self.assertTrue(np.all(d == true_d), 'Wrong answer')
     # self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
     s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
     self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
     self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
     self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
コード例 #2
0
 def runTest(self):
     n = 3
     g = np.array([0.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 = sqrt(2.0)
     hess = H
     xopt = np.zeros((n, ))
     sl = -1e20 * np.ones((n, ))
     su = 1e20 * np.ones((n, ))
     d, gnew, crvmin = trsbox(xopt, g, hess, sl, su, Delta)
     true_d = np.array([1.0, 0.0, -1.0])  # non-unique solution
     est_min = model_value(g, hess, d)
     true_min = model_value(g, hess, true_d)
     # Hope to get actual correct answer
     # self.assertTrue(np.all(d == true_d), 'Wrong answer')
     # self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
     s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, hess, Delta)
     self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
     self.assertTrue(np.all(gnew == g + hess.dot(d)), 'Wrong gnew')
     self.assertAlmostEqual(crvmin, 0.0, 'Wrong crvmin')
コード例 #3
0
 def runTest(self):
     n = 3
     g = np.array([1.0, 0.0, 1.0])
     H = np.array([[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]])
     Delta = 2.0
     xopt = np.ones((n, ))  # trying nonzero (since bounds inactive)
     sl = -1e20 * np.ones((n, ))
     su = 1e20 * np.ones((n, ))
     d, gnew, crvmin = trsbox(xopt, g, H, sl, su, Delta)
     true_d = np.array([-1.0, 0.0, -0.5])
     est_min = model_value(g, H, d)
     true_min = model_value(g, H, true_d)
     # Hope to get actual correct answer for internal minimum?
     # self.assertTrue(np.all(d == true_d), 'Wrong answer')
     # self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
     s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt(g, H, Delta)
     self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
     self.assertTrue(np.all(gnew == g + H.dot(d)), 'Wrong gnew')
     print(crvmin)
     self.assertAlmostEqual(crvmin, 1.2, 'Wrong crvmin')
コード例 #4
0
ファイル: test_trust_region.py プロジェクト: mjhough/dfols
 def runTest(self):
     n = 3
     g = np.array([1.0, 0.0, 1.0])
     H = np.array([[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]])
     Delta = 5.0 / 12.0
     xopt = np.zeros((n,))
     sl = xopt + np.array([-0.3, -0.01, -0.1])
     su = xopt + np.array([10.0, 1.0, 10.0])
     d, gnew, crvmin = trsbox(xopt, g, H, sl, su, Delta)
     true_d = np.array([-1.0 / 3.0, 0.0, -0.25])
     est_min = model_value(g, H, d)
     true_min = model_value(g, H, true_d)
     # Hope to get actual correct answer
     # self.assertTrue(np.all(d == true_d), 'Wrong answer')
     # self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
     s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt_box(g, H, Delta, sl - xopt, su - xopt)
     self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
     self.assertTrue(np.max(np.abs(gnew - g - H.dot(d))) < 1e-10, 'Wrong gnew')
     print(crvmin)
     self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')
コード例 #5
0
 def runTest(self):
     n = 3
     g = np.array([1.0, 0.0, 1.0])
     H = np.array([[1.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]])
     Delta = 2.0
     hess = Hessian(n, vals=H)
     xopt = np.ones((n, ))  # trying nonzero (since bounds inactive)
     sl = xopt + np.array([-0.5, -10.0, -10.0])
     su = xopt + np.array([10.0, 10.0, 10.0])
     d, gnew, crvmin = trsbox(xopt, g, hess, sl, su, Delta)
     true_d = np.array([-1.0, 0.0, -0.5])
     est_min = model_value(g, hess, d)
     true_min = model_value(g, hess, true_d)
     # Hope to get actual correct answer for internal minimum?
     # self.assertTrue(np.all(d == true_d), 'Wrong answer')
     # self.assertAlmostEqual(est_min, true_min, 'Wrong min value')
     s_cauchy, red_cauchy, crvmin_cauchy = cauchy_pt_box(
         g, hess, Delta, sl - xopt, su - xopt)
     # print(s_cauchy)
     # print(d)
     self.assertTrue(est_min <= red_cauchy, 'Cauchy reduction not achieved')
     self.assertTrue(np.all(gnew == g + hess.vec_mul(d)), 'Wrong gnew')
     print(crvmin)
     self.assertAlmostEqual(crvmin, -1.0, 'Wrong crvmin')