class_docstr: The multivariate normal distribution on `R^k`.
  
  The Multivariate Normal distribution is defined over `R^k` and parameterized
  by a (batch of) length-`k` `loc` vector (aka "mu") and a (batch of) `k x k`
  `scale` matrix; `covariance = scale @ scale.T`, where `@` denotes
  matrix-multiplication.
  
  #### Mathematical Details
  
  The probability density function (pdf) is,
  
  ```none
  pdf(x; loc, scale) = exp(-0.5 ||y||**2) / Z,
  y = inv(scale) @ (x - loc),
  Z = (2 pi)**(0.5 k) |det(scale)|,
  ```
  
  where:
  
  * `loc` is a vector in `R^k`,
  * `scale` is a linear operator in `R^{k x k}`, `cov = scale @ scale.T`,
  * `Z` denotes the normalization constant, and,
  * `||y||**2` denotes the squared Euclidean norm of `y`.
  
  The MultivariateNormal distribution is a member of the [location-scale
  family](https://en.wikipedia.org/wiki/Location-scale_family), i.e., it can be
  constructed as,
  
  ```none
  X ~ MultivariateNormal(loc=0, scale=1)   # Identity scale, zero shift.
  Y = scale @ X + loc
  ```
  
  #### Examples
  
  ```python
  tfd = tfp.distributions
  
  # Initialize a single 3-variate Gaussian.
  mu = [1., 2, 3]
  cov = [[ 0.36,  0.12,  0.06],
         [ 0.12,  0.29, -0.13],
         [ 0.06, -0.13,  0.26]]
  scale = tf.linalg.cholesky(cov)
  # ==> [[ 0.6,  0. ,  0. ],
  #      [ 0.2,  0.5,  0. ],
  #      [ 0.1, -0.3,  0.4]])
  
  mvn = tfd.MultivariateNormalLinearOperator(
      loc=mu,
      scale=tf.linalg.LinearOperatorLowerTriangular(scale))
  
  # Covariance agrees with cholesky(cov) parameterization.
  mvn.covariance()
  # ==> [[ 0.36,  0.12,  0.06],
  #      [ 0.12,  0.29, -0.13],
  #      [ 0.06, -0.13,  0.26]]
  
  # Compute the pdf of an`R^3` observation; return a scalar.
  mvn.prob([-1., 0, 1])  # shape: []
  
  # Initialize a 2-batch of 3-variate Gaussians.
  mu = [[1., 2, 3],
        [11, 22, 33]]              # shape: [2, 3]
  scale_diag = [[1., 2, 3],
                [0.5, 1, 1.5]]     # shape: [2, 3]
  
  mvn = tfd.MultivariateNormalLinearOperator(
      loc=mu,
      scale=tf.linalg.LinearOperatorDiag(scale_diag))
  
  # Compute the pdf of two `R^3` observations; return a length-2 vector.
  x = [[-0.9, 0, 0.1],
       [-10, 0, 9]]     # shape: [2, 3]
  mvn.prob(x)    # shape: [2]
  ```
class_docstr_tok: ["The","multivariate","normal","distribution","on","`","R^k","`",".","The","Multivariate","Normal","distribution","is","defined","over","`","R^k","`","and","parameterized","by","a","(","batch","of",")","length-","`","k","`","`","loc","`","vector","(","aka","``","mu","''",")","and","a","(","batch","of",")","`","k","x","k","`","`","scale","`","matrix",";","`","covariance","=","scale","@","scale.T","`",",","where","`","@","`","denotes","matrix-multiplication",".","#","#","#","#","Mathematical","Details","The","probability","density","function","(","pdf",")","is",",","``","`","none","pdf","(","x",";","loc",",","scale",")","=","exp","(","-0.5","||y||","*","*","2",")","\/","Z",",","y","=","inv","(","scale",")","@","(","x","-","loc",")",",","Z","=","(","2","pi",")","*","*","(","0.5","k",")","|det","(","scale",")","|",",","``","`","where",":","*","`","loc","`","is","a","vector","in","`","R^k","`",",","*","`","scale","`","is","a","linear","operator","in","`","R^","{","k","x","k","}","`",",","`","cov","=","scale","@","scale.T","`",",","*","`","Z","`","denotes","the","normalization","constant",",","and",",","*","`","||y||","*","*","2","`","denotes","the","squared","Euclidean","norm","of","`","y","`",".","The","MultivariateNormal","distribution","is","a","member","of","the","[","location-scale","family","]","(","https",":","\/\/en.wikipedia.org\/wiki\/Location-scale_family",")",",","i.e.",",","it","can","be","constructed","as",",","``","`","none","X","~","MultivariateNormal","(","loc=0",",","scale=1",")","#","Identity","scale",",","zero","shift",".","Y","=","scale","@","X","+","loc","``","`","#","#","#","#","Examples","``","`","python","tfd","=","tfp.distributions","#","Initialize","a","single","3-variate","Gaussian",".","mu","=","[","1.",",","2",",","3","]","cov","=","[","[","0.36",",","0.12",",","0.06","]",",","[","0.12",",","0.29",",","-0.13","]",",","[","0.06",",","-0.13",",","0.26","]","]","scale","=","tf.linalg.cholesky","(","cov",")","#","==",">","[","[","0.6",",","0.",",","0",".","]",",","#","[","0.2",",","0.5",",","0",".","]",",","#","[","0.1",",","-0.3",",","0.4","]","]",")","mvn","=","tfd.MultivariateNormalLinearOperator","(","loc=mu",",","scale=tf.linalg.LinearOperatorLowerTriangular","(","scale",")",")","#","Covariance","agrees","with","cholesky","(","cov",")","parameterization",".","mvn.covariance","(",")","#","==",">","[","[","0.36",",","0.12",",","0.06","]",",","#","[","0.12",",","0.29",",","-0.13","]",",","#","[","0.06",",","-0.13",",","0.26","]","]","#","Compute","the","pdf","of","an","`","R^3","`","observation",";","return","a","scalar",".","mvn.prob","(","[","-1.",",","0",",","1","]",")","#","shape",":","[","]","#","Initialize","a","2-batch","of","3-variate","Gaussians",".","mu","=","[","[","1.",",","2",",","3","]",",","[","11",",","22",",","33","]","]","#","shape",":","[","2",",","3","]","scale_diag","=","[","[","1.",",","2",",","3","]",",","[","0.5",",","1",",","1.5","]","]","#","shape",":","[","2",",","3","]","mvn","=","tfd.MultivariateNormalLinearOperator","(","loc=mu",",","scale=tf.linalg.LinearOperatorDiag","(","scale_diag",")",")","#","Compute","the","pdf","of","two","`","R^3","`","observations",";","return","a","length-2","vector",".","x","=","[","[","-0.9",",","0",",","0.1","]",",","[","-10",",","0",",","9","]","]","#","shape",":","[","2",",","3","]","mvn.prob","(","x",")","#","shape",":","[","2","]","``","`"]
docstr: Construct Multivariate Normal distribution on `R^k`.
  
  The `batch_shape` is the broadcast shape between `loc` and `scale`
  arguments.
  
  The `event_shape` is given by last dimension of the matrix implied by
  `scale`. The last dimension of `loc` (if provided) must broadcast with this.
  
  Recall that `covariance = scale @ scale.T`.
  
  Additional leading dimensions (if any) will index batches.
  
  Args:
    loc: Floating-point `Tensor`. If this is set to `None`, `loc` is
      implicitly `0`. When specified, may have shape `[B1, ..., Bb, k]` where
      `b >= 0` and `k` is the event size.
    scale: Instance of `LinearOperator` with same `dtype` as `loc` and shape
      `[B1, ..., Bb, k, k]`.
    validate_args: Python `bool`, default `False`. Whether to validate input
      with asserts. If `validate_args` is `False`, and the inputs are
      invalid, correct behavior is not guaranteed.
    allow_nan_stats: Python `bool`, default `True`. If `False`, raise an
      exception if a statistic (e.g. mean/mode/etc...) is undefined for any
      batch member If `True`, batch members with valid parameters leading to
      undefined statistics will return NaN for this statistic.
    experimental_use_kahan_sum: Python `bool`. When `True`, we use Kahan
      summation to aggregate independent underlying log_prob values. For best
      results, Kahan summation should also be applied when computing the
      log-determinant of the `LinearOperator` representing the scale matrix.
      Kahan summation improves against the precision of a naive float32 sum.
      This can be noticeable in particular for large dimensions in float32.
      See CPU caveat on `tfp.math.reduce_kahan_sum`.
    name: The name to give Ops created by the initializer.
  
  Raises:
    ValueError: if `scale` is unspecified.
    TypeError: if not `scale.dtype.is_floating`
docstr_tok: ["Construct","Multivariate","Normal","distribution","on","`","R^k","`",".","The","`","batch_shape","`","is","the","broadcast","shape","between","`","loc","`","and","`","scale","`","arguments",".","The","`","event_shape","`","is","given","by","last","dimension","of","the","matrix","implied","by","`","scale","`",".","The","last","dimension","of","`","loc","`","(","if","provided",")","must","broadcast","with","this",".","Recall","that","`","covariance","=","scale","@","scale.T","`",".","Additional","leading","dimensions","(","if","any",")","will","index","batches",".","Args",":","loc",":","Floating-point","`","Tensor","`",".","If","this","is","set","to","`","None","`",",","`","loc","`","is","implicitly","`","0","`",".","When","specified",",","may","have","shape","`","[","B1",",","...",",","Bb",",","k","]","`","where","`","b",">","=","0","`","and","`","k","`","is","the","event","size",".","scale",":","Instance","of","`","LinearOperator","`","with","same","`","dtype","`","as","`","loc","`","and","shape","`","[","B1",",","...",",","Bb",",","k",",","k","]","`",".","validate_args",":","Python","`","bool","`",",","default","`","False","`",".","Whether","to","validate","input","with","asserts",".","If","`","validate_args","`","is","`","False","`",",","and","the","inputs","are","invalid",",","correct","behavior","is","not","guaranteed",".","allow_nan_stats",":","Python","`","bool","`",",","default","`","True","`",".","If","`","False","`",",","raise","an","exception","if","a","statistic","(","e.g",".","mean\/mode\/etc","...",")","is","undefined","for","any","batch","member","If","`","True","`",",","batch","members","with","valid","parameters","leading","to","undefined","statistics","will","return","NaN","for","this","statistic",".","experimental_use_kahan_sum",":","Python","`","bool","`",".","When","`","True","`",",","we","use","Kahan","summation","to","aggregate","independent","underlying","log_prob","values",".","For","best","results",",","Kahan","summation","should","also","be","applied","when","computing","the","log-determinant","of","the","`","LinearOperator","`","representing","the","scale","matrix",".","Kahan","summation","improves","against","the","precision","of","a","naive","float32","sum",".","This","can","be","noticeable","in","particular","for","large","dimensions","in","float32",".","See","CPU","caveat","on","`","tfp.math.reduce_kahan_sum","`",".","name",":","The","name","to","give","Ops","created","by","the","initializer",".","Raises",":","ValueError",":","if","`","scale","`","is","unspecified",".","TypeError",":","if","not","`","scale.dtype.is_floating","`"]
code: def __init__(
      self,
      loc=None,
      scale=None,
      validate_args=False,
      allow_nan_stats=True,
      experimental_use_kahan_sum=False,
      name="MultivariateNormalLinearOperator",
  ):
      """Construct Multivariate Normal distribution on `R^k`.
  
      The `batch_shape` is the broadcast shape between `loc` and `scale`
      arguments.
  
      The `event_shape` is given by last dimension of the matrix implied by
      `scale`. The last dimension of `loc` (if provided) must broadcast with this.
  
      Recall that `covariance = scale @ scale.T`.
  
      Additional leading dimensions (if any) will index batches.
  
      Args:
        loc: Floating-point `Tensor`. If this is set to `None`, `loc` is
          implicitly `0`. When specified, may have shape `[B1, ..., Bb, k]` where
          `b >= 0` and `k` is the event size.
        scale: Instance of `LinearOperator` with same `dtype` as `loc` and shape
          `[B1, ..., Bb, k, k]`.
        validate_args: Python `bool`, default `False`. Whether to validate input
          with asserts. If `validate_args` is `False`, and the inputs are
          invalid, correct behavior is not guaranteed.
        allow_nan_stats: Python `bool`, default `True`. If `False`, raise an
          exception if a statistic (e.g. mean/mode/etc...) is undefined for any
          batch member If `True`, batch members with valid parameters leading to
          undefined statistics will return NaN for this statistic.
        experimental_use_kahan_sum: Python `bool`. When `True`, we use Kahan
          summation to aggregate independent underlying log_prob values. For best
          results, Kahan summation should also be applied when computing the
          log-determinant of the `LinearOperator` representing the scale matrix.
          Kahan summation improves against the precision of a naive float32 sum.
          This can be noticeable in particular for large dimensions in float32.
          See CPU caveat on `tfp.math.reduce_kahan_sum`.
        name: The name to give Ops created by the initializer.
  
      Raises:
        ValueError: if `scale` is unspecified.
        TypeError: if not `scale.dtype.is_floating`
      """
      parameters = dict(locals())
      self._experimental_use_kahan_sum = experimental_use_kahan_sum
      if scale is None:
          raise ValueError("Missing required `scale` parameter.")
      if not dtype_util.is_floating(scale.dtype):
          raise TypeError(
              "`scale` parameter must have floating-point dtype."
          )
  
      with tf.name_scope(name) as name:
          dtype = dtype_util.common_dtype(
              [loc, scale], dtype_hint=tf.float32
          )
          # Since expand_dims doesn't preserve constant-ness, we obtain the
          # non-dynamic value if possible.
          loc = tensor_util.convert_nonref_to_tensor(
              loc, dtype=dtype, name="loc"
          )
          (
              batch_shape,
              event_shape,
          ) = distribution_util.shapes_from_loc_and_scale(loc, scale)
      self._loc = loc
      self._scale = scale
  
      bijector = scale_matvec_linear_operator.ScaleMatvecLinearOperator(
          scale, validate_args=validate_args
      )
      if loc is not None:
          bijector = shift_bijector.Shift(
              shift=loc, validate_args=validate_args
          )(bijector)
      super(MultivariateNormalLinearOperator, self).__init__(
          # TODO(b/137665504): Use batch-adding meta-distribution to set the batch
          # shape instead of tf.zeros.
          # We use `Sample` instead of `Independent` because `Independent`
          # requires concatenating `batch_shape` and `event_shape`, which loses
          # static `batch_shape` information when `event_shape` is not statically
          # known.
          distribution=sample.Sample(
              normal.Normal(
                  loc=tf.zeros(batch_shape, dtype=dtype),
                  scale=tf.ones([], dtype=dtype),
              ),
              event_shape,
              experimental_use_kahan_sum=experimental_use_kahan_sum,
          ),
          bijector=bijector,
          validate_args=validate_args,
          name=name,
      )
      self._parameters = parameters
  
imports: import tensorflow.compat.v2
  from tensorflow_probability.python.bijectors import identity
  from tensorflow_probability.python.bijectors import scale_matvec_linear_operator
  from tensorflow_probability.python.bijectors import shift
  from tensorflow_probability.python.distributions import kullback_leibler
  from tensorflow_probability.python.distributions import normal
  from tensorflow_probability.python.distributions import sample
  from tensorflow_probability.python.distributions import transformed_distribution
  from tensorflow_probability.python.internal import distribution_util
  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 tensor_util
  from tensorflow_probability.python.internal import tensorshape_util
label_desc: Use image node_id 1 to create a new MultivariateNormalLinearOperator object from inherited base classes: transformed_distribution with example: obj = MultivariateNormalLinearOperator(loc, scale, validate_args, allow_nan_stats, experimental_use_kahan_sum, name)