#! /usr/bin/env python # def beale ( m, x ): #*****************************************************************************80 # ## BEALE computes the Beale function. # # Discussion: # # This function has a global minimizer: # # X = ( 3.0, 0.5 ) # # for which # # F(X) = 0. # # For a relatively easy computation, start the search at # # X = ( 1.0, 1.0 ) # # A harder computation starts at # # X = ( 1.0, 4.0 ) # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2016 # # Author: # # John Burkardt # # Reference: # # Evelyn Beale, # On an Iterative Method for Finding a Local Minimum of a Function # of More than One Variable, # Technical Report 25, # Statistical Techniques Research Group, # Princeton University, 1958. # # Richard Brent, # Algorithms for Minimization with Derivatives, # Dover, 2002, # ISBN: 0-486-41998-3, # LC: QA402.5.B74. # # Parameters: # # Input, integer M, the number of variables. # # Input, real X(M), the argument of the function. # # Output, real F, the value of the function at X. # f1 = 1.5 - x[0] * ( 1.0 - x[1] ) f2 = 2.25 - x[0] * ( 1.0 - x[1] ** 2 ) f3 = 2.625 - x[0] * ( 1.0 - x[1] ** 3 ) f = f1 ** 2 + f2 ** 2 + f3 ** 2 return f def beale_test ( ): #*****************************************************************************80 # #% BEALE_TEST works with the Beale function. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2016 # # Author: # # John Burkardt # import numpy as np import platform from compass_search import compass_search from r8vec_print import r8vec_print print ( '' ) print ( 'BEALE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Test COMPASS_SEARCH with the Beale function.' ) m = 2 delta_tol = 0.00001 delta = 0.1 k_max = 20000 x = np.array ( [ 1.0, 1.0 ] ) r8vec_print ( m, x, ' Initial point X0:' ) print ( '' ) print ( ' F(X0) = %g' % ( beale ( m, x ) ) ) x, fx, k = compass_search ( beale, m, x, delta_tol, delta, k_max ) r8vec_print ( m, x, ' Estimated minimizer X1:' ) print ( '' ) print ( ' F(X1) = %g, number of steps = %d' % ( fx, k ) ) # # Repeat with more difficult start. # x = np.array ( [ 1.0, 4.0 ] ) r8vec_print ( m, x, ' Initial point X0:' ) print ( '' ) print ( ' F(X0) = %g' % ( beale ( m, x ) ) ) x, fx, k = compass_search ( beale, m, x, delta_tol, delta, k_max ) r8vec_print ( m, x, ' Estimated minimizer X1:' ) print ( '' ) print ( ' F(X1) = %g, number of steps = %d' % ( fx, k ) ) # # Demonstrate correct minimizer. # x = np.array ( [ 3.0, 0.5 ] ) r8vec_print ( m, x, ' Correct minimizer X*:' ) print ( '' ) print ( ' F(X*) = %g' % ( beale ( m, x ) ) ) # # Terminate. # print ( '' ) print ( 'BEALE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) beale_test ( ) timestamp ( )