class_docstr: A distribution that masks invalid underlying distributions.
  
  Sometimes we may want a way of masking out a subset of distributions. Perhaps
  we have labels for only a subset of batch members and want to evaluate a
  log_prob. Or we may want to encode a sparse random variable as a dense
  random variable with a mask applied. In single-program/multiple-data regimes,
  it can be necessary to pad Distributions and the samples thereof to a given
  size in order to achieve the "single-program" desideratum.
  
  When computing a probability density in this regime, we would like to mask out
  the contributions of invalid batch members. We may also want to ensure that
  the values being sampled are valid parameters for descendant distributions in
  a hierarchical model, even if they are ultimately masked out. This
  distribution answers those requirements. Specifically, for invalid batch
  elements:
  - `log_prob(x) == 0.` for all `x`, with no gradients back to `x`, nor any
    gradients to the parameters of `distribution`.
  - `sample() == tf.stop_gradient(safe_value_fn(distribution))`, with no
    gradients back to the parameters of `distribution`.
  
  The distribution accepts a mask specified by `validity_mask`, a boolean tensor
  broadcastable with the underlying distribution's batch shape which specifies
  for each batch element whether or not it is valid.
  
  Entries in `validity_mask` which are `False` denote missing distributions,
  which means that the corresponding entries in the measures (e.g. `prob`)
  and statistics (e.g. `mean`) must not be treated as coming from some real
  distribution. Whenever doing a reduction across those quantites, make sure to
  either mask out the invalid entries or make sure the returned value
  corresponds to the identity element of the reduction. For a couple examples:
  - OK: `reduce_sum(masked_dist.log_prob(x))`
  - OK: `tfd.Independent(masked_dist, ...)`
  - Not OK: `reduce_var(masked_dist.mean())` will underestimate the variance
    because it uses too large an `N`.
  - Not OK: `tf.linalg.cholesky(masked_dist.covariance())` will fail for invalid
    batch elements.
  
  The default `safe_value_fn` is to draw a fixed-seeded sample from the
  underlying `distribution`.  Since this may be expensive, it is suggested to
  specify a computationally cheaper method. Some options might include:
  - `tfd.Distribution.mode`
  - `tfd.Distribution.mean`
  - `lambda d: d.quantile(.5)` (median)
  - `lambda _: 0.` (if zero is always in the support of d)
  - `lambda d: d.experimental_default_event_space_bijector()(0.)`
  Besides the output of `sample`, results from `safe_value_fn` may also appear
  in (invalid batch members of) `masked.default_event_space_bijector().forward`.
  
  #### Examples
  
  ```
  # Use tf.sequence_mask for `range(n) < num_valid`.
  num_valid = 3
  num_entries = 4
  d = tfd.Masked(
      tfd.MultivariateNormalDiag(tf.zeros([2, num_entries, 5]), tf.ones([5])),
      tf.sequence_mask(num_valid, num_entries))
  d.batch_shape  # [2, 4]
  d.event_shape  # [5]
  d.log_prob(tf.zeros([5]))  # shape [2, 4]
  # => [[nonzero, nonzero, nonzero, 0.],
  #     [nonzero, nonzero, nonzero, 0.]]
  
  # Explicitly denote which elements are valid, adding a new batch dim of 2.
  d = tfd.Masked(tfd.MultivariateNormalDiag(tf.zeros([4, 5]), tf.ones([5])),
                 [[False], [True]])
  d.batch_shape  # [2, 4]
  d.event_shape  # [5]
  d.log_prob(tf.zeros([5]))  # shape [2, 4]
  # => [[0., 0., 0., 0.],
  #     [nonzero, nonzero, nonzero, nonzero]]
  
  # Use `BatchBroadcast` and `Independent` to achieve the equivalent of adding
  # positional mask functionality to `tfd.Sample`.
  # Suppose we wanted to achieve this:
  # `tfd.Sample(tfd.Normal(tf.zeros(2), 1), [3, 4], validity_mask=mask)`
  # We can write:
  d = tfd.Independent(
      tfd.Masked(tfd.BatchBroadcast(tfd.Normal(0, 1), [2, 3, 4]), mask),
      reinterpreted_batch_ndims=2)
  d.batch_shape  # [2]
  d.event_shape  # [3, 4]
  d.log_prob(tf.ones([3, 4]))  # shape [2]
  ```
class_docstr_tok: ["A","distribution","that","masks","invalid","underlying","distributions",".","Sometimes","we","may","want","a","way","of","masking","out","a","subset","of","distributions",".","Perhaps","we","have","labels","for","only","a","subset","of","batch","members","and","want","to","evaluate","a","log_prob",".","Or","we","may","want","to","encode","a","sparse","random","variable","as","a","dense","random","variable","with","a","mask","applied",".","In","single-program\/multiple-data","regimes",",","it","can","be","necessary","to","pad","Distributions","and","the","samples","thereof","to","a","given","size","in","order","to","achieve","the","``","single-program","''","desideratum",".","When","computing","a","probability","density","in","this","regime",",","we","would","like","to","mask","out","the","contributions","of","invalid","batch","members",".","We","may","also","want","to","ensure","that","the","values","being","sampled","are","valid","parameters","for","descendant","distributions","in","a","hierarchical","model",",","even","if","they","are","ultimately","masked","out",".","This","distribution","answers","those","requirements",".","Specifically",",","for","invalid","batch","elements",":","-","`","log_prob","(","x",")","==","0.","`","for","all","`","x","`",",","with","no","gradients","back","to","`","x","`",",","nor","any","gradients","to","the","parameters","of","`","distribution","`",".","-","`","sample","(",")","==","tf.stop_gradient","(","safe_value_fn","(","distribution",")",")","`",",","with","no","gradients","back","to","the","parameters","of","`","distribution","`",".","The","distribution","accepts","a","mask","specified","by","`","validity_mask","`",",","a","boolean","tensor","broadcastable","with","the","underlying","distribution","'s","batch","shape","which","specifies","for","each","batch","element","whether","or","not","it","is","valid",".","Entries","in","`","validity_mask","`","which","are","`","False","`","denote","missing","distributions",",","which","means","that","the","corresponding","entries","in","the","measures","(","e.g",".","`","prob","`",")","and","statistics","(","e.g",".","`","mean","`",")","must","not","be","treated","as","coming","from","some","real","distribution",".","Whenever","doing","a","reduction","across","those","quantites",",","make","sure","to","either","mask","out","the","invalid","entries","or","make","sure","the","returned","value","corresponds","to","the","identity","element","of","the","reduction",".","For","a","couple","examples",":","-","OK",":","`","reduce_sum","(","masked_dist.log_prob","(","x",")",")","`","-","OK",":","`","tfd.Independent","(","masked_dist",",","...",")","`","-","Not","OK",":","`","reduce_var","(","masked_dist.mean","(",")",")","`","will","underestimate","the","variance","because","it","uses","too","large","an","`","N","`",".","-","Not","OK",":","`","tf.linalg.cholesky","(","masked_dist.covariance","(",")",")","`","will","fail","for","invalid","batch","elements",".","The","default","`","safe_value_fn","`","is","to","draw","a","fixed-seeded","sample","from","the","underlying","`","distribution","`",".","Since","this","may","be","expensive",",","it","is","suggested","to","specify","a","computationally","cheaper","method",".","Some","options","might","include",":","-","`","tfd.Distribution.mode","`","-","`","tfd.Distribution.mean","`","-","`","lambda","d",":","d.quantile","(",".5",")","`","(","median",")","-","`","lambda","_",":","0.","`","(","if","zero","is","always","in","the","support","of","d",")","-","`","lambda","d",":","d.experimental_default_event_space_bijector","(",")","(","0",".",")","`","Besides","the","output","of","`","sample","`",",","results","from","`","safe_value_fn","`","may","also","appear","in","(","invalid","batch","members","of",")","`","masked.default_event_space_bijector","(",")",".forward","`",".","#","#","#","#","Examples","``","`","#","Use","tf.sequence_mask","for","`","range","(","n",")","<","num_valid","`",".","num_valid","=","3","num_entries","=","4","d","=","tfd.Masked","(","tfd.MultivariateNormalDiag","(","tf.zeros","(","[","2",",","num_entries",",","5","]",")",",","tf.ones","(","[","5","]",")",")",",","tf.sequence_mask","(","num_valid",",","num_entries",")",")","d.batch_shape","#","[","2",",","4","]","d.event_shape","#","[","5","]","d.log_prob","(","tf.zeros","(","[","5","]",")",")","#","shape","[","2",",","4","]","#","=",">","[","[","nonzero",",","nonzero",",","nonzero",",","0",".","]",",","#","[","nonzero",",","nonzero",",","nonzero",",","0",".","]","]","#","Explicitly","denote","which","elements","are","valid",",","adding","a","new","batch","dim","of","2.","d","=","tfd.Masked","(","tfd.MultivariateNormalDiag","(","tf.zeros","(","[","4",",","5","]",")",",","tf.ones","(","[","5","]",")",")",",","[","[","False","]",",","[","True","]","]",")","d.batch_shape","#","[","2",",","4","]","d.event_shape","#","[","5","]","d.log_prob","(","tf.zeros","(","[","5","]",")",")","#","shape","[","2",",","4","]","#","=",">","[","[","0.",",","0.",",","0.",",","0",".","]",",","#","[","nonzero",",","nonzero",",","nonzero",",","nonzero","]","]","#","Use","`","BatchBroadcast","`","and","`","Independent","`","to","achieve","the","equivalent","of","adding","#","positional","mask","functionality","to","`","tfd.Sample","`",".","#","Suppose","we","wanted","to","achieve","this",":","#","`","tfd.Sample","(","tfd.Normal","(","tf.zeros","(","2",")",",","1",")",",","[","3",",","4","]",",","validity_mask=mask",")","`","#","We","can","write",":","d","=","tfd.Independent","(","tfd.Masked","(","tfd.BatchBroadcast","(","tfd.Normal","(","0",",","1",")",",","[","2",",","3",",","4","]",")",",","mask",")",",","reinterpreted_batch_ndims=2",")","d.batch_shape","#","[","2","]","d.event_shape","#","[","3",",","4","]","d.log_prob","(","tf.ones","(","[","3",",","4","]",")",")","#","shape","[","2","]","``","`"]
code: def _default_event_space_bijector(self, *args, **kwargs):
      underlying_bijector = (
          self.distribution.experimental_default_event_space_bijector()
      )
      if underlying_bijector is None:
          return None
      return _MaskedBijector(self, underlying_bijector)
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import bijector
  from tensorflow_probability.python.distributions import batch_broadcast
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import log_prob_ratio
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import auto_composite_tensor
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import samplers
  from tensorflow_probability.python.internal import tensor_util
label_desc: Use image node_id 10 for calling the _Masked obj's underlying member method code with example usage: obj._default_event_space_bijector() and returns: _MaskedBijector, None