class_docstr: Implements Welford's online scheme for estimating (co)variance (see :math:`[1]`).
  Useful for adapting diagonal and dense mass structures for HMC.
  
  **References**
  
  [1] `The Art of Computer Programming`,
  Donald E. Knuth
class_docstr_tok: ["Implements","Welford","'s","online","scheme","for","estimating","(","co",")","variance","(","see",":","math",":","`","[","1","]","`",")",".","Useful","for","adapting","diagonal","and","dense","mass","structures","for","HMC",".","*","*","References","*","*","[","1","]","`","The","Art","of","Computer","Programming","`",",","Donald","E.","Knuth"]
code: def update(self, sample):
      self.n_samples += 1
      delta_pre = sample - self._mean
      self._mean = self._mean + delta_pre / self.n_samples
      delta_post = sample - self._mean
  
      if self.diagonal:
          self._m2 += delta_pre * delta_post
      else:
          self._m2 += torch.ger(delta_post, delta_pre)
  
file_path: pyro/pyro/ops/welford.py
imports: import torch
label_desc: Use image node_id 3 for calling the WelfordCovariance obj's underlying member method code with example usage: obj.update(sample) without return types