1 from Numeric import copy, dot, sqrt
2
3
6 "Class containing non-specific trust region algorithm code."
7
8
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
16 self.calc_pk()
17
18
19 self.calc_rho()
20
21
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
32
33 if self.rho < 0.25:
34 self.delta_new = 0.25 * self.norm_pk
35
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
39 else:
40 self.delta_new = self.delta
41
42 if self.print_flag == 2:
43 print "Delta fin: " + `self.delta`
44
45
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
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
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
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
73 self.rho = act_red / pred_red
74