class_docstr: Adapts the inner kernel's `momentum_distribution` to estimated variance.
  
  This kernel uses an online variance estimate to adjust a diagonal covariance
  matrix for each of the state parts. More specifically, the
  `momentum_distribution` of the innermost kernel is set to a diagonal
  multivariate normal distribution whose variance is the *inverse* of the
  online estimate. The inverse of the covariance of the momentum is often called
  the "mass matrix" in the context of Hamiltonian Monte Carlo.
  
  This preconditioning scheme works well when the covariance is diagonally
  dominant, and may give reasonable results even when the number of draws is
  less than the dimension. In particular, it should generally do a better job
  than no preconditioning, which implicitly uses an identity mass matrix.
  
  Note that this kernel does not implement a calibrated sampler; rather, it is
  intended to be used as one step of an iterative adaptation process. It
  should not be used when drawing actual samples.
class_docstr_tok: ["Adapts","the","inner","kernel","'s","`","momentum_distribution","`","to","estimated","variance",".","This","kernel","uses","an","online","variance","estimate","to","adjust","a","diagonal","covariance","matrix","for","each","of","the","state","parts",".","More","specifically",",","the","`","momentum_distribution","`","of","the","innermost","kernel","is","set","to","a","diagonal","multivariate","normal","distribution","whose","variance","is","the","*","inverse","*","of","the","online","estimate",".","The","inverse","of","the","covariance","of","the","momentum","is","often","called","the","``","mass","matrix","''","in","the","context","of","Hamiltonian","Monte","Carlo",".","This","preconditioning","scheme","works","well","when","the","covariance","is","diagonally","dominant",",","and","may","give","reasonable","results","even","when","the","number","of","draws","is","less","than","the","dimension",".","In","particular",",","it","should","generally","do","a","better","job","than","no","preconditioning",",","which","implicitly","uses","an","identity","mass","matrix",".","Note","that","this","kernel","does","not","implement","a","calibrated","sampler",";","rather",",","it","is","intended","to","be","used","as","one","step","of","an","iterative","adaptation","process",".","It","should","not","be","used","when","drawing","actual","samples","."]
docstr: Creates the diagonal mass matrix adaptation kernel.
  
  Users must provide an `initial_running_variance`, either from a previous
  `DiagonalMassMatrixAdaptation`, or some other source. See
  `RunningCovariance.from_stats` for a convenient way to construct these.
  
  
  Args:
    inner_kernel: `TransitionKernel`-like object.
    initial_running_variance:
      `tfp.experimental.stats.RunningVariance`-like object, or list of them,
      for a batch of momentum distributions. These use `update` on the state
      to maintain an estimate of the variance, and so space, and so must have
      a structure compatible with the state space.
    num_estimation_steps: An optional scalar `int` `Tensor` number of initial
      steps to during which to adjust the running variance. This may be
      greater, less than, or equal to the number of burnin steps. If this
      argument is None, the mass matrix will be updated at each `one_step`
      call. Otherwise, the mass matrix will be updated when the current step
      is equal to `num_estimation_steps`.
    momentum_distribution_setter_fn: A callable with the signature
      `(kernel_results, new_momentum_distribution) -> new_kernel_results`
      where `kernel_results` are the results of the `inner_kernel`,
      `new_momentum_distribution` is a `CompositeTensor` or a nested
      collection of `CompositeTensor`s, and `new_kernel_results` are a
      possibly-modified copy of `kernel_results`. The default,
      `hmc_like_momentum_distribution_setter_fn`, presumes HMC-style
      `kernel_results`, and sets the `momentum_distribution` only under the
      `accepted_results` field.
    momentum_distribution_getter_fn: A callable with the signature
      `kernel_results -> momentum_distribution`
      where `kernel_results` are the results of the `inner_kernel` and
      `momentum_distribution` is a `CompositeTensor` or a nested
      collection of `CompositeTensor`s. The default,
      `hmc_like_momentum_distribution_getter_fn`, presumes HMC-style
      `kernel_results`, and gets the `momentum_distribution` only under the
      `accepted_results` field.
    validate_args: Python `bool`. When `True` kernel parameters are checked
      for validity. When `False` invalid inputs may silently render incorrect
      outputs.
    experimental_shard_axis_names: An optional structure of string names
      indicating how members of the state are sharded.
    name: Python `str` name prefixed to Ops created by this class. Default:
      'diagonal_mass_matrix_adaptation'.
docstr_tok: ["Creates","the","diagonal","mass","matrix","adaptation","kernel",".","Users","must","provide","an","`","initial_running_variance","`",",","either","from","a","previous","`","DiagonalMassMatrixAdaptation","`",",","or","some","other","source",".","See","`","RunningCovariance.from_stats","`","for","a","convenient","way","to","construct","these",".","Args",":","inner_kernel",":","`","TransitionKernel","`","-like","object",".","initial_running_variance",":","`","tfp.experimental.stats.RunningVariance","`","-like","object",",","or","list","of","them",",","for","a","batch","of","momentum","distributions",".","These","use","`","update","`","on","the","state","to","maintain","an","estimate","of","the","variance",",","and","so","space",",","and","so","must","have","a","structure","compatible","with","the","state","space",".","num_estimation_steps",":","An","optional","scalar","`","int","`","`","Tensor","`","number","of","initial","steps","to","during","which","to","adjust","the","running","variance",".","This","may","be","greater",",","less","than",",","or","equal","to","the","number","of","burnin","steps",".","If","this","argument","is","None",",","the","mass","matrix","will","be","updated","at","each","`","one_step","`","call",".","Otherwise",",","the","mass","matrix","will","be","updated","when","the","current","step","is","equal","to","`","num_estimation_steps","`",".","momentum_distribution_setter_fn",":","A","callable","with","the","signature","`","(","kernel_results",",","new_momentum_distribution",")","-",">","new_kernel_results","`","where","`","kernel_results","`","are","the","results","of","the","`","inner_kernel","`",",","`","new_momentum_distribution","`","is","a","`","CompositeTensor","`","or","a","nested","collection","of","`","CompositeTensor","`","s",",","and","`","new_kernel_results","`","are","a","possibly-modified","copy","of","`","kernel_results","`",".","The","default",",","`","hmc_like_momentum_distribution_setter_fn","`",",","presumes","HMC-style","`","kernel_results","`",",","and","sets","the","`","momentum_distribution","`","only","under","the","`","accepted_results","`","field",".","momentum_distribution_getter_fn",":","A","callable","with","the","signature","`","kernel_results","-",">","momentum_distribution","`","where","`","kernel_results","`","are","the","results","of","the","`","inner_kernel","`","and","`","momentum_distribution","`","is","a","`","CompositeTensor","`","or","a","nested","collection","of","`","CompositeTensor","`","s",".","The","default",",","`","hmc_like_momentum_distribution_getter_fn","`",",","presumes","HMC-style","`","kernel_results","`",",","and","gets","the","`","momentum_distribution","`","only","under","the","`","accepted_results","`","field",".","validate_args",":","Python","`","bool","`",".","When","`","True","`","kernel","parameters","are","checked","for","validity",".","When","`","False","`","invalid","inputs","may","silently","render","incorrect","outputs",".","experimental_shard_axis_names",":","An","optional","structure","of","string","names","indicating","how","members","of","the","state","are","sharded",".","name",":","Python","`","str","`","name","prefixed","to","Ops","created","by","this","class",".","Default",":","'diagonal_mass_matrix_adaptation","'","."]
code: def __init__(
      self,
      inner_kernel,
      initial_running_variance,
      num_estimation_steps=None,
      momentum_distribution_setter_fn=hmc_like_momentum_distribution_setter_fn,
      momentum_distribution_getter_fn=hmc_like_momentum_distribution_getter_fn,
      validate_args=False,
      experimental_shard_axis_names=None,
      name=None,
  ):
      """Creates the diagonal mass matrix adaptation kernel.
  
      Users must provide an `initial_running_variance`, either from a previous
      `DiagonalMassMatrixAdaptation`, or some other source. See
      `RunningCovariance.from_stats` for a convenient way to construct these.
  
  
      Args:
        inner_kernel: `TransitionKernel`-like object.
        initial_running_variance:
          `tfp.experimental.stats.RunningVariance`-like object, or list of them,
          for a batch of momentum distributions. These use `update` on the state
          to maintain an estimate of the variance, and so space, and so must have
          a structure compatible with the state space.
        num_estimation_steps: An optional scalar `int` `Tensor` number of initial
          steps to during which to adjust the running variance. This may be
          greater, less than, or equal to the number of burnin steps. If this
          argument is None, the mass matrix will be updated at each `one_step`
          call. Otherwise, the mass matrix will be updated when the current step
          is equal to `num_estimation_steps`.
        momentum_distribution_setter_fn: A callable with the signature
          `(kernel_results, new_momentum_distribution) -> new_kernel_results`
          where `kernel_results` are the results of the `inner_kernel`,
          `new_momentum_distribution` is a `CompositeTensor` or a nested
          collection of `CompositeTensor`s, and `new_kernel_results` are a
          possibly-modified copy of `kernel_results`. The default,
          `hmc_like_momentum_distribution_setter_fn`, presumes HMC-style
          `kernel_results`, and sets the `momentum_distribution` only under the
          `accepted_results` field.
        momentum_distribution_getter_fn: A callable with the signature
          `kernel_results -> momentum_distribution`
          where `kernel_results` are the results of the `inner_kernel` and
          `momentum_distribution` is a `CompositeTensor` or a nested
          collection of `CompositeTensor`s. The default,
          `hmc_like_momentum_distribution_getter_fn`, presumes HMC-style
          `kernel_results`, and gets the `momentum_distribution` only under the
          `accepted_results` field.
        validate_args: Python `bool`. When `True` kernel parameters are checked
          for validity. When `False` invalid inputs may silently render incorrect
          outputs.
        experimental_shard_axis_names: An optional structure of string names
          indicating how members of the state are sharded.
        name: Python `str` name prefixed to Ops created by this class. Default:
          'diagonal_mass_matrix_adaptation'.
      """
      inner_kernel = mcmc_util.enable_store_parameters_in_results(
          inner_kernel
      ).experimental_with_shard_axes(experimental_shard_axis_names)
      self._parameters = dict(
          inner_kernel=inner_kernel,
          initial_running_variance=initial_running_variance,
          num_estimation_steps=num_estimation_steps,
          momentum_distribution_setter_fn=momentum_distribution_setter_fn,
          momentum_distribution_getter_fn=momentum_distribution_getter_fn,
          experimental_shard_axis_names=experimental_shard_axis_names,
          name=name,
      )
  
imports: import collections
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.mcmc import preconditioning_utils
  from tensorflow_probability.python.experimental.stats import sample_stats
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import unnest
  from tensorflow_probability.python.mcmc import kernel
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 1 to create a new DiagonalMassMatrixAdaptation object from inherited base classes: kernel_base with example: obj = DiagonalMassMatrixAdaptation(inner_kernel, initial_running_variance, num_estimation_steps, momentum_distribution_setter_fn, momentum_distribution_getter_fn, validate_args, experimental_shard_axis_names, name)