class_docstr: RelaxedBernoulli distribution with temperature and logits parameters.
  
  The RelaxedBernoulli is a distribution over the unit interval (0,1), which
  continuously approximates a Bernoulli. The degree of approximation is
  controlled by a temperature: as the temperature goes to 0 the
  RelaxedBernoulli becomes discrete with a distribution described by the
  `logits` or `probs` parameters, as the temperature goes to infinity the
  RelaxedBernoulli becomes the constant distribution that is identically 0.5.
  
  The RelaxedBernoulli distribution is a reparameterized continuous
  distribution that is the binary special case of the RelaxedOneHotCategorical
  distribution (Maddison et al., 2016; Jang et al., 2016). For details on the
  binary special case see the appendix of Maddison et al. (2016) where it is
  referred to as BinConcrete. If you use this distribution, please cite both
  papers.
  
  Some care needs to be taken for loss functions that depend on the
  log-probability of RelaxedBernoullis, because computing log-probabilities of
  the RelaxedBernoulli can suffer from underflow issues. In many case loss
  functions such as these are invariant under invertible transformations of
  the random variables. The KL divergence, found in the variational autoencoder
  loss, is an example. Because RelaxedBernoullis are sampled by a Logistic
  random variable followed by a `tf.sigmoid` op, one solution is to treat
  the Logistic as the random variable and `tf.sigmoid` as downstream. The
  KL divergences of two Logistics, which are always followed by a `tf.sigmoid`
  op, is equivalent to evaluating KL divergences of RelaxedBernoulli samples.
  See Maddison et al., 2016 for more details where this distribution is called
  the BinConcrete.
  
  An alternative approach is to evaluate Bernoulli log probability or KL
  directly on relaxed samples, as done in Jang et al., 2016. In this case,
  guarantees on the loss are usually violated. For instance, using a Bernoulli
  KL in a relaxed ELBO is no longer a lower bound on the log marginal
  probability of the observation. Thus care and early stopping are important.
  
  #### Examples
  
  Creates three continuous distributions, which approximate 3 Bernoullis with
  probabilities (0.1, 0.5, 0.4). Samples from these distributions will be in
  the unit interval (0,1).
  
  ```python
  temperature = 0.5
  p = [0.1, 0.5, 0.4]
  dist = RelaxedBernoulli(temperature, probs=p)
  ```
  
  Creates three continuous distributions, which approximate 3 Bernoullis with
  logits (-2, 2, 0). Samples from these distributions will be in
  the unit interval (0,1).
  
  ```python
  temperature = 0.5
  logits = [-2, 2, 0]
  dist = RelaxedBernoulli(temperature, logits=logits)
  ```
  
  Creates three continuous distributions, whose sigmoid approximate 3 Bernoullis
  with logits (-2, 2, 0).
  
  ```python
  temperature = 0.5
  logits = [-2, 2, 0]
  dist = Logistic(logits/temperature, 1./temperature)
  samples = dist.sample()
  sigmoid_samples = tf.sigmoid(samples)
  # sigmoid_samples has the same distribution as samples from
  # RelaxedBernoulli(temperature, logits=logits)
  ```
  
  Creates three continuous distributions, which approximate 3 Bernoullis with
  logits (-2, 2, 0). Samples from these distributions will be in
  the unit interval (0,1). Because the temperature is very low, samples from
  these distributions are almost discrete, usually taking values very close to 0
  or 1.
  
  ```python
  temperature = 1e-5
  logits = [-2, 2, 0]
  dist = RelaxedBernoulli(temperature, logits=logits)
  ```
  
  Creates three continuous distributions, which approximate 3 Bernoullis with
  logits (-2, 2, 0). Samples from these distributions will be in
  the unit interval (0,1). Because the temperature is very high, samples from
  these distributions are usually close to the (0.5, 0.5, 0.5) vector.
  
  ```python
  temperature = 100
  logits = [-2, 2, 0]
  dist = RelaxedBernoulli(temperature, logits=logits)
  ```
  
  Chris J. Maddison, Andriy Mnih, and Yee Whye Teh. The Concrete Distribution:
  A Continuous Relaxation of Discrete Random Variables. 2016.
  
  Eric Jang, Shixiang Gu, and Ben Poole. Categorical Reparameterization with
  Gumbel-Softmax. 2016.
class_docstr_tok: ["RelaxedBernoulli","distribution","with","temperature","and","logits","parameters",".","The","RelaxedBernoulli","is","a","distribution","over","the","unit","interval","(","0,1",")",",","which","continuously","approximates","a","Bernoulli",".","The","degree","of","approximation","is","controlled","by","a","temperature",":","as","the","temperature","goes","to","0","the","RelaxedBernoulli","becomes","discrete","with","a","distribution","described","by","the","`","logits","`","or","`","probs","`","parameters",",","as","the","temperature","goes","to","infinity","the","RelaxedBernoulli","becomes","the","constant","distribution","that","is","identically","0.5",".","The","RelaxedBernoulli","distribution","is","a","reparameterized","continuous","distribution","that","is","the","binary","special","case","of","the","RelaxedOneHotCategorical","distribution","(","Maddison","et","al.",",","2016",";","Jang","et","al.",",","2016",")",".","For","details","on","the","binary","special","case","see","the","appendix","of","Maddison","et","al",".","(","2016",")","where","it","is","referred","to","as","BinConcrete",".","If","you","use","this","distribution",",","please","cite","both","papers",".","Some","care","needs","to","be","taken","for","loss","functions","that","depend","on","the","log-probability","of","RelaxedBernoullis",",","because","computing","log-probabilities","of","the","RelaxedBernoulli","can","suffer","from","underflow","issues",".","In","many","case","loss","functions","such","as","these","are","invariant","under","invertible","transformations","of","the","random","variables",".","The","KL","divergence",",","found","in","the","variational","autoencoder","loss",",","is","an","example",".","Because","RelaxedBernoullis","are","sampled","by","a","Logistic","random","variable","followed","by","a","`","tf.sigmoid","`","op",",","one","solution","is","to","treat","the","Logistic","as","the","random","variable","and","`","tf.sigmoid","`","as","downstream",".","The","KL","divergences","of","two","Logistics",",","which","are","always","followed","by","a","`","tf.sigmoid","`","op",",","is","equivalent","to","evaluating","KL","divergences","of","RelaxedBernoulli","samples",".","See","Maddison","et","al.",",","2016","for","more","details","where","this","distribution","is","called","the","BinConcrete",".","An","alternative","approach","is","to","evaluate","Bernoulli","log","probability","or","KL","directly","on","relaxed","samples",",","as","done","in","Jang","et","al.",",","2016",".","In","this","case",",","guarantees","on","the","loss","are","usually","violated",".","For","instance",",","using","a","Bernoulli","KL","in","a","relaxed","ELBO","is","no","longer","a","lower","bound","on","the","log","marginal","probability","of","the","observation",".","Thus","care","and","early","stopping","are","important",".","#","#","#","#","Examples","Creates","three","continuous","distributions",",","which","approximate","3","Bernoullis","with","probabilities","(","0.1",",","0.5",",","0.4",")",".","Samples","from","these","distributions","will","be","in","the","unit","interval","(","0,1",")",".","``","`","python","temperature","=","0.5","p","=","[","0.1",",","0.5",",","0.4","]","dist","=","RelaxedBernoulli","(","temperature",",","probs=p",")","``","`","Creates","three","continuous","distributions",",","which","approximate","3","Bernoullis","with","logits","(","-2",",","2",",","0",")",".","Samples","from","these","distributions","will","be","in","the","unit","interval","(","0,1",")",".","``","`","python","temperature","=","0.5","logits","=","[","-2",",","2",",","0","]","dist","=","RelaxedBernoulli","(","temperature",",","logits=logits",")","``","`","Creates","three","continuous","distributions",",","whose","sigmoid","approximate","3","Bernoullis","with","logits","(","-2",",","2",",","0",")",".","``","`","python","temperature","=","0.5","logits","=","[","-2",",","2",",","0","]","dist","=","Logistic","(","logits\/temperature",",","1.\/temperature",")","samples","=","dist.sample","(",")","sigmoid_samples","=","tf.sigmoid","(","samples",")","#","sigmoid_samples","has","the","same","distribution","as","samples","from","#","RelaxedBernoulli","(","temperature",",","logits=logits",")","``","`","Creates","three","continuous","distributions",",","which","approximate","3","Bernoullis","with","logits","(","-2",",","2",",","0",")",".","Samples","from","these","distributions","will","be","in","the","unit","interval","(","0,1",")",".","Because","the","temperature","is","very","low",",","samples","from","these","distributions","are","almost","discrete",",","usually","taking","values","very","close","to","0","or","1",".","``","`","python","temperature","=","1e-5","logits","=","[","-2",",","2",",","0","]","dist","=","RelaxedBernoulli","(","temperature",",","logits=logits",")","``","`","Creates","three","continuous","distributions",",","which","approximate","3","Bernoullis","with","logits","(","-2",",","2",",","0",")",".","Samples","from","these","distributions","will","be","in","the","unit","interval","(","0,1",")",".","Because","the","temperature","is","very","high",",","samples","from","these","distributions","are","usually","close","to","the","(","0.5",",","0.5",",","0.5",")","vector",".","``","`","python","temperature","=","100","logits","=","[","-2",",","2",",","0","]","dist","=","RelaxedBernoulli","(","temperature",",","logits=logits",")","``","`","Chris","J.","Maddison",",","Andriy","Mnih",",","and","Yee","Whye","Teh",".","The","Concrete","Distribution",":","A","Continuous","Relaxation","of","Discrete","Random","Variables",".","2016",".","Eric","Jang",",","Shixiang","Gu",",","and","Ben","Poole",".","Categorical","Reparameterization","with","Gumbel-Softmax",".","2016","."]
code: def _log_prob(self, y, **kwargs):
      # The computation below is the same as
      # `self._transformed_logistic().log_prob(y, **kwargs)`. However, when `y`
      # approaches `0` or `1` it encounters numerical problems. Namely,
      # the Jacobian correction in `TransformedDistribution` becomes large in
      # absolute value, and catastrophically cancels against a similar term in the
      # `log_prob`. Instead, we collapse this computation below, and do the
      # cancellation symbolically.
      # The below also handles the case where `logits` goes to
      # `+-inf`, which also returns `NaN` when using `TransformedDistribution`
  
      logits_parameter = self._logits_parameter_no_checks()
      logits_y = tf.math.log(y) - tf.math.log1p(-y)
      t = tf.convert_to_tensor(self._temperature)
      z = logits_parameter - t * logits_y
      result = tf.where(
          z > 0,
          -logits_parameter
          + tf.math.xlogy(t - 1.0, y)
          - (t + 1.0) * tf.math.log1p(-y)
          - 2 * tf.math.softplus(-z),
          logits_parameter
          - (t + 1.0) * tf.math.log(y)
          + tf.math.xlog1py(t - 1.0, -y)
          - 2 * tf.math.softplus(z),
      ) + tf.math.log(t)
      return tf.where(
          # Handle the case where `logits_parameter` is infinite. This corresponds
          # to a `Bernoulli` with all mass centered at `0` or `1`. The above
          # computation returns `NaN` values when `y = 0` or `y = 1`, so we
          # explicitly handle this here.
          tf.math.is_inf(logits_parameter)
          & tf.math.is_inf(logits_y)
          & ~tf.math.is_nan(logits_parameter)
          & ~tf.math.is_nan(logits_y),
          tf.where(
              tf.math.equal(
                  tf.math.sign(logits_parameter), tf.math.sign(logits_y)
              ),
              dtype_util.as_numpy_dtype(self.dtype)(np.inf),
              dtype_util.as_numpy_dtype(self.dtype)(-np.inf),
          ),
          result,
      )
  
imports: import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import sigmoid
  from tensorflow_probability.python.bijectors import softplus
  from tensorflow_probability.python.distributions import distribution
  from tensorflow_probability.python.distributions import logistic
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import assert_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import reparameterization
  from tensorflow_probability.python.internal import tensor_util
label_desc: Use image node_id 14 for calling the RelaxedBernoulli obj's underlying member method code with example usage: obj._log_prob(y) and returns: tf