class_docstr: Applies `Reducer`s to stream over MCMC samples.
  
  `WithReductions` augments an inner MCMC kernel with
  side-computations that can read the stream of samples as they
  are generated.  This is relevant for streaming uses of MCMC,
  where materializing the entire Markov chain history is undesirable,
  e.g. due to memory limits.
  
  One `WithReductions` instance can attach an arbitrary collection
  of side-computations, each of which must be packaged as a
  `Reducer`.  `WithReductions` operates by generating a
  sample with its `inner_kernel`'s `one_step`, then invoking each
  `Reducer`'s `one_step` method on that sample. The updated reducer
  states are stored in the `reduction_results` field of
  `WithReductions`' kernel results.
class_docstr_tok: ["Applies","`","Reducer","`","s","to","stream","over","MCMC","samples",".","`","WithReductions","`","augments","an","inner","MCMC","kernel","with","side-computations","that","can","read","the","stream","of","samples","as","they","are","generated",".","This","is","relevant","for","streaming","uses","of","MCMC",",","where","materializing","the","entire","Markov","chain","history","is","undesirable",",","e.g",".","due","to","memory","limits",".","One","`","WithReductions","`","instance","can","attach","an","arbitrary","collection","of","side-computations",",","each","of","which","must","be","packaged","as","a","`","Reducer","`",".","`","WithReductions","`","operates","by","generating","a","sample","with","its","`","inner_kernel","`","'s","`","one_step","`",",","then","invoking","each","`","Reducer","`","'s","`","one_step","`","method","on","that","sample",".","The","updated","reducer","states","are","stored","in","the","`","reduction_results","`","field","of","`","WithReductions","`","'","kernel","results","."]
docstr: Instantiates this object.
  
  Args:
    inner_kernel: `TransitionKernel` whose `one_step` will generate
      MCMC sample(s).
    reducer: A (possibly nested) structure of `Reducer`s to be evaluated
      on the `inner_kernel`'s samples.
    adjust_kr_fn: Optional function to adjust the kernel_results structure
      of `inner_kernel` before presenting it to `reducer`.  Useful for
      drivers (like `sample_fold`) that construct their own kernel onions,
      but accept `Reducer`s as arguments.
    name: Python `str` name prefixed to Ops created by this function.
      Default value: `None` (i.e., "reduced_kernel").
docstr_tok: ["Instantiates","this","object",".","Args",":","inner_kernel",":","`","TransitionKernel","`","whose","`","one_step","`","will","generate","MCMC","sample","(","s",")",".","reducer",":","A","(","possibly","nested",")","structure","of","`","Reducer","`","s","to","be","evaluated","on","the","`","inner_kernel","`","'s","samples",".","adjust_kr_fn",":","Optional","function","to","adjust","the","kernel_results","structure","of","`","inner_kernel","`","before","presenting","it","to","`","reducer","`",".","Useful","for","drivers","(","like","`","sample_fold","`",")","that","construct","their","own","kernel","onions",",","but","accept","`","Reducer","`","s","as","arguments",".","name",":","Python","`","str","`","name","prefixed","to","Ops","created","by","this","function",".","Default","value",":","`","None","`","(","i.e.",",","``","reduced_kernel","''",")","."]
code: def __init__(
      self, inner_kernel, reducer, adjust_kr_fn=lambda x: x, name=None
  ):
      """Instantiates this object.
  
      Args:
        inner_kernel: `TransitionKernel` whose `one_step` will generate
          MCMC sample(s).
        reducer: A (possibly nested) structure of `Reducer`s to be evaluated
          on the `inner_kernel`'s samples.
        adjust_kr_fn: Optional function to adjust the kernel_results structure
          of `inner_kernel` before presenting it to `reducer`.  Useful for
          drivers (like `sample_fold`) that construct their own kernel onions,
          but accept `Reducer`s as arguments.
        name: Python `str` name prefixed to Ops created by this function.
          Default value: `None` (i.e., "reduced_kernel").
      """
      self._parameters = dict(
          inner_kernel=inner_kernel,
          reducer=reducer,
          adjust_kr_fn=adjust_kr_fn,
          name=name or "reduced_kernel",
      )
  
file_path: probability/tensorflow_probability/python/experimental/mcmc/with_reductions.py
imports: import collections
  import tensorflow.compat.v2
  from tensorflow_probability.python.mcmc import kernel
  from tensorflow_probability.python.mcmc.internal import util
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 to create a new WithReductions object from inherited base classes: kernel_base with example: obj = WithReductions(inner_kernel, reducer, adjust_kr_fn, name)