class_docstr: Computes running central moments.
  
  `RunningCentralMoments` will compute arbitrary central moments in
  streaming fashion following the formula proposed by Philippe Pebay
  (2008) [1]. For reference, the formula we refer to is the incremental
  version of arbitrary moments (equation 2.9). Since the algorithm computes
  moments as a function of lower ones, even if not requested, all lower
  moments will be computed as well. The moments that are actually returned
  is specified by the `moment` parameter at initialization. Note, while
  any arbitrarily high central moment is theoretically supported,
  `RunningCentralMoments` cannot guarantee numerical stability for all
  moments.
  
  #### References
  [1]: Philippe Pebay. Formulas for Robust, One-Pass Parallel Computation of
        Covariances and Arbitrary-Order Statistical Moments. _Technical Report
        SAND2008-6212_, 2008.
        https://prod-ng.sandia.gov/techlib-noauth/access-control.cgi/2008/086212.pdf
docstr: Update with a new sample.
  
  Args:
    new_sample: Incoming `Tensor` sample with shape and dtype compatible with
      those used to form the `RunningCentralMoments`.
  
  Returns:
    state: `RunningCentralMoments` updated to include the new sample.
docstr_tok: ["Update","with","a","new","sample",".","Args",":","new_sample",":","Incoming","`","Tensor","`","sample","with","shape","and","dtype","compatible","with","those","used","to","form","the","`","RunningCentralMoments","`",".","Returns",":","state",":","`","RunningCentralMoments","`","updated","to","include","the","new","sample","."]
code: def update(self, new_sample):
      """Update with a new sample.
  
      Args:
        new_sample: Incoming `Tensor` sample with shape and dtype compatible with
          those used to form the `RunningCentralMoments`.
  
      Returns:
        state: `RunningCentralMoments` updated to include the new sample.
      """
      shape = self.mean_state.mean.shape
      dtype = self.mean_state.mean.dtype
      n_2 = 1
      n_1 = self.mean_state.num_samples
      n = tf.cast(n_1 + n_2, dtype=dtype)
      delta_mean = new_sample - self.mean_state.mean
      new_mean_state = self.mean_state.update(new_sample)
      # The sum of exponentiated residuals can be thought of as an estimation
      # of the central moment before dividing through by the number of samples.
      # Since the first central moment is always 0, it simplifies update
      # logic to prepend an appropriate structure of zeros.
      old_res = tf.concat(
          [
              tf.zeros(ps.concat([(1,), shape], axis=0), dtype),
              self.exponentiated_residuals,
          ],
          axis=0,
      )
      # Not storing said zeros in the carried state, though
      new_exponentiated_residuals = []
  
      # the following two nested for loops calculate equation 2.9 in Pebay's
      # 2008 paper from smallest moment to highest.
      max_moment = max(self.desired_moments)
      for p in range(2, max_moment + 1):
          summation = tf.zeros(shape, dtype)
          for k in range(1, p - 1):
              adjusted_old_res = ((-delta_mean / n) ** k) * old_res[
                  p - k - 1
              ]
              summation += _n_choose_k(p, k) * adjusted_old_res
          # the `adj_term` refers to the final term in equation 2.9 and is not
          # transcribed exactly; rather, it's simplified to avoid having a
          # `(n - 1)` denominator.
          adj_term = (
              ((delta_mean / n) ** p)
              * (n - 1)
              * ((n - 1) ** (p - 1) + (-1) ** p)
          )
          new_pth_residual = old_res[p - 1] + summation + adj_term
          new_exponentiated_residuals.append(new_pth_residual)
  
      return RunningCentralMoments(
          new_mean_state,
          # The cast is needed in case new_exponentiated_residuals is the empty
          # list, which will happen if the user requested only the first moment.
          exponentiated_residuals=tf.cast(
              tf.stack(new_exponentiated_residuals, axis=0), dtype=dtype
          ),
          desired_moments=self.desired_moments,
      )
  
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 6 for calling the RunningCentralMoments obj's underlying member method code with example usage: obj.update(new_sample) and returns: RunningCentralMoments