class_docstr: A Transformed Distribution.
  
  A `TransformedDistribution` models `p(y)` given a base distribution `p(x)`,
  and a deterministic, invertible, differentiable transform, `Y = g(X)`. The
  transform is typically an instance of the `Bijector` class and the base
  distribution is typically an instance of the `Distribution` class.
  
  A `Bijector` is expected to implement the following functions:
  
  - `forward`,
  - `inverse`,
  - `inverse_log_det_jacobian`.
  
  The semantics of these functions are outlined in the `Bijector` documentation.
  
  We now describe how a `TransformedDistribution` alters the input/outputs of a
  `Distribution` associated with a random variable (rv) `X`.
  
  Write `cdf(Y=y)` for an absolutely continuous cumulative distribution function
  of random variable `Y`; write the probability density function
  `pdf(Y=y) := d^k / (dy_1,...,dy_k) cdf(Y=y)` for its derivative wrt to `Y`
  evaluated at `y`. Assume that `Y = g(X)` where `g` is a deterministic
  diffeomorphism, i.e., a non-random, continuous, differentiable, and invertible
  function.  Write the inverse of `g` as `X = g^{-1}(Y)` and `(J o g)(x)` for
  the Jacobian of `g` evaluated at `x`.
  
  A `TransformedDistribution` implements the following operations:
  
    * `sample`
      Mathematically:   `Y = g(X)`
      Programmatically: `bijector.forward(distribution.sample(...))`
  
    * `log_prob`
      Mathematically:   `(log o pdf)(Y=y) = (log o pdf o g^{-1})(y)
                         + (log o abs o det o J o g^{-1})(y)`
      Programmatically: `(distribution.log_prob(bijector.inverse(y))
                         + bijector.inverse_log_det_jacobian(y))`
  
    * `log_cdf`
      Mathematically:   `(log o cdf)(Y=y) = (log o cdf o g^{-1})(y)`
      Programmatically: `distribution.log_cdf(bijector.inverse(x))`
  
    * and similarly for: `cdf`, `prob`, `log_survival_function`,
     `survival_function`.
  
  Kullback-Leibler divergence is also well defined for `TransformedDistribution`
  instances that have matching bijectors.  Bijector matching is performed via
  the `Bijector.__eq__` method, e.g., `td1.bijector == td2.bijector`, as part
  of the KL calculation.  If the underlying bijectors do not match, a
  `NotImplementedError` is raised when calling `kl_divergence`.  This is the
  same behavior as calling `kl_divergence` when two distributions do not have
  a registered KL divergence.
  
  **Note** Due to the current constraints imposed on bijector equality testing,
  `kl_divergence` may behave differently in eager mode computation vs. traced
  computation.  For example, if a TD Bijector's parameters are `Tensor` objects,
  and are themselves derived from e.g. a Variable, some stateful operation, or
  from an argument to a `tf.function` then Bijector equality cannot be known
  during the call to `kl_divergence` and the bijectors are assumed unequal.
  In this case, calling `kl_divergence` may raise an exception in
  graph / tf.function mode, but work just fine in eager / numpy mode.
  
  A simple example constructing a Log-Normal distribution from a Normal
  distribution:
  
  ```python
  tfd = tfp.distributions
  tfb = tfp.bijectors
  log_normal = tfd.TransformedDistribution(
    distribution=tfd.Normal(loc=0., scale=1.),
    bijector=tfb.Exp(),
    name='LogNormalTransformedDistribution')
  ```
  
  A `LogNormal` made from callables:
  
  ```python
  tfd = tfp.distributions
  tfb = tfp.bijectors
  log_normal = tfd.TransformedDistribution(
    distribution=tfd.Normal(loc=0., scale=1.),
    bijector=tfb.Inline(
      forward_fn=tf.exp,
      inverse_fn=tf.log,
      inverse_log_det_jacobian_fn=(
        lambda y: -tf.reduce_sum(tf.log(y), axis=-1)),
    name='LogNormalTransformedDistribution')
  ```
  
  Another example constructing a Normal from a StandardNormal:
  
  ```python
  tfd = tfp.distributions
  tfb = tfp.bijectors
  normal = tfd.TransformedDistribution(
    distribution=tfd.Normal(loc=0., scale=1.),
    bijector=tfb.Shift(shift=-1.)(tfb.Scale(scale=2.)),
    name='NormalTransformedDistribution')
  ```
  
  A `TransformedDistribution`'s `batch_shape` is derived by *broadcasting* the
  batch shapes of the base distribution and the bijector. The base distribution
  is then itself implicitly lifted to the broadcast batch shape. For example, in
  
  ```python
  tfd = tfp.distributions
  tfb = tfp.bijectors
  batch_normal = tfd.TransformedDistribution(
    distribution=tfd.Normal(loc=0., scale=1.),
    bijector=tfb.Shift(shift=[-1., 0., 1.]),
    name='BatchNormalTransformedDistribution')
  ```
  
  the base distribution has batch shape `[]`, and the bijector applied to this
  distribution contributes a batch shape of `[3]` (obtained as
  `bijector.experimental_batch_shape(
  x_event_ndims=tf.rank(distribution.event_shape))`, yielding the broadcast
  shape `batch_normal.batch_shape == [3]`. Although sampling from the base
  distribution would ordinarily return just a single value, calling
  `batch_normal.sample()` will return a Tensor of 3 independent values, just as
  if the base distribution had explicitly followed the broadcast batch shape.
  
  The `event_shape` of a `TransformedDistribution` is the `forward_event_shape`
  of the bijector applied to the `event_shape` of the base distribution.
  
  `tfd.Sample` or `tfd.Independent` may be used to add extra IID dimensions to
  the `event_shape` of the base distribution before the bijector operates on it.
  The following example demonstrates how to construct a multivariate Normal as a
  `TransformedDistribution`, by adding a rank-1 IID dimension to the
  `event_shape` of a standard Normal and applying `tfb.ScaleMatvecTriL`.
  
  ```python
  tfd = tfp.distributions
  tfb = tfp.bijectors
  # We will create two MVNs with batch_shape = event_shape = 2.
  mean = [[-1., 0],      # batch:0
          [0., 1]]       # batch:1
  chol_cov = [[[1., 0],
               [0, 1]],  # batch:0
              [[1, 0],
               [2, 2]]]  # batch:1
  mvn1 = tfd.TransformedDistribution(
      distribution=tfd.Sample(
          tfd.Normal(loc=[0., 0], scale=1.),  # base_dist.batch_shape == [2]
          sample_shape=[2])                   # base_dist.event_shape == [2]
      bijector=tfb.Shift(shift=mean)(tfb.ScaleMatvecTriL(scale_tril=chol_cov)))
  mvn2 = ds.MultivariateNormalTriL(loc=mean, scale_tril=chol_cov)
  # mvn1.log_prob(x) == mvn2.log_prob(x)
  ```
class_docstr_tok: ["A","Transformed","Distribution",".","A","`","TransformedDistribution","`","models","`","p","(","y",")","`","given","a","base","distribution","`","p","(","x",")","`",",","and","a","deterministic",",","invertible",",","differentiable","transform",",","`","Y","=","g","(","X",")","`",".","The","transform","is","typically","an","instance","of","the","`","Bijector","`","class","and","the","base","distribution","is","typically","an","instance","of","the","`","Distribution","`","class",".","A","`","Bijector","`","is","expected","to","implement","the","following","functions",":","-","`","forward","`",",","-","`","inverse","`",",","-","`","inverse_log_det_jacobian","`",".","The","semantics","of","these","functions","are","outlined","in","the","`","Bijector","`","documentation",".","We","now","describe","how","a","`","TransformedDistribution","`","alters","the","input\/outputs","of","a","`","Distribution","`","associated","with","a","random","variable","(","rv",")","`","X","`",".","Write","`","cdf","(","Y=y",")","`","for","an","absolutely","continuous","cumulative","distribution","function","of","random","variable","`","Y","`",";","write","the","probability","density","function","`","pdf","(","Y=y",")",":","=","d^k","\/","(","dy_1",",","...",",","dy_k",")","cdf","(","Y=y",")","`","for","its","derivative","wrt","to","`","Y","`","evaluated","at","`","y","`",".","Assume","that","`","Y","=","g","(","X",")","`","where","`","g","`","is","a","deterministic","diffeomorphism",",","i.e.",",","a","non-random",",","continuous",",","differentiable",",","and","invertible","function",".","Write","the","inverse","of","`","g","`","as","`","X","=","g^","{","-1","}","(","Y",")","`","and","`","(","J","o","g",")","(","x",")","`","for","the","Jacobian","of","`","g","`","evaluated","at","`","x","`",".","A","`","TransformedDistribution","`","implements","the","following","operations",":","*","`","sample","`","Mathematically",":","`","Y","=","g","(","X",")","`","Programmatically",":","`","bijector.forward","(","distribution.sample","(","...",")",")","`","*","`","log_prob","`","Mathematically",":","`","(","log","o","pdf",")","(","Y=y",")","=","(","log","o","pdf","o","g^","{","-1","}",")","(","y",")","+","(","log","o","abs","o","det","o","J","o","g^","{","-1","}",")","(","y",")","`","Programmatically",":","`","(","distribution.log_prob","(","bijector.inverse","(","y",")",")","+","bijector.inverse_log_det_jacobian","(","y",")",")","`","*","`","log_cdf","`","Mathematically",":","`","(","log","o","cdf",")","(","Y=y",")","=","(","log","o","cdf","o","g^","{","-1","}",")","(","y",")","`","Programmatically",":","`","distribution.log_cdf","(","bijector.inverse","(","x",")",")","`","*","and","similarly","for",":","`","cdf","`",",","`","prob","`",",","`","log_survival_function","`",",","`","survival_function","`",".","Kullback-Leibler","divergence","is","also","well","defined","for","`","TransformedDistribution","`","instances","that","have","matching","bijectors",".","Bijector","matching","is","performed","via","the","`","Bijector.__eq__","`","method",",","e.g.",",","`","td1.bijector","==","td2.bijector","`",",","as","part","of","the","KL","calculation",".","If","the","underlying","bijectors","do","not","match",",","a","`","NotImplementedError","`","is","raised","when","calling","`","kl_divergence","`",".","This","is","the","same","behavior","as","calling","`","kl_divergence","`","when","two","distributions","do","not","have","a","registered","KL","divergence",".","*","*","Note","*","*","Due","to","the","current","constraints","imposed","on","bijector","equality","testing",",","`","kl_divergence","`","may","behave","differently","in","eager","mode","computation","vs.","traced","computation",".","For","example",",","if","a","TD","Bijector","'s","parameters","are","`","Tensor","`","objects",",","and","are","themselves","derived","from","e.g",".","a","Variable",",","some","stateful","operation",",","or","from","an","argument","to","a","`","tf.function","`","then","Bijector","equality","can","not","be","known","during","the","call","to","`","kl_divergence","`","and","the","bijectors","are","assumed","unequal",".","In","this","case",",","calling","`","kl_divergence","`","may","raise","an","exception","in","graph","\/","tf.function","mode",",","but","work","just","fine","in","eager","\/","numpy","mode",".","A","simple","example","constructing","a","Log-Normal","distribution","from","a","Normal","distribution",":","``","`","python","tfd","=","tfp.distributions","tfb","=","tfp.bijectors","log_normal","=","tfd.TransformedDistribution","(","distribution=tfd.Normal","(","loc=0.",",","scale=1",".",")",",","bijector=tfb.Exp","(",")",",","name='LogNormalTransformedDistribution","'",")","``","`","A","`","LogNormal","`","made","from","callables",":","``","`","python","tfd","=","tfp.distributions","tfb","=","tfp.bijectors","log_normal","=","tfd.TransformedDistribution","(","distribution=tfd.Normal","(","loc=0.",",","scale=1",".",")",",","bijector=tfb.Inline","(","forward_fn=tf.exp",",","inverse_fn=tf.log",",","inverse_log_det_jacobian_fn=","(","lambda","y",":","-tf.reduce_sum","(","tf.log","(","y",")",",","axis=-1",")",")",",","name='LogNormalTransformedDistribution","'",")","``","`","Another","example","constructing","a","Normal","from","a","StandardNormal",":","``","`","python","tfd","=","tfp.distributions","tfb","=","tfp.bijectors","normal","=","tfd.TransformedDistribution","(","distribution=tfd.Normal","(","loc=0.",",","scale=1",".",")",",","bijector=tfb.Shift","(","shift=-1.",")","(","tfb.Scale","(","scale=2",".",")",")",",","name='NormalTransformedDistribution","'",")","``","`","A","`","TransformedDistribution","`","'s","`","batch_shape","`","is","derived","by","*","broadcasting","*","the","batch","shapes","of","the","base","distribution","and","the","bijector",".","The","base","distribution","is","then","itself","implicitly","lifted","to","the","broadcast","batch","shape",".","For","example",",","in","``","`","python","tfd","=","tfp.distributions","tfb","=","tfp.bijectors","batch_normal","=","tfd.TransformedDistribution","(","distribution=tfd.Normal","(","loc=0.",",","scale=1",".",")",",","bijector=tfb.Shift","(","shift=","[","-1.",",","0.",",","1",".","]",")",",","name='BatchNormalTransformedDistribution","'",")","``","`","the","base","distribution","has","batch","shape","`","[","]","`",",","and","the","bijector","applied","to","this","distribution","contributes","a","batch","shape","of","`","[","3","]","`","(","obtained","as","`","bijector.experimental_batch_shape","(","x_event_ndims=tf.rank","(","distribution.event_shape",")",")","`",",","yielding","the","broadcast","shape","`","batch_normal.batch_shape","==","[","3","]","`",".","Although","sampling","from","the","base","distribution","would","ordinarily","return","just","a","single","value",",","calling","`","batch_normal.sample","(",")","`","will","return","a","Tensor","of","3","independent","values",",","just","as","if","the","base","distribution","had","explicitly","followed","the","broadcast","batch","shape",".","The","`","event_shape","`","of","a","`","TransformedDistribution","`","is","the","`","forward_event_shape","`","of","the","bijector","applied","to","the","`","event_shape","`","of","the","base","distribution",".","`","tfd.Sample","`","or","`","tfd.Independent","`","may","be","used","to","add","extra","IID","dimensions","to","the","`","event_shape","`","of","the","base","distribution","before","the","bijector","operates","on","it",".","The","following","example","demonstrates","how","to","construct","a","multivariate","Normal","as","a","`","TransformedDistribution","`",",","by","adding","a","rank-1","IID","dimension","to","the","`","event_shape","`","of","a","standard","Normal","and","applying","`","tfb.ScaleMatvecTriL","`",".","``","`","python","tfd","=","tfp.distributions","tfb","=","tfp.bijectors","#","We","will","create","two","MVNs","with","batch_shape","=","event_shape","=","2.","mean","=","[","[","-1.",",","0","]",",","#","batch:0","[","0.",",","1","]","]","#","batch:1","chol_cov","=","[","[","[","1.",",","0","]",",","[","0",",","1","]","]",",","#","batch:0","[","[","1",",","0","]",",","[","2",",","2","]","]","]","#","batch:1","mvn1","=","tfd.TransformedDistribution","(","distribution=tfd.Sample","(","tfd.Normal","(","loc=","[","0.",",","0","]",",","scale=1",".",")",",","#","base_dist.batch_shape","==","[","2","]","sample_shape=","[","2","]",")","#","base_dist.event_shape","==","[","2","]","bijector=tfb.Shift","(","shift=mean",")","(","tfb.ScaleMatvecTriL","(","scale_tril=chol_cov",")",")",")","mvn2","=","ds.MultivariateNormalTriL","(","loc=mean",",","scale_tril=chol_cov",")","#","mvn1.log_prob","(","x",")","==","mvn2.log_prob","(","x",")","``","`"]
code: def _quantile(self, value, **kwargs):
      if (
          not self.bijector._is_injective
      ):  # pylint: disable=protected-access
          raise NotImplementedError(
              "`quantile` is not implemented when "
              "`bijector` is not injective."
          )
      distribution_kwargs, bijector_kwargs = self._kwargs_split_fn(
          kwargs
      )
      value = ps.smart_where(
          self.bijector._internal_is_increasing(
              **bijector_kwargs
          ),  # pylint: disable=protected-access
          lambda: value,
          lambda: 1 - value,
      )
      # x_q is the "qth quantile" of X iff q = P[X <= x_q].  Now, since X =
      # g^{-1}(Y), q = P[X <= x_q] = P[g^{-1}(Y) <= x_q] = P[Y <= g(x_q)],
      # implies the qth quantile of Y is g(x_q).
      inv_cdf = self.distribution.quantile(value, **distribution_kwargs)
      return self.bijector.forward(inv_cdf, **bijector_kwargs)
  
imports: import functools
  import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import ldj_ratio
  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 auto_composite_tensor
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import parameter_properties
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 19 for calling the _TransformedDistribution obj's underlying member method code with example usage: obj._quantile(value) and returns: self