Пример #1
0
 def para_solver(L):
     # Levenberg-Marquardt
     # HT = H + (L-1)**2*np.diag(np.diag(H))
     # Attempt to use plain Levenberg
     HT = H + (L-1)**2*np.eye(len(H))
     # print "Inverting Scaled Hessian:"                       ###
     # print " G:"                                             ###
     # pvec1d(G,precision=5)                                   ###
     # print " HT: (Scal = %.4f)" % (1+(L-1)**2)               ###
     # pmat2d(HT,precision=5)                                  ###
     Hi = invert_svd(np.mat(HT))
     dx = flat(-1 * Hi * col(G))
     # print " dx:"                                            ###
     # pvec1d(dx,precision=5)                                  ###
     # dxa = -solve(HT, G)
     # dxa = flat(dxa)
     # print " dxa:"                                           ###
     # pvec1d(dxa,precision=5)                                 ###
     # print                                                   ###
     sol = flat(0.5*row(dx)*np.mat(H)*col(dx))[0] + np.dot(dx,G)
     for i in self.excision:    # Reinsert deleted coordinates - don't take a step in those directions
         dx = np.insert(dx, i, 0)
     return dx, sol
Пример #2
0
 def _compute(self, dx):
     self.dx = dx.copy()
     Tmp = np.mat(self.H)*col(dx)
     Reg_Term   = self.Penalty.compute(xkd+flat(dx), Obj0)
     self.Val   = (X + np.dot(dx, G) + 0.5*row(dx)*Tmp + Reg_Term[0] - data['X'])[0,0]
     self.Grad  = flat(col(G) + Tmp) + Reg_Term[1]