1 from Numeric import dot, sqrt
2
3
5 """An algorithm for trust region radius selection.
6
7 Page 68 from 'Numerical Optimization' by Jorge Nocedal and Stephen J. Wright, 1999
8 """
9
10 while 1:
11
12 pk = get_pk()
13
14
15 rho = calc_rho(func, xk, pk, dfk, Bk)
16
17
18 norm_pk = sqrt(dot(pk, pk))
19
20
21
22 if rho < 0.25:
23 delta_new = 0.25 * norm_pk
24
25 elif rho > 0.75 and norm_pk == delta:
26 delta_new = min(2.0*delta, delta_max)
27
28 else:
29 delta_new = delta
30
31
32 if rho > eta:
33 xk_new = xk + pk
34 else:
35 xk_new = xk
36
37
38 delta = delta_new
39 xk = xk_new
40
41
43 """Function to calculate the ratio rho used to choose the trust region radius.
44
45 The ratio is defined as:
46
47 f(xk) - f(xk + pk)
48 rho = ------------------
49 mk(0) - mk(pk)
50
51 Where the numerator is called the actual reduction and the denominator is the predicted reduction.
52 """
53
54
55 fk = apply(func, (xk,)+args)
56 f_pk = apply(func, (xk + pk,)+args)
57 act_red = f - f_p
58
59
60 mk_pk = fk + dot(dfk, pk) + 0.5 * dot(pk, dot(Bk, pk))
61 pred_red = f - mk_pk
62
63
64 rho = act_red / pred_red
65 return rho
66