docstr: Test that gradient is consistent with loss and that minimum is
  achievable with a small gradient
docstr_tok: ["Test","that","gradient","is","consistent","with","loss","and","that","minimum","is","achievable","with","a","small","gradient"]
code: def _test_grad(
      self, model, coeffs, delta_check_grad=None, delta_model_grad=None
  ):
      """Test that gradient is consistent with loss and that minimum is
      achievable with a small gradient
      """
      if coeffs.dtype is np.dtype("float32"):
          check_grad_epsilon = 3e-3
      else:
          check_grad_epsilon = 1e-7
  
      if delta_check_grad is None:
          delta_check_grad = self.delta_check_grad
  
      if delta_model_grad is None:
          delta_model_grad = self.delta_model_grad
  
      with warnings.catch_warnings(record=True):
          grad_check = check_grad(
              model.loss, model.grad, coeffs, epsilon=check_grad_epsilon
          )
  
      self.assertAlmostEqual(grad_check, 0.0, delta=delta_check_grad)
      # Check that minimum is achievable with a small gradient
  
      with warnings.catch_warnings(record=True):
          coeffs_min = fmin_bfgs(
              model.loss, coeffs, fprime=model.grad, disp=False
          )
          coeffs_min = coeffs_min.astype(self.dtype)
  
      self.assertAlmostEqual(
          norm(model.grad(coeffs_min)), 0.0, delta=delta_model_grad
      )
  
file_path: tick/tick/base_model/tests/generalized_linear_model.py
imports: import warnings
  import numpy
  from numpy.linalg import norm
  from scipy.optimize import check_grad, fmin_bfgs
  import unittest
label_desc: Use image node_id 2 for calling the TestGLM obj's underlying member method code with example usage: obj._test_grad(model, coeffs, delta_check_grad, delta_model_grad) without return types