class_docstr: `Reducer` that computes a running covariance.
  
  By default, `CovarianceReducer` computes covariance directly over the
  latent state, ignoring kernel results; however, it can also compute
  a running covariance on samples evaluated on some arbitrary structure of
  `transform_fn`s. A `trasform_fn` is defined as any function that accepts
  the chain state and kernel results, and ouptuts a `Tensor` or nested
  structure of `Tensor`s to compute the covariance over. To be explicit,
  if we denote a `transform_fn` as f(x, y), then `CovarianceReducer` will
  compute Cov(f(x, y)). If some structure of `transform_fn`s are given,
  the final statistic (as returned by the `finalize` method) will mimic
  the results of that structure.
  
  As with all reducers, CovarianceReducer 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.
  
  `CovarianceReducer` is meant to fit into the larger Streaming MCMC
  framework. `RunningCovariance` in `tfp.experimental.stats` is better suited
  for more generic streaming covariance needs.
  
  There are two ways to stream over MCMC samples. The first is to manually
  wrap `CovarianceReducer` in a `tfp.experimental.mcmc.WithReductions`
  `TransitionKernel`. Doing so enables a wide variety of possible compositions.
  For example, to perform covariance calculation on samples that survive
  thinning and burn-in, `WithReductions` should wrap around an appropriate
  `SampleDiscardingKernel`.
  
  If the sole objective is to estimate covariance, it may be more convenient to
  use a pre-defined driver like `tfp.experimental.mcmc.sample_fold`.
  `sample_fold` will automatically create the Transition Kernel onion, apply
  `kernel` samples to update reducer states, and `finalize` calculations.
  
  ```
  python
  
  kernel = ...
  reducer = tfp.experimental.mcmc.CovarianceReducer()
  covariance_estimate, _, _ = tfp.experimental.mcmc.sample_fold(
      num_steps=...,
      current_state=...,
      previous_kernel_results=...,
      kernel=kernel,
      reducers=reducer,
  )
  covariance_estimate  # estimate of covariance (not `CovarianceReducerState`)
  ```
docstr: Initializes a `CovarianceReducerState` using previously defined metadata.
  
  For calculation purposes, the `initial_chain_state` does not count as a
  sample. This is a deliberate decision that ensures consistency across
  sampling procedures (i.e. `tfp.mcmc.sample_chain` follows similar
  semantics).
  
  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). It is used to infer the shape and dtype of future samples.
    initial_kernel_results: A (possibly nested) structure of `Tensor`s
      representing internal calculations made in a related `TransitionKernel`.
  
  Returns:
    state: `CovarianceReducerState` with `cov_state` field representing
      a stream of no inputs.
docstr_tok: ["Initializes","a","`","CovarianceReducerState","`","using","previously","defined","metadata",".","For","calculation","purposes",",","the","`","initial_chain_state","`","does","not","count","as","a","sample",".","This","is","a","deliberate","decision","that","ensures","consistency","across","sampling","procedures","(","i.e",".","`","tfp.mcmc.sample_chain","`","follows","similar","semantics",")",".","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",")",".","It","is","used","to","infer","the","shape","and","dtype","of","future","samples",".","initial_kernel_results",":","A","(","possibly","nested",")","structure","of","`","Tensor","`","s","representing","internal","calculations","made","in","a","related","`","TransitionKernel","`",".","Returns",":","state",":","`","CovarianceReducerState","`","with","`","cov_state","`","field","representing","a","stream","of","no","inputs","."]
code: def initialize(
      self, initial_chain_state, initial_kernel_results=None
  ):
      """Initializes a `CovarianceReducerState` using previously defined metadata.
  
      For calculation purposes, the `initial_chain_state` does not count as a
      sample. This is a deliberate decision that ensures consistency across
      sampling procedures (i.e. `tfp.mcmc.sample_chain` follows similar
      semantics).
  
      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). It is used to infer the shape and dtype of future samples.
        initial_kernel_results: A (possibly nested) structure of `Tensor`s
          representing internal calculations made in a related `TransitionKernel`.
  
      Returns:
        state: `CovarianceReducerState` with `cov_state` field representing
          a stream of no inputs.
      """
      with tf.name_scope(
          mcmc_util.make_name(
              self.name, "covariance_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_result = tf.nest.map_structure(
              lambda fn: fn(
                  initial_chain_state, initial_kernel_results
              ),
              self.transform_fn,
          )
          event_ndims = _canonicalize_event_ndims(
              initial_fn_result, self.event_ndims
          )
          running_covariances = tf.nest.map_structure(
              sample_stats.RunningCovariance.from_example,
              initial_fn_result,
              event_ndims,
          )
          return CovarianceReducerState(running_covariances)
  
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 CovarianceReducer obj's underlying member method code with example usage: obj.initialize(initial_chain_state, initial_kernel_results) and returns: CovarianceReducerState