docstr: Test if gradient has the correct value for logistic regression.
docstr_tok: ["Test","if","gradient","has","the","correct","value","for","logistic","regression","."]
code: def test_grad_logistic(self):
      """Test if gradient has the correct value for logistic regression."""
      # Set data
      ndim = 2
      data = np.array(
          [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0], [-10.0, 9.0]]
      )
      labels = np.array([1.0, -1.0, 1.0, -1.0])
  
      # Set model parameters for linear regression.
      w = objax.TrainVar(jn.ones(ndim))
  
      def loss(x, y):
          xyw = jn.dot(x * np.tile(y, (ndim, 1)).transpose(), w.value)
          return jn.log(jn.exp(-xyw) + 1).mean(0)
  
      grad = objax.Grad(loss, objax.VarCollection({"w": w}))
      g = grad(data, labels)
  
      self.assertEqual(g[0].shape, tuple([ndim]))
  
      xw = np.dot(data, w.value)
      g_expect_w = -(
          data
          * np.tile(
              labels / (1 + np.exp(labels * xw)), (ndim, 1)
          ).transpose()
      ).mean(0)
      np.testing.assert_allclose(g[0], g_expect_w, atol=1e-7)
  
imports: import inspect
  import unittest
  from typing import Tuple, Dict, List
  import jax
  import jax.numpy
  import numpy
  from scipy.stats.distributions import chi2
  import objax
  from objax.typing import JaxArray
  from objax.zoo.dnnet import DNNet
label_desc: Use image node_id 3 for calling the TestGrad obj's underlying member method code with example usage: obj.test_grad_logistic() and returns: jn