def __init__(self, wrt, f, fprime, min_grad=1e-6, args=None): """Create a NonlinearConjugateGradient object. Parameters ---------- wrt : array_like Array of parameters of the problem. f : callable Objective function. fprime : callable First derivative of the objective function. min_grad : float If all components of the gradient fall below this value, stop minimization. args : iterable, optional Iterable of arguments passed on to the objective function and its derivatives. """ super(NonlinearConjugateGradient, self).__init__(wrt, args=args) self.f = f self.fprime = fprime self.line_search = WolfeLineSearch(wrt, self.f, self.fprime, c2=0.2) self.min_grad = min_grad
def __init__(self, wrt, f, fprime, initial_hessian_diag=1, n_factors=10, line_search=None, args=None): """ Create an Lbfgs object. Attributes ---------- wrt : array_like Current solution to the problem. Can be given as a first argument to \ ``.f`` and ``.fprime``. f : Callable The object function. fprime : Callable First derivative of the objective function. Returns an array of the \ same shape as ``.wrt``. initial_hessian_diag : array_like The initial estimate of the diagonal of the Hessian. n_factors : int The number of factors that should be used to implicitly represent the inverse Hessian. line_search : LineSearch object. Line search object to perform line searches with. args : iterable Iterator over arguments which ``fprime`` will be called with. """ super(Lbfgs, self).__init__(wrt, args=args) self.f = f self.fprime = fprime self.initial_hessian_diag = initial_hessian_diag self.n_factors = n_factors if line_search is not None: self.line_search = line_search else: self.line_search = WolfeLineSearch(wrt, self.f, self.fprime)
def __init__(self, wrt, f, fprime, initial_inv_hessian=None, line_search=None, args=None): """Create a BFGS object. Parameters ---------- wrt : array_like Array that represents the solution. Will be operated upon in place. ``f`` and ``fprime`` should accept this array as a first argument. f : callable The objective function. fprime : callable Callable that given a solution vector as first parameter and *args and **kwargs drawn from the iterations ``args`` returns a search direction, such as a gradient. initial_inv_hessian : array_like The initial estimate of the approximiate Hessian. line_search : LineSearch object. Line search object to perform line searches with. args : iterable Iterator over arguments which ``fprime`` will be called with. """ super(Bfgs, self).__init__(wrt, args=args) self.f = f self.fprime = fprime self.inv_hessian = initial_inv_hessian if line_search is not None: self.line_search = line_search else: self.line_search = WolfeLineSearch(wrt, self.f, self.fprime)