def update(self, gradient, step):
self.old_gradient = self.gradient<EOL>self.gradient = gradient<EOL>N = len(self.gradient)<EOL>if self.inv_hessian is None:<EOL><INDENT>self.direction = -self.gradient<EOL>self.status = "<STR_LIT>"<EOL>self.inv_hessian = np.identity(N, float)<EOL><DEDENT>else:<EOL><INDENT>self.direction = -np.dot(self.inv_hessian, self.gradient)<EOL>self.status = "<STR_LIT>"<EOL>y = self.gradient - self.old_gradient<EOL>s = step<EOL>sy = abs(np.dot(s, y))+<NUM_LIT><EOL>A = np.outer(-y/sy, s)<EOL>A.ravel()[::N+<NUM_LIT:1>] += <NUM_LIT:1><EOL>self.inv_hessian = (<EOL>np.dot(np.dot(A.transpose(), self.inv_hessian), A) +<EOL>np.outer(s/sy, s)<EOL>)<EOL><DEDENT>
Update the search direction given the latest gradient and step