geometric/step.py
def trust_step(target, v0, X, G, H, IC, rfo, verbose=0):
    """
    Apply an iteration formula to find the trust radius step,
    given the target value of the trust radius.

    Parameters
    ----------
    target : float
        Target size of the trust radius step
    v0 : float
        Initial guess for Number that is added to the Hessian diagonal
    X : np.ndarray
        Flat array of Cartesian coordinates in atomic units
    G : np.ndarray
        Flat array containing internal gradient
    H : np.ndarray
        Square array containing internal Hessian
    IC : InternalCoordinates
        Object describing the internal coordinate system
    rfo : bool
        If True, use rational functional optimization, otherwise use trust-radius method
    verbose : int
        Print diagnostic messages

    Returns
    -------
    dy : np.ndarray
        The internal coordinate step with the desired size
    sol : float
        Expected change of the objective function
    """
    if verbose >= 2: logger.info("    trust_step targeting internal coordinate step of length %.4f\n" % target)
    dy, sol, dy_prime = get_delta_prime(v0, X, G, H, IC, rfo, verbose)

    ndy = np.linalg.norm(dy)
    if ndy < target:
        return dy, sol
    v = v0
    niter = 0
    ndy_last = 0
    # Store the minimum norm in case we give up
    m_ndy = ndy
    m_dy = dy.copy()
    m_sol = sol
    while True:
        if rfo:
            # Nonlinear Newton's method solution, from Bofill (1998)
            v += (target/ndy-1)*(ndy/dy_prime) 
        else:
            # Iterative formula from Hebden (1973), equation 5.2.10 in "Practical methods of optimization" by Fletcher
            v += (1-ndy/target)*(ndy/dy_prime)
        dy, sol, dy_prime, = get_delta_prime(v, X, G, H, IC, rfo, verbose)
        ndy = np.linalg.norm(dy)
        if np.abs((ndy-target)/target) < 0.001:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy on target:   %.5f ---> %.5f\n" % (niter, v, ndy, target))
            return dy, sol
        # With Lagrange multipliers it may be impossible to go under a target step size
        elif niter > 10 and np.abs(ndy_last-ndy)/ndy < 0.001:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy over target: %.5f -x-> %.5f\n" % (niter, v, ndy, target))
            return dy, sol
        elif verbose >= 2:
            logger.info("    trust_step Iter:  %4i, v = %.5f, dy -> target:   %.5f ---> %.5f\n" % (niter, v, ndy, target))
        niter += 1
        ndy_last = ndy
        if ndy < m_ndy:
            m_ndy = ndy
            m_dy = dy.copy()
            m_sol = sol
        # Break out of infinite oscillation loops
        if niter%100 == 99:
            logger.info("    trust_step Iter:  %4i, randomizing\n" % niter)
            v += np.random.random() * niter / 100
        if niter%1000 == 999:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy at max-iter: %.5f -x-> %.5f\n" % (niter, v, ndy, target))
            return m_dy, m_sol

    Apply an iteration formula to find the trust radius step,
    given the target value of the trust radius.

    Parameters
    ----------
    target : float
        Target size of the trust radius step
    v0 : float
        Initial guess for Number that is added to the Hessian diagonal
    X : np.ndarray
        Flat array of Cartesian coordinates in atomic units
    G : np.ndarray
        Flat array containing internal gradient
    H : np.ndarray
        Square array containing internal Hessian
    IC : InternalCoordinates
        Object describing the internal coordinate system
    rfo : bool
        If True, use rational functional optimization, otherwise use trust-radius method
    verbose : int
        Print diagnostic messages

    Returns
    -------
    dy : np.ndarray
        The internal coordinate step with the desired size
    sol : float
        Expected change of the objective function
    
Apply an iteration formula to find the trust radius step,
given the target value of the trust radius.

Parameters



Returns

dy : np.ndarray
The internal coordinate step with the desired size
sol : float
Expected change of the objective function
Apply an iteration formula to find the trust radius step given the target value of the trust radius . Parameters Returns dy : np . ndarray The internal coordinate step with the desired size sol : float Expected change of the objective function
def trust_step(target, v0, X, G, H, IC, rfo, verbose=0):
    if verbose >= 2: logger.info("    trust_step targeting internal coordinate step of length %.4f\n" % target)
    dy, sol, dy_prime = get_delta_prime(v0, X, G, H, IC, rfo, verbose)
    ndy = np.linalg.norm(dy)
    if ndy < target:
        return dy, sol
    v = v0
    niter = 0
    ndy_last = 0
    m_ndy = ndy
    m_dy = dy.copy()
    m_sol = sol
    while True:
        if rfo:
            v += (target/ndy-1)*(ndy/dy_prime) 
        else:
            v += (1-ndy/target)*(ndy/dy_prime)
        dy, sol, dy_prime, = get_delta_prime(v, X, G, H, IC, rfo, verbose)
        ndy = np.linalg.norm(dy)
        if np.abs((ndy-target)/target) < 0.001:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy on target:   %.5f ---> %.5f\n" % (niter, v, ndy, target))
            return dy, sol
        elif niter > 10 and np.abs(ndy_last-ndy)/ndy < 0.001:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy over target: %.5f -x-> %.5f\n" % (niter, v, ndy, target))
            return dy, sol
        elif verbose >= 2:
            logger.info("    trust_step Iter:  %4i, v = %.5f, dy -> target:   %.5f ---> %.5f\n" % (niter, v, ndy, target))
        niter += 1
        ndy_last = ndy
        if ndy < m_ndy:
            m_ndy = ndy
            m_dy = dy.copy()
            m_sol = sol
        if niter%100 == 99:
            logger.info("    trust_step Iter:  %4i, randomizing\n" % niter)
            v += np.random.random() * niter / 100
        if niter%1000 == 999:
            if verbose >= 3: get_delta_prime(v, X, G, H, IC, rfo, verbose+1)
            if verbose: logger.info("    trust_step Iter:  %4i, v = %.5f, dy at max-iter: %.5f -x-> %.5f\n" % (niter, v, ndy, target))
            return m_dy, m_sol
def trust_step ( target , v0 , X , G , H , IC , rfo , verbose = 0 ) : if verbose >= 2 : logger . info ( "    trust_step targeting internal coordinate step of length %.4f\n" % target ) dy , sol , dy_prime = get_delta_prime ( v0 , X , G , H , IC , rfo , verbose ) ndy = np . linalg . norm ( dy ) if ndy < target : return dy , sol v = v0 niter = 0 ndy_last = 0 m_ndy = ndy m_dy = dy . copy ( ) m_sol = sol while True : if rfo : v += ( target / ndy - 1 ) * ( ndy / dy_prime ) else : v += ( 1 - ndy / target ) * ( ndy / dy_prime ) dy , sol , dy_prime , = get_delta_prime ( v , X , G , H , IC , rfo , verbose ) ndy = np . linalg . norm ( dy ) if np . abs ( ( ndy - target ) / target ) < 0.001 : if verbose >= 3 : get_delta_prime ( v , X , G , H , IC , rfo , verbose + 1 ) if verbose : logger . info ( "    trust_step Iter:  %4i, v = %.5f, dy on target:   %.5f ---> %.5f\n" % ( niter , v , ndy , target ) ) return dy , sol elif niter > 10 and np . abs ( ndy_last - ndy ) / ndy < 0.001 : if verbose >= 3 : get_delta_prime ( v , X , G , H , IC , rfo , verbose + 1 ) if verbose : logger . info ( "    trust_step Iter:  %4i, v = %.5f, dy over target: %.5f -x-> %.5f\n" % ( niter , v , ndy , target ) ) return dy , sol elif verbose >= 2 : logger . info ( "    trust_step Iter:  %4i, v = %.5f, dy -> target:   %.5f ---> %.5f\n" % ( niter , v , ndy , target ) ) niter += 1 ndy_last = ndy if ndy < m_ndy : m_ndy = ndy m_dy = dy . copy ( ) m_sol = sol if niter % 100 == 99 : logger . info ( "    trust_step Iter:  %4i, randomizing\n" % niter ) v += np . random . random ( ) * niter / 100 if niter % 1000 == 999 : if verbose >= 3 : get_delta_prime ( v , X , G , H , IC , rfo , verbose + 1 ) if verbose : logger . info ( "    trust_step Iter:  %4i, v = %.5f, dy at max-iter: %.5f -x-> %.5f\n" % ( niter , v , ndy , target ) ) return m_dy , m_sol
Apply an iteration formula to find the trust radius step,
given the target value of the trust radius.
Apply an iteration formula to find the trust radius step given the target value of the trust radius .
"""
    Apply an iteration formula to find the trust radius step,
    given the target value of the trust radius.

    Parameters
    ----------
    target : float
        Target size of the trust radius step
    v0 : float
        Initial guess for Number that is added to the Hessian diagonal
    X : np.ndarray
        Flat array of Cartesian coordinates in atomic units
    G : np.ndarray
        Flat array containing internal gradient
    H : np.ndarray
        Square array containing internal Hessian
    IC : InternalCoordinates
        Object describing the internal coordinate system
    rfo : bool
        If True, use rational functional optimization, otherwise use trust-radius method
    verbose : int
        Print diagnostic messages

    Returns
    -------
    dy : np.ndarray
        The internal coordinate step with the desired size
    sol : float
        Expected change of the objective function
    """ # Store the minimum norm in case we give up # Nonlinear Newton's method solution, from Bofill (1998) # Iterative formula from Hebden (1973), equation 5.2.10 in "Practical methods of optimization" by Fletcher # With Lagrange multipliers it may be impossible to go under a target step size # Break out of infinite oscillation loops
target
v0
X
G
H
IC
rfo
verbose