class_docstr: Likes :class:`WelfordCovariance` but generalized to the arrowhead structure.
class_docstr_tok: ["Likes",":","class",":","`","WelfordCovariance","`","but","generalized","to","the","arrowhead","structure","."]
docstr: Gets the covariance in arrowhead form: (top, bottom_diag) where `top = cov[:head_size]`
  and `bottom_diag = cov.diag()[head_size:]`.
docstr_tok: ["Gets","the","covariance","in","arrowhead","form",":","(","top",",","bottom_diag",")","where","`","top","=","cov","[",":","head_size","]","`","and","`","bottom_diag","=","cov.diag","(",")","[","head_size",":","]","`","."]
code: def get_covariance(self, regularize=True):
      """
      Gets the covariance in arrowhead form: (top, bottom_diag) where `top = cov[:head_size]`
      and `bottom_diag = cov.diag()[head_size:]`.
      """
      if self.n_samples < 2:
          raise RuntimeError(
              "Insufficient samples to estimate covariance"
          )
      top = self._m2_top / (self.n_samples - 1)
      bottom_diag = self._m2_bottom_diag / (self.n_samples - 1)
      if regularize:
          top = top * (self.n_samples / (self.n_samples + 5.0))
          bottom_diag = bottom_diag * (
              self.n_samples / (self.n_samples + 5.0)
          )
          shrinkage = 1e-3 * (5.0 / (self.n_samples + 5.0))
          top.view(-1)[:: top.size(-1) + 1] += shrinkage
          bottom_diag = bottom_diag + shrinkage
  
      return top, bottom_diag
  
file_path: pyro/pyro/ops/welford.py
imports: import torch
label_desc: Use image node_id 4 for calling the WelfordArrowheadCovariance obj's underlying member method code with example usage: obj.get_covariance(regularize) and returns: top,  bottom_diag