class_docstr: A masked deterministic mixture of two distributions.
  
  This is useful when the mask is sampled from another distribution,
  possibly correlated across the batch. Often the mask can be
  marginalized out via enumeration.
  
  Example::
  
      change_point = pyro.sample("change_point",
                                 dist.Categorical(torch.ones(len(data) + 1)),
                                 infer={'enumerate': 'parallel'})
      mask = torch.arange(len(data), dtype=torch.long) >= changepoint
      with pyro.plate("data", len(data)):
          pyro.sample("obs", MaskedMixture(mask, dist1, dist2), obs=data)
  
  :param torch.Tensor mask: A boolean tensor toggling between ``component0``
      and ``component1``.
  :param pyro.distributions.TorchDistribution component0: a distribution
      for batch elements ``mask == False``.
  :param pyro.distributions.TorchDistribution component1: a distribution
      for batch elements ``mask == True``.
class_docstr_tok: ["A","masked","deterministic","mixture","of","two","distributions",".","This","is","useful","when","the","mask","is","sampled","from","another","distribution",",","possibly","correlated","across","the","batch",".","Often","the","mask","can","be","marginalized","out","via","enumeration",".","Example",":",":","change_point","=","pyro.sample","(","``","change_point","''",",","dist.Categorical","(","torch.ones","(","len","(","data",")","+","1",")",")",",","infer=","{","'enumerate","'",":","'parallel","'","}",")","mask","=","torch.arange","(","len","(","data",")",",","dtype=torch.long",")",">","=","changepoint","with","pyro.plate","(","``","data","''",",","len","(","data",")",")",":","pyro.sample","(","``","obs","''",",","MaskedMixture","(","mask",",","dist1",",","dist2",")",",","obs=data",")",":","param","torch.Tensor","mask",":","A","boolean","tensor","toggling","between","``","component0","``","and","``","component1","``",".",":","param","pyro.distributions.TorchDistribution","component0",":","a","distribution","for","batch","elements","``","mask","==","False","``",".",":","param","pyro.distributions.TorchDistribution","component1",":","a","distribution","for","batch","elements","``","mask","==","True","``","."]
code: def __init__(self, mask, component0, component1, validate_args=None):
      if not torch.is_tensor(mask) or mask.dtype != torch.bool:
          raise ValueError(
              "Expected mask to be a BoolTensor but got {}".format(
                  type(mask)
              )
          )
      if component0.event_shape != component1.event_shape:
          raise ValueError(
              "components event_shape disagree: {} vs {}".format(
                  component0.event_shape, component1.event_shape
              )
          )
      batch_shape = broadcast_shape(
          mask.shape, component0.batch_shape, component1.batch_shape
      )
      if mask.shape != batch_shape:
          mask = mask.expand(batch_shape)
      if component0.batch_shape != batch_shape:
          component0 = component0.expand(batch_shape)
      if component1.batch_shape != batch_shape:
          component1 = component1.expand(batch_shape)
  
      self.mask = mask
      self.component0 = component0
      self.component1 = component1
      super().__init__(
          batch_shape, component0.event_shape, validate_args
      )
  
      # We need to disable _validate_sample on each component since samples are only valid on the
      # component from which they are drawn. Instead we perform validation using a MaskedConstraint.
      self.component0._validate_args = False
      self.component1._validate_args = False
  
file_path: pyro/pyro/distributions/mixture.py
imports: import torch
  from torch.distributions import constraints
  from torch.distributions.utils import lazy_property
  from pyro.distributions.torch_distribution import TorchDistribution
  from pyro.distributions.util import broadcast_shape
label_desc: Use image node_id 1 to create a new MaskedMixture object from inherited base classes: TorchDistribution with example: obj = MaskedMixture(mask, component0, component1, validate_args)