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

Source Code for Module minimise.generic_trust_region

 1  from Numeric import copy, dot, sqrt 
 2   
 3   
4 -class generic_trust_region:
5 - def __init__(self):
6 "Class containing non-specific trust region algorithm code."
7 8
9 - def new_param_func(self):
10 """An algorithm for trust region radius selection. 11 12 Page 68 from 'Numerical Optimization' by Jorge Nocedal and Stephen J. Wright, 1999 13 """ 14 15 # Optain pk. 16 self.calc_pk() 17 18 # Evaluate rho. 19 self.calc_rho() 20 21 # Calculate the Euclidean norm of pk. 22 self.norm_pk = sqrt(dot(self.pk, self.pk)) 23 24 if self.print_flag == 2: 25 print "Delta orig: " + `self.delta` 26 print "rho: " + `self.rho` 27 print "pk: " + `self.pk` 28 print "||pk||: " + `self.norm_pk` 29 print "dfk: " + `self.dfk` 30 31 # Choose the trust region radius for the next iteration. 32 # Rho is close to zero or negative, therefore the trust region is shrunk. 33 if self.rho < 0.25: 34 self.delta_new = 0.25 * self.norm_pk 35 # Rho is close to one and pk has reached the boundary of the trust region, therefore the trust region is expanded. 36 elif self.rho > 0.75 and self.norm_pk == self.delta: 37 self.delta_new = min(2.0*self.delta, self.delta_max) 38 # Rho is positive but not close to one, therefore the trust region is unaltered. 39 else: 40 self.delta_new = self.delta 41 42 if self.print_flag == 2: 43 print "Delta fin: " + `self.delta` 44 45 # Choose the position for the next iteration. 46 if self.rho > self.eta: 47 self.xk_new = self.xk + self.pk 48 else: 49 self.xk_new = copy.deepcopy(self.xk)
50 51
52 - def calc_rho(self):
53 """Function to calculate the ratio rho used to choose the trust region radius. 54 55 The ratio is defined as: 56 57 f(xk) - f(xk + pk) 58 rho = ------------------ 59 mk(0) - mk(pk) 60 61 Where the numerator is called the actual reduction and the denominator is the predicted reduction. 62 """ 63 64 # Actual reduction. 65 fxkpk, self.f_count = apply(self.func, (self.xk + self.pk,)+self.args), self.f_count + 1 66 act_red = self.fk - fxkpk 67 68 # Predicted reduction. 69 mk_pk = self.fk + dot(self.dfk, self.pk) + 0.5 * dot(self.pk, dot(self.d2fk, self.pk)) 70 pred_red = self.fk - mk_pk 71 72 # Rho. 73 self.rho = act_red / pred_red
74