docstr: Compare to the explicit reparameterization derivative.
docstr_tok: ["Compare","to","the","explicit","reparameterization","derivative","."]
code: def testCompareToExplicitGradient(self):
      """Compare to the explicit reparameterization derivative."""
      concentration_np = np.arange(4)[..., np.newaxis] + 1.0
      concentration = tf.constant(concentration_np, self.dtype)
      loc_np = np.arange(3) + 1.0
      loc = tf.constant(loc_np, self.dtype)
  
      def gen_samples(l, c):
          return inverse_gaussian.InverseGaussian(l, c).sample(
              2, seed=test_util.test_seed()
          )
  
      samples, [loc_grad, concentration_grad] = self.evaluate(
          gradient.value_and_gradient(gen_samples, [loc, concentration])
      )
      self.assertEqual(samples.shape, (2, 4, 3))
      self.assertEqual(concentration_grad.shape, concentration.shape)
      self.assertEqual(loc_grad.shape, loc.shape)
  
      # Compute the gradient by computing the derivative of gammaincinv
      # over each entry and summing.
      def expected_grad(s, l, c):
          u = _scipy_invgauss(l, c).cdf(s)
          delta = 1e-4
          return (
              sp_misc.derivative(
                  lambda x: _scipy_invgauss(x, c).ppf(u),
                  l,
                  dx=delta * l,
              ),
              sp_misc.derivative(
                  lambda x: _scipy_invgauss(l, x).ppf(u),
                  c,
                  dx=delta * c,
              ),
          )
  
      expected_loc_grad, expected_concentration_grad = expected_grad(
          samples, loc_np, concentration_np
      )
  
      self.assertAllClose(
          concentration_grad,
          np.sum(expected_concentration_grad, axis=(0, 2))[
              ..., np.newaxis
          ],
          rtol=1e-3,
      )
  
      self.assertAllClose(
          loc_grad, np.sum(expected_loc_grad, axis=(0, 1)), rtol=1e-3
      )
  
imports: import numpy
  from scipy import misc
  from scipy import stats
  import tensorflow.compat.v1
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import inverse_gaussian
  from tensorflow_probability.python.internal import test_util
  from tensorflow_probability.python.math import gradient
label_desc: Use image node_id 23 for calling the _InverseGaussianTest obj's underlying member method code with example usage: obj.testCompareToExplicitGradient() and returns: inverse_gaussian, sp_misc,  sp_misc