class_docstr: A running R-hat diagnostic.
  
  `RunningPotentialScaleReduction` uses Gelman and Rubin (1992)'s potential
  scale reduction (also known as R-hat) for chain convergence [1].
  
  If multiple independent R-hat computations are desired across a latent
  state, one should use a (possibly nested) collection for initialization
  parameters `independent_chain_ndims` and `shape`. Subsequent chain states
  used to update the streaming R-hat should mimic their identical structure.
  
  `RunningPotentialScaleReduction` 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.
  
  `RunningPotentialScaleReduction` is meant to serve general streaming R-hat.
  For a specialized version that fits streaming over MCMC samples, see
  `PotentialScaleReductionReducer` in `tfp.experimental.mcmc`.
  
  #### References
  
  [1]: Andrew Gelman and Donald B. Rubin. Inference from Iterative Simulation
       Using Multiple Sequences. _Statistical Science_, 7(4):457-472, 1992.
docstr: Starts an empty `RunningPotentialScaleReduction` from metadata.
  
  Args:
    example: A `Tensor`.  The `RunningPotentialScaleReduction` will
      accept samples of the same dtype and broadcast-compatible
      shape as the example.
    independent_chain_ndims: Integer or Integer type `Tensor` with value
      `>= 1` giving the number of leading dimensions holding independent
      chain results to be tested for convergence. Using a collection
      implies that future samples will mimic that exact structure.
  
  Returns:
    state: `RunningPotentialScaleReduction` representing a stream of
      no inputs.  Note that by convention, the supplied example is
      used only for initialization, but not counted as a sample.
docstr_tok: ["Starts","an","empty","`","RunningPotentialScaleReduction","`","from","metadata",".","Args",":","example",":","A","`","Tensor","`",".","The","`","RunningPotentialScaleReduction","`","will","accept","samples","of","the","same","dtype","and","broadcast-compatible","shape","as","the","example",".","independent_chain_ndims",":","Integer","or","Integer","type","`","Tensor","`","with","value","`",">","=","1","`","giving","the","number","of","leading","dimensions","holding","independent","chain","results","to","be","tested","for","convergence",".","Using","a","collection","implies","that","future","samples","will","mimic","that","exact","structure",".","Returns",":","state",":","`","RunningPotentialScaleReduction","`","representing","a","stream","of","no","inputs",".","Note","that","by","convention",",","the","supplied","example","is","used","only","for","initialization",",","but","not","counted","as","a","sample","."]
code: def from_example(cls, example, independent_chain_ndims=1):
      """Starts an empty `RunningPotentialScaleReduction` from metadata.
  
      Args:
        example: A `Tensor`.  The `RunningPotentialScaleReduction` will
          accept samples of the same dtype and broadcast-compatible
          shape as the example.
        independent_chain_ndims: Integer or Integer type `Tensor` with value
          `>= 1` giving the number of leading dimensions holding independent
          chain results to be tested for convergence. Using a collection
          implies that future samples will mimic that exact structure.
  
      Returns:
        state: `RunningPotentialScaleReduction` representing a stream of
          no inputs.  Note that by convention, the supplied example is
          used only for initialization, but not counted as a sample.
      """
      return cls.from_shape(
          shape=ps.shape(example),
          dtype=example.dtype,
          independent_chain_ndims=independent_chain_ndims,
      )
  
imports: import functools
  import math
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import nest_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.mcmc import diagnostic
  from tensorflow.python.util import nest
label_desc: Use image node_id 5 for calling the RunningPotentialScaleReduction obj's underlying member method code with example usage: obj.from_example(cls, example, independent_chain_ndims) and returns: cls