Changeset 975 for trunk/GSASIImath.py
- Timestamp:
- Jun 29, 2013 11:39:57 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIImath.py
r974 r975 42 42 atan2d = lambda y,x: 180.*np.arctan2(y,x)/np.pi 43 43 44 def HessianLSQ(func,x0,Hess,args=(),ftol=1.49012e-8,xtol=1.49012e-8, maxcyc=0 ):44 def HessianLSQ(func,x0,Hess,args=(),ftol=1.49012e-8,xtol=1.49012e-8, maxcyc=0,Print=False): 45 45 46 46 """ … … 66 66 :param int maxcyc: The maximum number of cycles of refinement to execute, if -1 refine 67 67 until other limits are met (ftol, xtol) 68 :param bool Print: True for printing results (residuals & times) by cycle 68 69 69 70 :returns: (x,cov_x,infodict) where … … 100 101 lamMax = lam 101 102 nfev = 0 103 if Print: 104 print ' Hessian refinement on %d variables:'%(n) 102 105 while icycle < maxcyc: 103 lamMax = max(lamMax,lam)106 time0 = time.time() 104 107 M = func(x0,*args) 105 108 nfev += 1 … … 112 115 Anorm = np.outer(Adiag,Adiag) 113 116 Yvec /= Adiag 114 Amat /= Anorm 117 Amat /= Anorm 115 118 while True: 116 119 Lam = np.eye(Amat.shape[0])*lam … … 135 138 print 'ouch #3 chisq1 ',chisq1,' stuck > chisq0 ',chisq0 136 139 break 140 lamMax = max(lamMax,lam) 141 if Print: 142 print ' Cycle: %d, Time: %.2fs, Chi**2: %.3g, Lambda: %.3g'%(icycle,time.time()-time0,chisq1,lam) 137 143 if (chisq0-chisq1)/chisq0 < ftol: 138 144 break … … 141 147 nfev += 1 142 148 Yvec,Amat = Hess(x0,*args) 149 Lam = np.eye(Amat.shape[0])*lam 150 Amatlam = Amat*(One+Lam) 143 151 try: 144 Bmat = nl.inv(Amat )152 Bmat = nl.inv(Amatlam) 145 153 return [x0,Bmat,{'num cyc':icycle,'fvec':M,'nfev':nfev,'lamMax':lamMax,'psing':[]}] 146 154 except nl.LinAlgError:
Note: See TracChangeset
for help on using the changeset viewer.