Package minimise :: Package hessian_mods :: Module eigenvalue
[hide private]
[frames] | no frames]

Source Code for Module minimise.hessian_mods.eigenvalue

 1  ############################################################################### 
 2  #                                                                             # 
 3  # Copyright (C) 2003 Edward d'Auvergne                                        # 
 4  #                                                                             # 
 5  # This file is part of the program relax.                                     # 
 6  #                                                                             # 
 7  # relax is free software; you can redistribute it and/or modify               # 
 8  # it under the terms of the GNU General Public License as published by        # 
 9  # the Free Software Foundation; either version 2 of the License, or           # 
10  # (at your option) any later version.                                         # 
11  #                                                                             # 
12  # relax is distributed in the hope that it will be useful,                    # 
13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
15  # GNU General Public License for more details.                                # 
16  #                                                                             # 
17  # You should have received a copy of the GNU General Public License           # 
18  # along with relax; if not, write to the Free Software                        # 
19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
20  #                                                                             # 
21  ############################################################################### 
22   
23   
24  from LinearAlgebra import eigenvectors, inverse 
25  from Numeric import matrixmultiply, sort 
26   
27   
28 -def eigenvalue(dfk, d2fk, I, print_prefix, print_flag, return_matrix=0):
29 """The eigenvalue Hessian modification. 30 31 This modification is based on equation 6.14 from page 144 of 'Numerical Optimization' by 32 Jorge Nocedal and Stephen J. Wright, 1999, 2nd ed. 33 34 Returns the modified Newton step. 35 """ 36 37 # Calculate the eigenvalues. 38 eigen = eigenvectors(d2fk) 39 eigenvals = sort(eigen[0]) 40 41 # Modify the Hessian if the smallest eigenvalue is negative. 42 tau = None 43 if eigenvals[0] < 0.0: 44 tau = max(0.0, 1e-2 - eigenvals[0]) 45 matrix = d2fk + tau * I 46 else: 47 matrix = d2fk 48 49 # Debugging. 50 if print_flag >= 3: 51 eigen_new = eigenvectors(matrix) 52 eigenvals_new = sort(eigen_new[0]) 53 print print_prefix + "d2fk:\n" + `d2fk` 54 print print_prefix + "eigenvals(d2fk): " + `eigenvals` 55 print print_prefix + "tau: " + `tau` 56 print print_prefix + "matrix:\n" + `matrix` 57 print print_prefix + "eigenvals(matrix): " + `eigenvals_new` 58 print print_prefix + "Newton dir: " + `-matrixmultiply(inverse(matrix), dfk)` 59 60 # Calculate the Newton direction. 61 if return_matrix: 62 return -matrixmultiply(inverse(matrix), dfk), matrix 63 else: 64 return -matrixmultiply(inverse(matrix), dfk)
65