class_docstr: Mixture (same-family) distribution.
  
  The `MixtureSameFamily` distribution implements a (batch of) mixture
  distribution where all components are from different parameterizations of the
  same distribution type. It is parameterized by a `Categorical` 'selecting
  distribution' (over `k` components) and a components distribution, i.e., a
  `Distribution` with a rightmost batch shape (equal to `[k]`) which indexes
  each (batch of) component.
  
  #### Examples
  
  ```python
  tfd = tfp.distributions
  
  ### Create a mixture of two scalar Gaussians:
  
  gm = tfd.MixtureSameFamily(
      mixture_distribution=tfd.Categorical(
          probs=[0.3, 0.7]),
      components_distribution=tfd.Normal(
        loc=[-1., 1],       # One for each component.
        scale=[0.1, 0.5]))  # And same here.
  
  gm.mean()
  # ==> 0.4
  
  gm.variance()
  # ==> 1.018
  
  # Plot PDF.
  x = np.linspace(-2., 3., int(1e4), dtype=np.float32)
  import matplotlib.pyplot as plt
  plt.plot(x, gm.prob(x));
  
  ### Create a mixture of three Bivariate Gaussians:
  
  gm = tfd.MixtureSameFamily(
      mixture_distribution=tfd.Categorical(
          probs=[0.2, 0.4, 0.4]),
      components_distribution=tfd.MultivariateNormalDiag(
          loc=[[-1., 1],  # component 1
               [1, -1],  # component 2
               [1, 1]],  # component 3
          scale_diag=tf.tile([[.3], [.6], [.7]], [1, 2])))
  
  gm.components_distribution.batch_shape
  # ==> (3,)
  
  gm.components_distribution.event_shape
  # ==> (2,)
  
  gm.mean()
  # ==> array([ 0.6, 0.2], dtype=float32)
  
  gm.covariance()
  # ==> array([[ 0.998    , -0.32     ],
  #            [-0.32     ,  1.3180001]], dtype=float32)
  
  # Plot PDF contours.
  def meshgrid(x):
    y = x
    [gx, gy] = np.meshgrid(x, y, indexing='ij')
    gx, gy = np.float32(gx), np.float32(gy)
    grid = np.concatenate([gx.ravel()[None, :], gy.ravel()[None, :]], axis=0)
    return grid.T.reshape(x.size, y.size, 2)
  grid = meshgrid(np.linspace(-2, 2, 100, dtype=np.float32))
  plt.contour(grid[..., 0], grid[..., 1], gm.prob(grid));
  ```
  
  Note that this distribution is *not* a joint distribution over categorical
  and continuous values, but rather a mixture of continuous distributions
  proportioned by the given categorical distribution. If you want a joint
  distribution, you might write it as:
  
  ```python
  @tfd.JointDistributionCoroutineAutoBatched
  def model():
    mus = tf.constant([[-1., 1], # component 1
                       [1, -1],  # component 2
                       [1, 1]])  # component 3
    scales = tf.constant([.3, .6, .7])
    idx = yield tfd.Categorical(probs=[.2, .4, .4], name='idx')
    val = yield tfd.MultivariateNormalDiag(
        loc=mus[idx], scale_diag=tf.ones(2) * scales[idx], name='val')
  
  model.sample()
  # ==> StructTuple(
  #       idx=2,
  #       val=array([1.0582672, 1.3583777], dtype=float32)
  #     )
  ```
class_docstr_tok: ["Mixture","(","same-family",")","distribution",".","The","`","MixtureSameFamily","`","distribution","implements","a","(","batch","of",")","mixture","distribution","where","all","components","are","from","different","parameterizations","of","the","same","distribution","type",".","It","is","parameterized","by","a","`","Categorical","`","'selecting","distribution","'","(","over","`","k","`","components",")","and","a","components","distribution",",","i.e.",",","a","`","Distribution","`","with","a","rightmost","batch","shape","(","equal","to","`","[","k","]","`",")","which","indexes","each","(","batch","of",")","component",".","#","#","#","#","Examples","``","`","python","tfd","=","tfp.distributions","#","#","#","Create","a","mixture","of","two","scalar","Gaussians",":","gm","=","tfd.MixtureSameFamily","(","mixture_distribution=tfd.Categorical","(","probs=","[","0.3",",","0.7","]",")",",","components_distribution=tfd.Normal","(","loc=","[","-1.",",","1","]",",","#","One","for","each","component",".","scale=","[","0.1",",","0.5","]",")",")","#","And","same","here",".","gm.mean","(",")","#","==",">","0.4","gm.variance","(",")","#","==",">","1.018","#","Plot","PDF",".","x","=","np.linspace","(","-2.",",","3.",",","int","(","1e4",")",",","dtype=np.float32",")","import","matplotlib.pyplot","as","plt","plt.plot","(","x",",","gm.prob","(","x",")",")",";","#","#","#","Create","a","mixture","of","three","Bivariate","Gaussians",":","gm","=","tfd.MixtureSameFamily","(","mixture_distribution=tfd.Categorical","(","probs=","[","0.2",",","0.4",",","0.4","]",")",",","components_distribution=tfd.MultivariateNormalDiag","(","loc=","[","[","-1.",",","1","]",",","#","component","1","[","1",",","-1","]",",","#","component","2","[","1",",","1","]","]",",","#","component","3","scale_diag=tf.tile","(","[","[",".3","]",",","[",".6","]",",","[",".7","]","]",",","[","1",",","2","]",")",")",")","gm.components_distribution.batch_shape","#","==",">","(","3",",",")","gm.components_distribution.event_shape","#","==",">","(","2",",",")","gm.mean","(",")","#","==",">","array","(","[","0.6",",","0.2","]",",","dtype=float32",")","gm.covariance","(",")","#","==",">","array","(","[","[","0.998",",","-0.32","]",",","#","[","-0.32",",","1.3180001","]","]",",","dtype=float32",")","#","Plot","PDF","contours",".","def","meshgrid","(","x",")",":","y","=","x","[","gx",",","gy","]","=","np.meshgrid","(","x",",","y",",","indexing='ij","'",")","gx",",","gy","=","np.float32","(","gx",")",",","np.float32","(","gy",")","grid","=","np.concatenate","(","[","gx.ravel","(",")","[","None",",",":","]",",","gy.ravel","(",")","[","None",",",":","]","]",",","axis=0",")","return","grid.T.reshape","(","x.size",",","y.size",",","2",")","grid","=","meshgrid","(","np.linspace","(","-2",",","2",",","100",",","dtype=np.float32",")",")","plt.contour","(","grid","[","...",",","0","]",",","grid","[","...",",","1","]",",","gm.prob","(","grid",")",")",";","``","`","Note","that","this","distribution","is","*","not","*","a","joint","distribution","over","categorical","and","continuous","values",",","but","rather","a","mixture","of","continuous","distributions","proportioned","by","the","given","categorical","distribution",".","If","you","want","a","joint","distribution",",","you","might","write","it","as",":","``","`","python","@","tfd.JointDistributionCoroutineAutoBatched","def","model","(",")",":","mus","=","tf.constant","(","[","[","-1.",",","1","]",",","#","component","1","[","1",",","-1","]",",","#","component","2","[","1",",","1","]","]",")","#","component","3","scales","=","tf.constant","(","[",".3",",",".6",",",".7","]",")","idx","=","yield","tfd.Categorical","(","probs=","[",".2",",",".4",",",".4","]",",","name='idx","'",")","val","=","yield","tfd.MultivariateNormalDiag","(","loc=mus","[","idx","]",",","scale_diag=tf.ones","(","2",")","*","scales","[","idx","]",",","name='val","'",")","model.sample","(",")","#","==",">","StructTuple","(","#","idx=2",",","#","val=array","(","[","1.0582672",",","1.3583777","]",",","dtype=float32",")","#",")","``","`"]
docstr: Per mixture component log probability.
  
  Args:
    x: A tensor representing observations from the mixture. Must
      be broadcastable with the mixture's batch shape.
  
  Returns:
    A Tensor representing, for each observation and for each mixture
    component, the log joint probability of that mixture component and
    the observation. The shape will be equal to the concatenation of (1) the
    broadcast shape of the observations and the batch shape, and (2) the
    number of mixture components.
docstr_tok: ["Per","mixture","component","log","probability",".","Args",":","x",":","A","tensor","representing","observations","from","the","mixture",".","Must","be","broadcastable","with","the","mixture","'s","batch","shape",".","Returns",":","A","Tensor","representing",",","for","each","observation","and","for","each","mixture","component",",","the","log","joint","probability","of","that","mixture","component","and","the","observation",".","The","shape","will","be","equal","to","the","concatenation","of","(","1",")","the","broadcast","shape","of","the","observations","and","the","batch","shape",",","and","(","2",")","the","number","of","mixture","components","."]
code: def _per_mixture_component_log_prob(self, x):
      """Per mixture component log probability.
  
      Args:
        x: A tensor representing observations from the mixture. Must
          be broadcastable with the mixture's batch shape.
  
      Returns:
        A Tensor representing, for each observation and for each mixture
        component, the log joint probability of that mixture component and
        the observation. The shape will be equal to the concatenation of (1) the
        broadcast shape of the observations and the batch shape, and (2) the
        number of mixture components.
      """
      x = self._pad_sample_dims(x)
      log_prob_x = self.components_distribution.log_prob(x)  # [S, B, k]
      log_mix_prob = tf.math.log_softmax(
          self.mixture_distribution.logits_parameter(), axis=-1
      )  # [B, k]
      return log_prob_x + log_mix_prob
  
imports: import warnings
  import tensorflow.compat.v2
  from tensorflow_probability.python.distributions import batch_broadcast
  from tensorflow_probability.python.distributions import categorical
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import independent
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import custom_gradient
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensorshape_util
  from tensorflow_probability.python.math.gradient import value_and_batch_jacobian
label_desc: Use image node_id 11 for calling the _MixtureSameFamily obj's underlying member method code with example usage: obj._per_mixture_component_log_prob(x) and returns: unknown