line_search.py 1.49 KB
Newer Older
1
2
3
4
import abc

from keepers import Loggable

5
6
from nifty import LineEnergy

7
8
9

class LineSearch(object, Loggable):
    """
Jait Dixit's avatar
Jait Dixit committed
10
    Class for finding a step size.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    """
    __metaclass__ = abc.ABCMeta

    def __init__(self):

        """
        Parameters
        ----------

        f : callable f(x, *args)
            Objective function.

        fprime : callable f'(x, *args)
            Objective functions gradient.

        f_args : tuple (optional)
            Additional arguments passed to objective function and its
            derivation.
        """

        self.pk = None
32
        self.line_energy = None
theos's avatar
theos committed
33
        self.f_k_minus_1 = None
34

35
    def _set_line_energy(self, energy, pk, f_k_minus_1=None):
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
        """
        Set the coordinates for a new line search.

        Parameters
        ----------
        xk : ndarray, d2o, field
            Starting point.

        pk : ndarray, d2o, field
            Unit vector in search direction.

        f_k : float (optional)
            Function value f(x_k).

        fprime_k : ndarray, d2o, field (optional)
            Function value fprime(xk).

        """
54
55
56
        self.line_energy = LineEnergy(position=0.,
                                      energy=energy,
                                      line_direction=pk)
57
58
        if f_k_minus_1 is not None:
            f_k_minus_1 = f_k_minus_1.copy()
theos's avatar
theos committed
59
60
        self.f_k_minus_1 = f_k_minus_1

61
    @abc.abstractmethod
62
    def perform_line_search(self, energy, pk, f_k_minus_1=None):
63
        raise NotImplementedError