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: Finalizes expectation calculation from the `final_reducer_state`.
  
  If the finalized method is invoked on a stream of no inputs, a corresponding
  structure of `tf.ones` will be returned.
  
  Args:
    final_reducer_state: `ExpectationsReducerState` that represents the
      final reducer state.
  
  Returns:
    expectation: an estimate of the expectation with identical structure to
      `self.transform_fn`.
docstr_tok: ["Finalizes","expectation","calculation","from","the","`","final_reducer_state","`",".","If","the","finalized","method","is","invoked","on","a","stream","of","no","inputs",",","a","corresponding","structure","of","`","tf.ones","`","will","be","returned",".","Args",":","final_reducer_state",":","`","ExpectationsReducerState","`","that","represents","the","final","reducer","state",".","Returns",":","expectation",":","an","estimate","of","the","expectation","with","identical","structure","to","`","self.transform_fn","`","."]
code: def finalize(self, final_reducer_state):
      """Finalizes expectation calculation from the `final_reducer_state`.
  
      If the finalized method is invoked on a stream of no inputs, a corresponding
      structure of `tf.ones` will be returned.
  
      Args:
        final_reducer_state: `ExpectationsReducerState` that represents the
          final reducer state.
  
      Returns:
        expectation: an estimate of the expectation with identical structure to
          `self.transform_fn`.
      """
      with tf.name_scope(
          mcmc_util.make_name(
              self.name, "expectations_reducer", "finalize"
          )
      ):
          return nest.map_structure(
              lambda state: state.mean,
              final_reducer_state.expectation_state,
              check_types=False,
          )
  
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 4 for calling the ExpectationsReducer obj's underlying member method code with example usage: obj.finalize(final_reducer_state) and returns: nest