class_docstr: The DAGMM module used in the DAGMM detector.
  
  :meta private:
code: def compute_energy(
      self, z, phi=None, mu=None, cov=None, size_average=True, eps=1e-6
  ):
      phi = self.phi if phi is None else phi
      mu = self.mu if mu is None else mu
      cov = self.cov if cov is None else cov
  
      cov_inv, cov_det, cov_diag = [], [], 0
      for i in range(cov.shape[0]):
          cov_k = (
              cov[i] + torch.eye(cov.shape[1], device=self.device) * eps
          )
          inv_k = torch.tensor(
              np.linalg.pinv(cov_k.cpu().data.numpy()),
              dtype=torch.float,
              device=self.device,
          )
          cov_inv.append(inv_k.unsqueeze(0))
          eigenvalues = np.linalg.eigvals(
              cov_k.data.cpu().numpy() * (2 * np.pi)
          )
          determinant = np.prod(
              np.clip(eigenvalues, a_min=eps, a_max=None)
          )
          cov_det.append(determinant)
          cov_diag += torch.sum(1.0 / cov_k.diag())
  
      z_mu = z.unsqueeze(1) - mu.unsqueeze(0)
      cov_inv = torch.cat(cov_inv, dim=0)
      cov_det = torch.tensor(
          cov_det, dtype=torch.float, device=self.device
      )
      exp_term_tmp = -0.5 * torch.sum(
          torch.sum(z_mu.unsqueeze(-1) * cov_inv.unsqueeze(0), dim=-2)
          * z_mu,
          dim=-1,
      )
      max_val = torch.max(
          exp_term_tmp.clamp(min=0), dim=1, keepdim=True
      )[0]
      exp_term = torch.exp(exp_term_tmp - max_val)
  
      sample_energy = -max_val.squeeze() - torch.log(
          torch.sum(
              phi.unsqueeze(0)
              * exp_term
              / (torch.sqrt(cov_det) + eps).unsqueeze(0),
              dim=1,
          )
          + eps
      )
      if size_average:
          sample_energy = torch.mean(sample_energy)
      return sample_energy, cov_diag
  
imports: import copy
  import random
  from typing import List
  import numpy
  import pandas
  from merlion.utils import TimeSeries
  from merlion.models.base import NormalizingConfig
  from merlion.models.anomaly.base import DetectorBase, DetectorConfig, MultipleTimeseriesDetectorMixin
  from merlion.post_process.threshold import AggregateAlarms
  from merlion.utils.misc import ProgressBar, initializer
  from merlion.models.utils.rolling_window_dataset import RollingWindowDataset
label_desc: Use image node_id 5 for calling the DAGMMModule obj's underlying member method code with example usage: obj.compute_energy(z, phi, mu, cov, size_average, eps) and returns: sample_energy,  cov_diag