Example #1
0
class TrustRegionCG(TrustRegionSolver):
    """
    Instantiate a trust-region subproblem solver based on the truncated
    conjugate gradient method of Steihaug and Toint. See the :mod:`pcg` module
    for more information.

    The main difference between this class and the :class:`TrustRegionPCG`
    class is that :class:`TrustRegionPCG` only accepts explicit
    preconditioners (i.e. in matrix form). This class accepts an implicit
    preconditioner, i.e., any callable object.
    """
    def __init__(self, g, H, **kwargs):

        TrustRegionSolver.__init__(self, g, **kwargs)
        self.cgSolver = TruncatedCG(g, H, **kwargs)
        self.niter = 0
        self.stepNorm = 0.0
        self.step = None
        self.m = None  # Model value at candidate solution

    def Solve(self, **kwargs):
        """
        Solve trust-region subproblem using the truncated conjugate-gradient
        algorithm.
        """
        self.cgSolver.Solve(**kwargs)
        self.niter = self.cgSolver.niter
        self.stepNorm = self.cgSolver.stepNorm
        self.step = self.cgSolver.step
        # Compute model reduction.
        self.m = np.dot(self.g, self.step)
        self.m += 0.5 * np.dot(self.step, self.cgSolver.H * self.step)
        return