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

Source Code for Module minimise.steepest_descent

 1  from Numeric import copy, dot 
 2   
 3  from generic_line_search import generic_line_search 
 4  from generic_minimise import generic_minimise 
 5   
 6   
7 -class steepest_descent(generic_line_search, generic_minimise):
8 - def __init__(self, func, dfunc=None, args=(), x0=None, line_search_algor=None, func_tol=1e-5, maxiter=1000, full_output=0, print_flag=0, a0=1.0, mu=0.0001, eta=0.1):
9 "Class for steepest descent minimisation specific functions." 10 11 self.func = func 12 self.dfunc = dfunc 13 self.args = args 14 self.xk = x0 15 self.func_tol = func_tol 16 self.maxiter = maxiter 17 self.full_output = full_output 18 self.print_flag = print_flag 19 20 if not line_search_algor: 21 raise NameError, "No line search algorithm has been supplied." 22 else: 23 self.line_search_algor = line_search_algor 24 25 # Set a0. 26 self.a0 = a0 27 28 # Line search constants for the Wolfe conditions. 29 self.mu = mu 30 self.eta = eta 31 32 # Initialise the function, gradient, and hessian evaluation counters. 33 self.f_count = 0 34 self.g_count = 0 35 self.h_count = 0 36 37 # Initialise the warning string. 38 self.warning = None 39 40 # The initial function value and gradient vector. 41 self.fk, self.f_count = apply(self.func, (self.xk,)+self.args), self.f_count + 1 42 self.dfk, self.g_count = apply(self.dfunc, (self.xk,)+self.args), self.g_count + 1 43 44 # Minimisation. 45 self.minimise = self.generic_minimise
46 47
48 - def backup_current_data(self):
49 "Function to backup the current data dfk into dfk_last." 50 51 self.fk_last = self.fk 52 self.dfk_last = copy.deepcopy(self.dfk)
53 54
55 - def dir(self):
56 "Return the steepest descent direction." 57 58 self.pk = -self.dfk
59 60
61 - def get_a0(self):
62 "Update a0 using information about the last iteration." 63 64 self.a0 = self.alpha * dot(self.dfk_last, -self.dfk_last) / dot(self.dfk, -self.dfk)
65 66
67 - def update_data(self):
68 "Function to update the function value, gradient vector, and hessian matrix" 69 70 self.xk = copy.deepcopy(self.xk_new) 71 self.fk, self.f_count = apply(self.func, (self.xk,)+self.args), self.f_count + 1 72 self.dfk, self.g_count = apply(self.dfunc, (self.xk,)+self.args), self.g_count + 1
73