class_docstr: Multi Variate Gaussian Distribution.
docstr: Estimates covariance matrix like numpy.cov.
  
  Args:
      observations (Tensor): A 1-D or 2-D array containing multiple variables and observations.
           Each row of `m` represents a variable, and each column a single
           observation of all those variables. Also see `rowvar` below.
      rowvar (bool): If `rowvar` is True (default), then each row represents a
          variable, with observations in the columns. Otherwise, the relationship
          is transposed: each column represents a variable, while the rows
          contain observations. Defaults to False.
      bias (bool): Default normalization (False) is by ``(N - 1)``, where ``N`` is the
          number of observations given (unbiased estimate). If `bias` is True,
          then normalization is by ``N``. These values can be overridden by using
          the keyword ``ddof`` in numpy versions >= 1.5. Defaults to False
      ddof (int | None): If not ``None`` the default value implied by `bias` is overridden.
          Note that ``ddof=1`` will return the unbiased estimate, even if both
          `fweights` and `aweights` are specified, and ``ddof=0`` will return
          the simple average. See the notes for the details. The default value
          is ``None``.
      aweights (Tensor): 1-D array of observation vector weights. These relative weights are
          typically large for observations considered "important" and smaller for
          observations considered less "important". If ``ddof=0`` the array of
          weights can be used to assign probabilities to observation vectors. (Default value = None)
  
  
  Returns:
    The covariance matrix of the variables.
code: def _cov(
      observations: Tensor,
      rowvar: bool = False,
      bias: bool = False,
      ddof: int | None = None,
      aweights: Tensor = None,
  ) -> Tensor:
      """Estimates covariance matrix like numpy.cov.
  
      Args:
          observations (Tensor): A 1-D or 2-D array containing multiple variables and observations.
               Each row of `m` represents a variable, and each column a single
               observation of all those variables. Also see `rowvar` below.
          rowvar (bool): If `rowvar` is True (default), then each row represents a
              variable, with observations in the columns. Otherwise, the relationship
              is transposed: each column represents a variable, while the rows
              contain observations. Defaults to False.
          bias (bool): Default normalization (False) is by ``(N - 1)``, where ``N`` is the
              number of observations given (unbiased estimate). If `bias` is True,
              then normalization is by ``N``. These values can be overridden by using
              the keyword ``ddof`` in numpy versions >= 1.5. Defaults to False
          ddof (int | None): If not ``None`` the default value implied by `bias` is overridden.
              Note that ``ddof=1`` will return the unbiased estimate, even if both
              `fweights` and `aweights` are specified, and ``ddof=0`` will return
              the simple average. See the notes for the details. The default value
              is ``None``.
          aweights (Tensor): 1-D array of observation vector weights. These relative weights are
              typically large for observations considered "important" and smaller for
              observations considered less "important". If ``ddof=0`` the array of
              weights can be used to assign probabilities to observation vectors. (Default value = None)
  
  
      Returns:
        The covariance matrix of the variables.
      """
      # ensure at least 2D
      if observations.dim() == 1:
          observations = observations.view(-1, 1)
  
      # treat each column as a data point, each row as a variable
      if rowvar and observations.shape[0] != 1:
          observations = observations.t()
  
      if ddof is None:
          if bias == 0:
              ddof = 1
          else:
              ddof = 0
  
      weights = aweights
      weights_sum: Any
  
      if weights is not None:
          if not torch.is_tensor(weights):
              weights = torch.tensor(
                  weights, dtype=torch.float
              )  # pylint: disable=not-callable
          weights_sum = torch.sum(weights)
          avg = torch.sum(
              observations * (weights / weights_sum)[:, None], 0
          )
      else:
          avg = torch.mean(observations, 0)
  
      # Determine the normalization
      if weights is None:
          fact = observations.shape[0] - ddof
      elif ddof == 0:
          fact = weights_sum
      elif aweights is None:
          fact = weights_sum - ddof
      else:
          fact = (
              weights_sum
              - ddof * torch.sum(weights * weights) / weights_sum
          )
  
      observations_m = observations.sub(avg.expand_as(observations))
  
      if weights is None:
          x_transposed = observations_m.t()
      else:
          x_transposed = torch.mm(
              torch.diag(weights), observations_m
          ).t()
  
      covariance = torch.mm(x_transposed, observations_m)
      covariance = covariance / fact
  
      return covariance.squeeze()
  
file_path: anomalib/src/anomalib/models/components/stats/multi_variate_gaussian.py
imports: from __future__ import annotations
  from typing import Any
  import torch
  from torch import Tensor, nn
label_desc: Use image node_id 2 for calling the MultiVariateGaussian obj's underlying member method code with example usage: obj._cov(observations, rowvar, bias, ddof, aweights) and returns: covariance