コード例 #1
0
 def testGoldsteinConditionsWithSuppliedGradientTwo(self):
     problem = OptimizationProblem(f, grad)
     op = ClassicalNewton(problem)
     actual = op.solve((1))
     self.assert_almost_equal(expected, actual, 0.0001)
 def testRosenBrockWithEasyInitialGuess(self):
     problem = OptimizationProblem(f)
     op = ClassicalNewton(problem)
     res = op.solve((2,2), search='inexact', cond = 'GS')
     np.testing.assert_almost_equal(self.ros_res, res)
 def testRosenBrockWithHardInitialGuessAndSuppliedGradient(self):
     problem = OptimizationProblem(f, grad)
     op = ClassicalNewton(problem)
     res = op.solve((-1.2, 1), search='exact')
     np.testing.assert_almost_equal(self.ros_res, res)
 def testRosenBrockWithStandardInitialGuess(self):
     problem = OptimizationProblem(f)
     op = ClassicalNewton(problem)
     res = op.solve(search='exact')
     np.testing.assert_almost_equal(self.ros_res, res)
 def testHessianFunctionWithGradient(self):
     problem = OptimizationProblem(f, grad)
     op = ClassicalNewton(problem)
     hessian = op.get_hessian(f, (1,2))
     np.testing.assert_allclose(self.man_hess, hessian, 0.0001)
 def testSuppliedGradient(self):
     problem = OptimizationProblem(f, grad)
     op = ClassicalNewton(problem)
     gradient = op.get_gradient(f, (1,2))
     np.testing.assert_allclose(gradient, self.man_gradient)