| Trees | Indices | Help |
|
|---|
|
|
1 ###############################################################################
2 # #
3 # Copyright (C) 2003-2013 Edward d'Auvergne #
4 # #
5 # This file is part of the minfx optimisation library, #
6 # https://sourceforge.net/projects/minfx #
7 # #
8 # This program is free software: you can redistribute it and/or modify #
9 # it under the terms of the GNU General Public License as published by #
10 # the Free Software Foundation, either version 3 of the License, or #
11 # (at your option) any later version. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 # #
21 ###############################################################################
22
23 # Module docstring.
24 """Eigenvalue Hessian modification.
25
26 This file is part of the U{minfx optimisation library<https://sourceforge.net/projects/minfx>}.
27 """
28
29 # Python module imports.
30 from numpy import dot, sort
31 from numpy.linalg import eig, inv
32
33
35 """The eigenvalue Hessian modification.
36
37 This modification is based on equation 6.14 from page 144 of 'Numerical Optimization' by Jorge Nocedal and Stephen J. Wright, 1999, 2nd ed.
38
39 Returns the modified Newton step.
40 """
41
42 # Calculate the eigenvalues.
43 eigen = eig(d2fk)
44 eigenvals = sort(eigen[0])
45
46 # Modify the Hessian if the smallest eigenvalue is negative.
47 tau = None
48 if eigenvals[0] < 0.0:
49 tau = max(0.0, 1e-2 - eigenvals[0])
50 matrix = d2fk + tau * I
51 else:
52 matrix = d2fk
53
54 # Debugging.
55 if print_flag >= 3:
56 eigen_new = eig(matrix)
57 eigenvals_new = sort(eigen_new[0])
58 print(print_prefix + "d2fk:\n" + repr(d2fk))
59 print(print_prefix + "eigenvals(d2fk): " + repr(eigenvals))
60 print(print_prefix + "tau: " + repr(tau))
61 print(print_prefix + "matrix:\n" + repr(matrix))
62 print(print_prefix + "eigenvals(matrix): " + repr(eigenvals_new))
63 print(print_prefix + "Newton dir: " + repr(-dot(inv(matrix), dfk)))
64
65 # Calculate the Newton direction.
66 if return_matrix:
67 return -dot(inv(matrix), dfk), matrix
68 else:
69 return -dot(inv(matrix), dfk)
70
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Nov 26 19:05:06 2013 | http://epydoc.sourceforge.net |