code: def test_marginalized_gradient(self):
      n = 10
  
      mu1 = tf.Variable(3.0)
      mu2 = tf.Variable(3.0)
  
      def model():
          change_year = yield Root(
              categorical.Categorical(probs=tf.ones(n) / n)
          )
          for year in range(n):
              post_change_year = tf.cast(
                  year >= change_year, dtype=tf.int32
              )
              mu = tf.gather([mu1, mu2], post_change_year)
              accidents = yield poisson.Poisson(mu)
  
      counts = np.ones([n], dtype=np.float32)
      dist = marginalize.MarginalizableJointDistributionCoroutine(model)
      obs = ["marginalize"] + list(counts)
      with tf.GradientTape() as tape:
          loss = -dist.marginalized_log_prob(obs)
      grad = tape.gradient(loss, [mu1, mu2])
      self.assertLen(grad, 2)
      self.assertAllNotNone(grad)
  
imports: import functools
  import itertools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import deterministic
  from tensorflow_probability.python.distributions import hidden_markov_model
  from tensorflow_probability.python.distributions import joint_distribution_coroutine
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import poisson
  from tensorflow_probability.python.distributions import sample
  import tensorflow_probability.python.experimental.marginalize
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 8 for calling the _MarginalizeTest obj's underlying member method code with example usage: obj.test_marginalized_gradient() without return types