class_docstr: `Reducer` that computes a running expectation.
  
  `ExpectationsReducer` calculates expectations over some arbitrary structure
  of `transform_fn`s. A `transform_fn` is a function that accepts a Markov
  chain sample and kernel results, and outputs the relevant value for
  expectation calculation. In other words, if we denote a `transform_fn`
  as f(x,y), `ExpectationsReducer` approximates E[f(x,y)] for all provided
  functions. The finalized expectation will also identically mimic the
  structure of `transform_fn`.
  
  As with all reducers, ExpectationsReducer does not hold state information;
  rather, it stores supplied metadata. Intermediate calculations are held in
  a state object, which is returned via `initialize` and `one_step` method
  calls.
class_docstr_tok: ["`","Reducer","`","that","computes","a","running","expectation",".","`","ExpectationsReducer","`","calculates","expectations","over","some","arbitrary","structure","of","`","transform_fn","`","s",".","A","`","transform_fn","`","is","a","function","that","accepts","a","Markov","chain","sample","and","kernel","results",",","and","outputs","the","relevant","value","for","expectation","calculation",".","In","other","words",",","if","we","denote","a","`","transform_fn","`","as","f","(","x",",","y",")",",","`","ExpectationsReducer","`","approximates","E","[","f","(","x",",","y",")","]","for","all","provided","functions",".","The","finalized","expectation","will","also","identically","mimic","the","structure","of","`","transform_fn","`",".","As","with","all","reducers",",","ExpectationsReducer","does","not","hold","state","information",";","rather",",","it","stores","supplied","metadata",".","Intermediate","calculations","are","held","in","a","state","object",",","which","is","returned","via","`","initialize","`","and","`","one_step","`","method","calls","."]
docstr: Initializes an empty `ExpectationsReducerState`.
  
  Args:
    initial_chain_state: A (possibly nested) structure of `Tensor`s or Python
      `list`s of `Tensor`s representing the current state(s) of the Markov
      chain(s).
    initial_kernel_results: A (possibly nested) structure of `Tensor`s
      representing internal calculations made in a related `TransitionKernel`.
  
  Returns:
    state: `ExpectationsReducerState` representing a stream of no inputs.
docstr_tok: ["Initializes","an","empty","`","ExpectationsReducerState","`",".","Args",":","initial_chain_state",":","A","(","possibly","nested",")","structure","of","`","Tensor","`","s","or","Python","`","list","`","s","of","`","Tensor","`","s","representing","the","current","state","(","s",")","of","the","Markov","chain","(","s",")",".","initial_kernel_results",":","A","(","possibly","nested",")","structure","of","`","Tensor","`","s","representing","internal","calculations","made","in","a","related","`","TransitionKernel","`",".","Returns",":","state",":","`","ExpectationsReducerState","`","representing","a","stream","of","no","inputs","."]
code: def initialize(
      self, initial_chain_state, initial_kernel_results=None
  ):
      """Initializes an empty `ExpectationsReducerState`.
  
      Args:
        initial_chain_state: A (possibly nested) structure of `Tensor`s or Python
          `list`s of `Tensor`s representing the current state(s) of the Markov
          chain(s).
        initial_kernel_results: A (possibly nested) structure of `Tensor`s
          representing internal calculations made in a related `TransitionKernel`.
  
      Returns:
        state: `ExpectationsReducerState` representing a stream of no inputs.
      """
      with tf.name_scope(
          mcmc_util.make_name(
              self.name, "expectations_reducer", "initialize"
          )
      ):
          initial_chain_state = tf.nest.map_structure(
              tf.convert_to_tensor, initial_chain_state
          )
          if initial_kernel_results is not None:
              initial_kernel_results = tf.nest.map_structure(
                  tf.convert_to_tensor,
                  initial_kernel_results,
                  expand_composites=True,
              )
          initial_fn_results = tf.nest.map_structure(
              lambda fn: fn(
                  initial_chain_state, initial_kernel_results
              ),
              self.transform_fn,
          )
          return ExpectationsReducerState(
              tf.nest.map_structure(
                  sample_stats.RunningMean.from_example,
                  initial_fn_results,
              )
          )
  
file_path: probability/tensorflow_probability/python/experimental/mcmc/expectations_reducer.py
imports: import collections
  import tensorflow.compat.v2
  from tensorflow_probability.python.experimental.mcmc import reducer
  from tensorflow_probability.python.experimental.stats import sample_stats
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.mcmc.internal import util
  from tensorflow.python.util import nest
label_desc: Use image node_id 2 for calling the ExpectationsReducer obj's underlying member method code with example usage: obj.initialize(initial_chain_state, initial_kernel_results) and returns: ExpectationsReducerState