예제 #1
0
 def test_call_gradient(self):
     step = FRConjugateGradientStep()
     state = {}
     function = Function()
     assert_equal(
         step(function=function, point=numpy.zeros((2)), state=state),
         numpy.array((4., -16.)))
예제 #2
0
 def test_call(self):
     step = FRConjugateGradientStep()
     step_decorated = RestartNotOrthogonalConjugateGradientStep(step, 0.1)
     state = {'iteration': 0}
     function = Function()
     assert_equal(
         step_decorated(function=function,
                        point=numpy.zeros((2)),
                        state=state), numpy.array((4., -16.)))
예제 #3
0
 def test_call_restart(self):
     step = FRConjugateGradientStep()
     step_decorated = RestartPeriodicallyConjugateGradientStep(step, 10)
     state = {'iteration': 10, 'step': None}
     function = Function()
     assert_equal(
         step_decorated(function=function,
                        point=numpy.zeros((2)),
                        state=state), numpy.array((4., -16.)))
예제 #4
0
 def test_call_conjugate_gradient(self):
     step = FRConjugateGradientStep()
     state = {}
     function = Function()
     direction = step(function=function,
                      point=numpy.zeros((2)),
                      state=state)
     origin = 0.178571428571 * direction
     newDirection = step(function=function, point=origin, state=state)
     assert (function(origin + 0.01 * newDirection) < function(origin))