class_docstr: Tracks quantities for numerically stable mean and variance calculation.
class_docstr_tok: ["Tracks","quantities","for","numerically","stable","mean","and","variance","calculation","."]
docstr: Combine weighted mean and variance parameters, updating in place.
docstr_tok: ["Combine","weighted","mean","and","variance","parameters",",","updating","in","place","."]
code: def _combine(
      self,
      b_count: int,
      b_mean: float,
      b_variance: float,
      b_weights_mean: float,
  ):
      """Combine weighted mean and variance parameters, updating in place."""
  
      a_count = self.count
      a_mean = self.mean
      a_variance = self.variance
      a_weights_mean = self.weights_mean
  
      new_count = a_count + b_count
      new_weight_sum = (
          a_count * a_weights_mean + b_count * b_weights_mean
      )
      if new_count == 0 or new_weight_sum == 0:
          return
      # In the case of very inbalanced sizes we prefer ratio ~= 0
      if b_count * b_weights_mean > a_count * a_weights_mean:
          a_count, b_count = b_count, a_count
          a_mean, b_mean = b_mean, a_mean
          a_variance, b_variance = b_variance, a_variance
          a_weights_mean, b_weights_mean = (
              b_weights_mean,
              a_weights_mean,
          )
      ratio = b_count * b_weights_mean / new_weight_sum
      new_weights_mean = a_weights_mean + b_count / new_count * (
          b_weights_mean - a_weights_mean
      )
      new_mean = a_mean + ratio * (b_mean - a_mean)
      var = a_variance + ratio * (
          b_variance
          - a_variance
          + (b_mean - new_mean) * (b_mean - a_mean)
      )
      self.count = new_count
      self.mean = new_mean
      self.variance = var
      self.weights_mean = new_weights_mean
  
imports: from typing import Optional
  import numpy
label_desc: Use image node_id 4 for calling the WeightedMeanVarAccumulator obj's underlying member method code with example usage: obj._combine(b_count, b_mean, b_variance, b_weights_mean) without return types