#NEWLINE# def scalar_search_armijo( phi , phi0 , derphi0 , c1 = 0.0001 , alpha0 = 1 , amin = 0 ) : #NEWLINE# #INDENT# "Minimize over alpha, the function ``phi(alpha)``.\n\n    Uses the interpolation algorithm (Armijo backtracking) as suggested by\n    Wright and Nocedal in 'Numerical Optimization', 1999, pg. 56-57\n\n    alpha > 0 is assumed to be a descent direction.\n\n    Returns\n    -------\n    alpha\n    phi1\n\n    " #NEWLINE# phi_a0 = phi ( alpha0 ) #NEWLINE# if ( phi_a0 <= ( phi0 + ( ( c1 * alpha0 ) * derphi0 ) ) ) : #NEWLINE# #INDENT# return ( alpha0 , phi_a0 ) #NEWLINE# #UNINDENT# alpha1 = ( ( ( ( - derphi0 ) * ( alpha0 ** 2 ) ) / 2.0 ) / ( ( phi_a0 - phi0 ) - ( derphi0 * alpha0 ) ) ) #NEWLINE# phi_a1 = phi ( alpha1 ) #NEWLINE# if ( phi_a1 <= ( phi0 + ( ( c1 * alpha1 ) * derphi0 ) ) ) : #NEWLINE# #INDENT# return ( alpha1 , phi_a1 ) #NEWLINE# #UNINDENT# while ( alpha1 > amin ) : #NEWLINE# #INDENT# factor = ( ( ( alpha0 ** 2 ) * ( alpha1 ** 2 ) ) * ( alpha1 - alpha0 ) ) #NEWLINE# a = ( ( ( alpha0 ** 2 ) * ( ( phi_a1 - phi0 ) - ( derphi0 * alpha1 ) ) ) - ( ( alpha1 ** 2 ) * ( ( phi_a0 - phi0 ) - ( derphi0 * alpha0 ) ) ) ) #NEWLINE# a = ( a / factor ) #NEWLINE# b = ( ( ( - ( alpha0 ** 3 ) ) * ( ( phi_a1 - phi0 ) - ( derphi0 * alpha1 ) ) ) + ( ( alpha1 ** 3 ) * ( ( phi_a0 - phi0 ) - ( derphi0 * alpha0 ) ) ) ) #NEWLINE# b = ( b / factor ) #NEWLINE# alpha2 = ( ( ( - b ) + np . sqrt ( abs ( ( ( b ** 2 ) - ( ( 3 * a ) * derphi0 ) ) ) ) ) / ( 3.0 * a ) ) #NEWLINE# phi_a2 = phi ( alpha2 ) #NEWLINE# if ( phi_a2 <= ( phi0 + ( ( c1 * alpha2 ) * derphi0 ) ) ) : #NEWLINE# #INDENT# return ( alpha2 , phi_a2 ) #NEWLINE# #UNINDENT# if ( ( ( alpha1 - alpha2 ) > ( alpha1 / 2.0 ) ) or ( ( 1 - ( alpha2 / alpha1 ) ) < 0.96 ) ) : #NEWLINE# #INDENT# alpha2 = ( alpha1 / 2.0 ) #NEWLINE# #UNINDENT# alpha0 = alpha1 #NEWLINE# alpha1 = alpha2 #NEWLINE# phi_a0 = phi_a1 #NEWLINE# phi_a1 = phi_a2 #NEWLINE# #UNINDENT# return ( None , phi_a1 )