def approx_direction(self, x): """ Calculate - H^{-1} * g """ g = self.grad(x) H = self.hess(x) try: L = np.linalg.cholesky(H) except np.linalg.LinAlgError: raise ValueError("The hessian is not positive definite.") # Solve L * y = b y = ut.forward_sub(L, -g) # Solve U * s = y d = ut.backward_sub(L.T, y) return d
def approx_direction(self, x): g = self.grad(x) try: gamma = g - self.g_old except: gamma = np.ones(self.dim) self.g_old = g.copy() H = self.hess P, L, U = lu(H) # d = np.linalg.solve(H, -g) # Solve L * y = b y = ut.forward_sub(L, -g) # Solve U * s = y d = ut.backward_sub(U, y) d = np.dot(np.linalg.inv(H), -g) return d, gamma