nnrl/optim/hessian_free.py
def line_search(
    func,
    x_0,
    d_x,
    expected_improvement,
    y_0=None,
    accept_ratio=0.1,
    backtrack_ratio=0.8,
    max_backtracks=15,
    atol=1e-7,
):
    """Perform a linesearch on func with start x_0 and direction d_x."""
    # pylint:disable=too-many-arguments
    if y_0 is None:
        y_0 = func(x_0)

    if expected_improvement >= atol:
        for exp in range(max_backtracks):
            ratio = backtrack_ratio ** exp
            x_new = x_0 - ratio * d_x
            y_new = func(x_new)
            improvement = y_0 - y_new
            # Armijo condition
            if improvement / (expected_improvement * ratio) >= accept_ratio:
                return x_new, expected_improvement * ratio, improvement

    return x_0, expected_improvement, 0
Perform a linesearch on func with start x_0 and direction d_x.
Perform a linesearch on func with start x_0 and direction d_x.
Perform a linesearch on func with start x_0 and direction d_x .
def line_search(
    func,
    x_0,
    d_x,
    expected_improvement,
    y_0=None,
    accept_ratio=0.1,
    backtrack_ratio=0.8,
    max_backtracks=15,
    atol=1e-7,
):
    if y_0 is None:
        y_0 = func(x_0)
    if expected_improvement >= atol:
        for exp in range(max_backtracks):
            ratio = backtrack_ratio ** exp
            x_new = x_0 - ratio * d_x
            y_new = func(x_new)
            improvement = y_0 - y_new
            if improvement / (expected_improvement * ratio) >= accept_ratio:
                return x_new, expected_improvement * ratio, improvement
    return x_0, expected_improvement, 0
def line_search ( func , x_0 , d_x , expected_improvement , y_0 = None , accept_ratio = 0.1 , backtrack_ratio = 0.8 , max_backtracks = 15 , atol = 1e-7 , ) : if y_0 is None : y_0 = func ( x_0 ) if expected_improvement >= atol : for exp in range ( max_backtracks ) : ratio = backtrack_ratio ** exp x_new = x_0 - ratio * d_x y_new = func ( x_new ) improvement = y_0 - y_new if improvement / ( expected_improvement * ratio ) >= accept_ratio : return x_new , expected_improvement * ratio , improvement return x_0 , expected_improvement , 0
Perform a linesearch on func with start x_0 and direction d_x.
Perform a linesearch on func with start x_0 and direction d_x .
"""Perform a linesearch on func with start x_0 and direction d_x.""" # pylint:disable=too-many-arguments # Armijo condition
func
x_0
d_x
expected_improvement
y_0
accept_ratio
backtrack_ratio
max_backtracks
atol