Ejemplo n.º 1
0
    def __init__(self,eggs,spam=None,a=(0.2,0.5,1,2),c=(1E-4,0.9),note=False):
        """
            Initializes the steepest_descent and sets the attributes (except
            for `x`).

            Parameters
            ----------
            eggs : function
                Given the current `x` it returns the tuple of energy and gradient.
            spam : function, *optional*
                Callback function which is given the current `x` and iteration
                counter each iteration (default: None).
            a : {4-tuple}, *optional*
                Numbers obeying 0 < a1 ~ a2 < 1 ~ a3 < a4 that modify the step
                widths (default: (0.2,0.5,1,2)).
            c : {2-tuple}, *optional*
                Numbers obeying 0 < c1 < c2 < 1 that specify the Wolfe-conditions
                (default: (1E-4,0.9)).
            note : bool, *optional*
                Indicates whether notes are printed or not (default: False).

        """
        self.eggs = eggs ## returns energy and gradient

        self.spam = spam ## serves as callback given x and iteration number
        self.a = a ## 0 < a1 ~ a2 < 1 ~ a3 < a4
        self.c = c ## 0 < c1 < c2 < 1
        self.note = notification(default=bool(note))

        self._alpha = None ## last alpha
Ejemplo n.º 2
0
    def __init__(self,
                 eggs,
                 spam=None,
                 a=(0.2, 0.5, 1, 2),
                 c=(1E-4, 0.9),
                 note=False):
        """
            Initializes the steepest_descent and sets the attributes (except
            for `x`).

            Parameters
            ----------
            eggs : function
                Given the current `x` it returns the tuple of energy and gradient.
            spam : function, *optional*
                Callback function which is given the current `x` and iteration
                counter each iteration (default: None).
            a : {4-tuple}, *optional*
                Numbers obeying 0 < a1 ~ a2 < 1 ~ a3 < a4 that modify the step
                widths (default: (0.2,0.5,1,2)).
            c : {2-tuple}, *optional*
                Numbers obeying 0 < c1 < c2 < 1 that specify the Wolfe-conditions
                (default: (1E-4,0.9)).
            note : bool, *optional*
                Indicates whether notes are printed or not (default: False).

        """
        self.eggs = eggs  ## returns energy and gradient

        self.spam = spam  ## serves as callback given x and iteration number
        self.a = a  ## 0 < a1 ~ a2 < 1 ~ a3 < a4
        self.c = c  ## 0 < c1 < c2 < 1
        self.note = notification(default=bool(note))

        self._alpha = None  ## last alpha
Ejemplo n.º 3
0
    def __init__(self, A, b, W=None, spam=None, reset=None, note=False):
        """
            Initializes the conjugate_gradient and sets the attributes (except
            for `x`).

            Parameters
            ----------
            A : {operator, function}
                Operator `A` applicable to a field.
            b : field
                Resulting field of the operation `A(x)`.
            W : {operator, function}, *optional*
                Operator `W` that is a preconditioner on `A` and is applicable to a
                field (default: None).
            spam : function, *optional*
                Callback function which is given the current `x` and iteration
                counter each iteration (default: None).
            reset : integer, *optional*
                Number of iterations after which to restart; i.e., forget previous
                conjugated directions (default: sqrt(b.dim())).
            note : bool, *optional*
                Indicates whether notes are printed or not (default: False).

        """
        if (hasattr(A, "__call__")):
            self.A = A  ## applies A
        else:
            raise AttributeError(
                about._errors.cstring("ERROR: invalid input."))
        self.b = b

        if (W is None) or (hasattr(W, "__call__")):
            self.W = W  ## applies W ~ A_inverse
        else:
            raise AttributeError(
                about._errors.cstring("ERROR: invalid input."))

        self.spam = spam  ## serves as callback given x and iteration number
        if (reset is None):  ## 2 < reset ~ sqrt(dim)
            self.reset = max(2, int(np.sqrt(b.domain.dim(split=False))))
        else:
            self.reset = max(2, int(reset))
        self.note = notification(default=bool(note))
Ejemplo n.º 4
0
    def __init__(self,A,b,W=None,spam=None,reset=None,note=False):
        """
            Initializes the conjugate_gradient and sets the attributes (except
            for `x`).

            Parameters
            ----------
            A : {operator, function}
                Operator `A` applicable to a field.
            b : field
                Resulting field of the operation `A(x)`.
            W : {operator, function}, *optional*
                Operator `W` that is a preconditioner on `A` and is applicable to a
                field (default: None).
            spam : function, *optional*
                Callback function which is given the current `x` and iteration
                counter each iteration (default: None).
            reset : integer, *optional*
                Number of iterations after which to restart; i.e., forget previous
                conjugated directions (default: sqrt(b.dim())).
            note : bool, *optional*
                Indicates whether notes are printed or not (default: False).

        """
        if(hasattr(A,"__call__")):
            self.A = A ## applies A
        else:
            raise AttributeError(about._errors.cstring("ERROR: invalid input."))
        self.b = b

        if(W is None)or(hasattr(W,"__call__")):
            self.W = W ## applies W ~ A_inverse
        else:
            raise AttributeError(about._errors.cstring("ERROR: invalid input."))

        self.spam = spam ## serves as callback given x and iteration number
        if(reset is None): ## 2 < reset ~ sqrt(dim)
            self.reset = max(2,int(np.sqrt(b.domain.dim(split=False))))
        else:
            self.reset = max(2,int(reset))
        self.note = notification(default=bool(note))