def __call__(self, counter, fn, gradient, step):
if self.max_iter is not None and counter >= self.max_iter:<EOL><INDENT>return True<EOL><DEDENT>if self.fun_margin is not None:<EOL><INDENT>if self.fn_lowest is None or fn < self.fn_lowest:<EOL><INDENT>self.fn_lowest = fn<EOL><DEDENT>elif fn > self.fn_lowest + self.fun_margin:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>if self.grad_margin is not None:<EOL><INDENT>grad_rms = np.sqrt((gradient**<NUM_LIT:2>).mean())<EOL>if self.grad_rms_lowest is None or grad_rms < self.grad_rms_lowest:<EOL><INDENT>self.grad_rms_lowest = grad_rms<EOL><DEDENT>elif grad_rms > self.grad_rms_lowest + self.grad_margin:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>if self.step_min is not None:<EOL><INDENT>step_rms = np.sqrt((step**<NUM_LIT:2>).mean())<EOL>if self.step_min > step_rms:<EOL><INDENT>return True<EOL><DEDENT><DEDENT>return False<EOL>
Return True when the minimizer has lost track