relaxed_newton.py 1.15 KB
Newer Older
1
2
3
# -*- coding: utf-8 -*-

from .quasi_newton_minimizer import QuasiNewtonMinimizer
4
from .line_searching import LineSearchStrongWolfe
5
6
7


class RelaxedNewton(QuasiNewtonMinimizer):
8
9
10
11
12
13
14
15
16
17
18
19
    def __init__(self, line_searcher=LineSearchStrongWolfe(), callback=None,
                 convergence_tolerance=1E-4, convergence_level=3,
                 iteration_limit=None):
        super(RelaxedNewton, self).__init__(
                                line_searcher=line_searcher,
                                callback=callback,
                                convergence_tolerance=convergence_tolerance,
                                convergence_level=convergence_level,
                                iteration_limit=iteration_limit)

        self.line_searcher.prefered_initial_step_size = 1.

20
    def _get_descend_direction(self, energy):
21
22
23
        gradient = energy.gradient
        curvature = energy.curvature
        descend_direction = curvature.inverse_times(gradient)
24
25
26
27
28
29
        return descend_direction * -1
        #norm = descend_direction.norm()
#        if norm != 1:
#            return descend_direction / -norm
#        else:
#            return descend_direction * -1