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 reducer states with identical structure to the `init_state`.
  
  Args:
    init_state: `Tensor` or Python `list` of `Tensor`s representing the
      state(s) of the Markov chain(s). For consistency across sampling
      procedures (i.e. `tfp.mcmc.sample_chain` follows similar semantics),
      the initial state does not count as a "sample". Hence, all reducer
      states will reflect empty streams.
    inner_results: Optional results tuple for the inner kernel.  Will be
      re-bootstrapped if omitted.
    previous_reducer_state: Optional results structure for the reducers.  Will
      be re-initialized if omitted.
  
  Returns:
    kernel_results: `WithReductionsKernelResults` representing updated
      kernel results. Reducer states are stored in the
      `reduction_results` field. The state structure is identical
      to `self.reducer`.
docstr_tok: ["Instantiates","reducer","states","with","identical","structure","to","the","`","init_state","`",".","Args",":","init_state",":","`","Tensor","`","or","Python","`","list","`","of","`","Tensor","`","s","representing","the","state","(","s",")","of","the","Markov","chain","(","s",")",".","For","consistency","across","sampling","procedures","(","i.e",".","`","tfp.mcmc.sample_chain","`","follows","similar","semantics",")",",","the","initial","state","does","not","count","as","a","``","sample","''",".","Hence",",","all","reducer","states","will","reflect","empty","streams",".","inner_results",":","Optional","results","tuple","for","the","inner","kernel",".","Will","be","re-bootstrapped","if","omitted",".","previous_reducer_state",":","Optional","results","structure","for","the","reducers",".","Will","be","re-initialized","if","omitted",".","Returns",":","kernel_results",":","`","WithReductionsKernelResults","`","representing","updated","kernel","results",".","Reducer","states","are","stored","in","the","`","reduction_results","`","field",".","The","state","structure","is","identical","to","`","self.reducer","`","."]
code: def bootstrap_results(
      self, init_state, inner_results=None, previous_reducer_state=None
  ):
      """Instantiates reducer states with identical structure to the `init_state`.
  
      Args:
        init_state: `Tensor` or Python `list` of `Tensor`s representing the
          state(s) of the Markov chain(s). For consistency across sampling
          procedures (i.e. `tfp.mcmc.sample_chain` follows similar semantics),
          the initial state does not count as a "sample". Hence, all reducer
          states will reflect empty streams.
        inner_results: Optional results tuple for the inner kernel.  Will be
          re-bootstrapped if omitted.
        previous_reducer_state: Optional results structure for the reducers.  Will
          be re-initialized if omitted.
  
      Returns:
        kernel_results: `WithReductionsKernelResults` representing updated
          kernel results. Reducer states are stored in the
          `reduction_results` field. The state structure is identical
          to `self.reducer`.
      """
      with tf.name_scope(
          mcmc_util.make_name(
              self.name, "with_reductions", "bootstrap_results"
          )
      ):
          if inner_results is None:
              inner_results = self.inner_kernel.bootstrap_results(
                  init_state
              )
          inner_results_adj = self.adjust_kr_fn(inner_results)
          if previous_reducer_state is None:
              previous_reducer_state = tf.nest.map_structure(
                  lambda r: r.initialize(init_state, inner_results_adj),
                  self.reducer,
              )
          return WithReductionsKernelResults(
              previous_reducer_state, inner_results
          )
  
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 3 for calling the WithReductions obj's underlying member method code with example usage: obj.bootstrap_results(init_state, inner_results, previous_reducer_state) and returns: WithReductionsKernelResults