code: def test_namedtuple_sample_log_prob(self):
      Model = collections.namedtuple(
          "Model", ["e", "scale", "loc", "m", "x"]
      )  # pylint: disable=invalid-name
      # pylint: disable=bad-whitespace
      model = Model(
          e=independent.Independent(
              exponential.Exponential(rate=[100, 120]), 1
          ),
          scale=lambda e: gamma.Gamma(
              concentration=e[..., 0], rate=e[..., 1]
          ),
          loc=normal.Normal(loc=0, scale=2.0),
          m=normal.Normal,
          x=lambda m: sample_lib.Sample(
              bernoulli.Bernoulli(logits=m), 12
          ),
      )
      # pylint: enable=bad-whitespace
      d = jdn.JointDistributionNamed(model, validate_args=True)
  
      self.assertEqual(
          (
              ("e", ()),
              ("scale", ("e",)),
              ("loc", ()),
              ("m", ("loc", "scale")),
              ("x", ("m",)),
          ),
          d.resolve_graph(),
      )
  
      xs = d.sample(seed=test_util.test_seed())
      self.assertLen(xs, 5)
      # We'll verify the shapes work as intended when we plumb these back into the
      # respective log_probs.
  
      ds, _ = d.sample_distributions(
          value=xs, seed=test_util.test_seed()
      )
      self.assertLen(ds, 5)
      self.assertIsInstance(ds.e, independent.Independent)
      self.assertIsInstance(ds.scale, gamma.Gamma)
      self.assertIsInstance(ds.loc, normal.Normal)
      self.assertIsInstance(ds.m, normal.Normal)
      self.assertIsInstance(ds.x, sample_lib.Sample)
  
      # Static properties.
      self.assertAllEqual(
          Model(
              e=tf.float32,
              scale=tf.float32,
              loc=tf.float32,
              m=tf.float32,
              x=tf.int32,
          ),
          d.dtype,
      )
  
      batch_shape_tensor_, event_shape_tensor_ = self.evaluate(
          [d.batch_shape_tensor(), d.event_shape_tensor()]
      )
  
      expected_batch_shape = Model(e=[], scale=[], loc=[], m=[], x=[])
      for expected, actual_tensorshape, actual_shape_tensor_ in zip(
          expected_batch_shape, d.batch_shape, batch_shape_tensor_
      ):
          self.assertAllEqual(expected, actual_tensorshape)
          self.assertAllEqual(expected, actual_shape_tensor_)
  
      expected_event_shape = Model(
          e=[2], scale=[], loc=[], m=[], x=[12]
      )
      for expected, actual_tensorshape, actual_shape_tensor_ in zip(
          expected_event_shape, d.event_shape, event_shape_tensor_
      ):
          self.assertAllEqual(expected, actual_tensorshape)
          self.assertAllEqual(expected, actual_shape_tensor_)
  
      expected_lp_parts = type(d.dtype)(
          *[d.log_prob(x) for d, x in zip(ds, xs)]
      )
      expected_jlp = sum(expected_lp_parts)
      actual_jlp = d.log_prob(xs)
      self.assertAllClose(expected_jlp, actual_jlp, atol=0.0, rtol=1e-4)
      self.assertAllCloseNested(
          expected_lp_parts, d.log_prob_parts(xs), atol=0.0, rtol=1e-4
      )
      self.assertAllCloseNested(
          expected_lp_parts,
          d.log_prob_parts(**xs._asdict()),
          atol=0.0,
          rtol=1e-4,
      )
      self.assertAllCloseNested(
          expected_lp_parts,
          d.log_prob_parts(tuple(xs)),
          atol=0.0,
          rtol=1e-4,
      )
      self.assertAllCloseNested(
          expected_lp_parts, d.log_prob_parts(*xs), atol=0.0, rtol=1e-4
      )
  
imports: import collections
  from absl.testing import parameterized
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector_test_util
  from tensorflow_probability.python.bijectors import scale
  from tensorflow_probability.python.distributions import bernoulli
  from tensorflow_probability.python.distributions import beta
  from tensorflow_probability.python.distributions import exponential
  from tensorflow_probability.python.distributions import gamma
  from tensorflow_probability.python.distributions import half_normal
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.distributions import joint_distribution_named
  from tensorflow_probability.python.distributions import joint_distribution_sequential
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import lognormal
  from tensorflow_probability.python.distributions import mvn_diag
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import student_t
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import test_util
label_desc: Use image node_id 2 for calling the JointDistributionNamedTest obj's underlying member method code with example usage: obj.test_namedtuple_sample_log_prob() without return types