class_docstr: `Reducer` that computes a running R-hat diagnostic statistic.
  
  `PotentialScaleReductionReducer` assumes that all provided chain states
  include samples from multiple independent Markov chains, and that all of
  these chains are to be included in the same calculation.
  `PotentialScaleReductionReducer` also assumes that incoming samples have
  shape `[Ci1, Ci2,...,CiD] + A`. Dimensions `0` through `D - 1` index the
  `Ci1 x ... x CiD` independent chains to be tested for convergence to the
  same target. The remaining dimensions, `A`, represent the event shape and
  hence, can have any shape (even empty, which implies scalar samples). The
  number of independent chain dimensions is defined by the
  `independent_chain_ndims` parameter at initialization.
  
  As with all reducers, PotentialScaleReductionReducer 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.
  
  `PotentialScaleReductionReducer` is meant to fit into the larger Streaming
  MCMC framework. `RunningPotentialScaleReduction` in `tfp.experimental.stats`
  is better suited for more generic streaming R-hat needs. More precise
  algorithmic details can also be found by referencing
  `RunningPotentialScaleReduction`.
class_docstr_tok: ["`","Reducer","`","that","computes","a","running","R-hat","diagnostic","statistic",".","`","PotentialScaleReductionReducer","`","assumes","that","all","provided","chain","states","include","samples","from","multiple","independent","Markov","chains",",","and","that","all","of","these","chains","are","to","be","included","in","the","same","calculation",".","`","PotentialScaleReductionReducer","`","also","assumes","that","incoming","samples","have","shape","`","[","Ci1",",","Ci2",",","...",",","CiD","]","+","A","`",".","Dimensions","`","0","`","through","`","D","-","1","`","index","the","`","Ci1","x","...","x","CiD","`","independent","chains","to","be","tested","for","convergence","to","the","same","target",".","The","remaining","dimensions",",","`","A","`",",","represent","the","event","shape","and","hence",",","can","have","any","shape","(","even","empty",",","which","implies","scalar","samples",")",".","The","number","of","independent","chain","dimensions","is","defined","by","the","`","independent_chain_ndims","`","parameter","at","initialization",".","As","with","all","reducers",",","PotentialScaleReductionReducer","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",".","`","PotentialScaleReductionReducer","`","is","meant","to","fit","into","the","larger","Streaming","MCMC","framework",".","`","RunningPotentialScaleReduction","`","in","`","tfp.experimental.stats","`","is","better","suited","for","more","generic","streaming","R-hat","needs",".","More","precise","algorithmic","details","can","also","be","found","by","referencing","`","RunningPotentialScaleReduction","`","."]
docstr: Initializes an empty `PotentialScaleReductionReducerState`.
  
  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`.
      For streaming R-hat, this argument has no influence on the
      computation; hence, it is `None` by default. However, it's
      still accepted to fit the `Reducer` base class.
  
  Returns:
    state: `PotentialScaleReductionReducerState` with `rhat_state` field
      representing a stream of no inputs.
docstr_tok: ["Initializes","an","empty","`","PotentialScaleReductionReducerState","`",".","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","`",".","For","streaming","R-hat",",","this","argument","has","no","influence","on","the","computation",";","hence",",","it","is","`","None","`","by","default",".","However",",","it's","still","accepted","to","fit","the","`","Reducer","`","base","class",".","Returns",":","state",":","`","PotentialScaleReductionReducerState","`","with","`","rhat_state","`","field","representing","a","stream","of","no","inputs","."]
code: def initialize(
      self, initial_chain_state, initial_kernel_results=None
  ):
      """Initializes an empty `PotentialScaleReductionReducerState`.
  
      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`.
          For streaming R-hat, this argument has no influence on the
          computation; hence, it is `None` by default. However, it's
          still accepted to fit the `Reducer` base class.
  
      Returns:
        state: `PotentialScaleReductionReducerState` with `rhat_state` field
          representing a stream of no inputs.
      """
      with tf.name_scope(
          mcmc_util.make_name(
              self.name,
              "potential_scale_reduction_reducer",
              "initialize",
          )
      ):
          initial_chain_state = tf.nest.map_structure(
              tf.convert_to_tensor, initial_chain_state
          )
          sample_shape = tf.nest.map_structure(
              lambda chain_state: tuple(ps.shape(chain_state)),
              initial_chain_state,
          )
          chain_ndims = tf.nest.map_structure(
              lambda chain_state: self.independent_chain_ndims,
              initial_chain_state,
          )
          dtype = tf.nest.map_structure(
              lambda chain_state: chain_state.dtype, initial_chain_state
          )
          rhat = sample_stats.RunningPotentialScaleReduction.from_shape(
              shape=sample_shape,
              independent_chain_ndims=chain_ndims,
              dtype=dtype,
          )
          return PotentialScaleReductionReducerState(rhat)
  
file_path: probability/tensorflow_probability/python/experimental/mcmc/potential_scale_reduction_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 prefer_static
  from tensorflow_probability.python.mcmc.internal import util
label_desc: Use image node_id 2 for calling the PotentialScaleReductionReducer obj's underlying member method code with example usage: obj.initialize(initial_chain_state, initial_kernel_results) and returns: PotentialScaleReductionReducerState