Package minimise :: Module generic_line_search
[hide private]
[frames] | no frames]

Source Code for Module minimise.generic_line_search

 1  from re import match 
 2   
 3  # Line search functions. 
 4  from line_search.backtrack import backtrack 
 5  from line_search.nocedal_wright_interpol import nocedal_wright_interpol 
 6  from line_search.nocedal_wright_wolfe import nocedal_wright_wolfe 
 7  from line_search.more_thuente import more_thuente 
 8   
 9   
10 -class generic_line_search:
11 - def __init__(self):
12 "Class containing non-specific line search algorithm code."
13 14
15 - def new_param_func(self):
16 """Pure Newton minimisation. 17 18 Function options 19 ~~~~~~~~~~~~~~~~ 20 21 func - The function to minimise. 22 dfunc - The function which returns the gradient vector. 23 d2func - The function which returns the hessian matrix. 24 x0 - The initial parameter vector. 25 args - The tuple of arguments to supply to the functions func, dfunc, and d2func. 26 tol - The cutoff value used to terminate minimisation by comparison to the difference in function values between iterations. 27 maxiter - The maximum number of iterations. 28 full_output - A flag specifying what should be returned (see below). 29 print_flag - A flag specifying how much information should be printed to standard output during minimisation: 30 31 The print flag corresponds to: 32 0 - No output. 33 1 - Minimal output. 34 2 - Full output. 35 36 37 Returned objects 38 ~~~~~~~~~~~~~~~~ 39 40 If full_output=0, then only the minimised parameter vector is returned. 41 If full_output=1, then the minimised parameter vector, function value at the minimum, number of iterations, and a warning flag are returned. 42 The warning flag corresponds to: 43 0 - Minimisation terminated successfully. 44 1 - Maximum number of iterations have been reached. 45 46 47 Internal variables 48 ~~~~~~~~~~~~~~~~~~ 49 50 k - The iteration number. 51 xk - Parameter vector at iteration number k. 52 fk - Function value at xk. 53 fk_last - Function value at xk-1. 54 dfk - Gradient vector at xk. 55 d2fk - Hessian matrix at xk. 56 pk - Descent direction of the iteration number k. 57 58 """ 59 60 # Initialise. 61 fc, gc, hc = 0, 0, 0 62 63 # Calculate the search direction for iteration k. 64 self.dir() 65 66 # Get a0. 67 try: 68 self.get_a0() 69 except AttributeError: 70 "a0 should not be changed." 71 72 # Backtracking line search. 73 if match('^[Bb]ack', self.line_search_algor): 74 self.alpha, fc = backtrack(self.func, self.args, self.xk, self.fk, self.dfk, self.pk, a_init=self.a0) 75 # Nocedal and Wright interpolation based line search. 76 elif match('^[Nn]ocedal[ _][Ww]right[ _][Ii]nt', self.line_search_algor): 77 self.alpha, fc = nocedal_wright_interpol(self.func, self.args, self.xk, self.fk, self.dfk, self.pk, a_init=self.a0, mu=self.mu, print_flag=0) 78 # Nocedal and Wright line search for the Wolfe conditions. 79 elif match('^[Nn]ocedal[ _][Ww]right[ _][Ww]olfe', self.line_search_algor): 80 self.alpha, fc, gc = nocedal_wright_wolfe(self.func, self.dfunc, self.args, self.xk, self.fk, self.dfk, self.pk, a_init=self.a0, mu=self.mu, eta=self.eta, print_flag=0) 81 # More and Thuente line search. 82 elif match('^[Mm]ore[ _][Tt]huente$', self.line_search_algor): 83 self.alpha, fc, gc = more_thuente(self.func, self.dfunc, self.args, self.xk, self.fk, self.dfk, self.pk, a_init=self.a0, mu=self.mu, eta=self.eta, print_flag=0) 84 # No line search. 85 elif match('^[Nn]one$', self.line_search_algor): 86 self.alpha = self.a0 87 # No match to line search string. 88 else: 89 raise NameError, "The line search algorithm " + self.line_search_algor + " is not coded.\n" 90 91 self.f_count = self.f_count + fc 92 self.g_count = self.g_count + gc 93 self.h_count = self.h_count + hc 94 95 # Find the new parameter vector. 96 self.xk_new = self.xk + self.alpha * self.pk
97