class_docstr: Grouped KNN density estimator.
  
  Keeps track of the group (e.g. video id) from which the features were sampled for normalization purposes.
  
  Args:
      n_neighbors (int): Number of neighbors used in KNN search.
docstr: Predict the (normalized) density for a set of features.
  
  Args:
      features (Tensor): Input features that will be compared to the density model.
      group (Any, optional): Group (video id) from which the features originate. If passed, all features of the
          same group in the memory bank will be excluded from the density estimation.
      n_neighbors (int): Number of neighbors used in the KNN search.
      normalize (bool): Flag indicating if the density should be normalized to min-max stats of the feature bank.
  Returns:
      Tensor: Mean (normalized) distances of input feature vectors to k nearest neighbors in feature bank.
code: def predict(
      self,
      features: Tensor,
      group: Any = None,
      n_neighbors: int = 1,
      normalize: bool = True,
  ) -> Tensor:
      """Predict the (normalized) density for a set of features.
  
      Args:
          features (Tensor): Input features that will be compared to the density model.
          group (Any, optional): Group (video id) from which the features originate. If passed, all features of the
              same group in the memory bank will be excluded from the density estimation.
          n_neighbors (int): Number of neighbors used in the KNN search.
          normalize (bool): Flag indicating if the density should be normalized to min-max stats of the feature bank.
      Returns:
          Tensor: Mean (normalized) distances of input feature vectors to k nearest neighbors in feature bank.
      """
      n_neighbors = n_neighbors or self.n_neighbors
  
      if group:
          mem_bank = self.memory_bank.copy()
          mem_bank.pop(group)
      else:
          mem_bank = self.memory_bank
  
      mem_bank_tensor = torch.vstack(list(mem_bank.values()))
  
      distances = self._nearest_neighbors(
          mem_bank_tensor, features, n_neighbors=n_neighbors
      )
  
      if normalize:
          distances = self._normalize(distances)
  
      return distances.mean(axis=1)
  
imports: from __future__ import annotations
  from abc import ABC, abstractmethod
  from typing import Any
  import torch
  from sklearn.mixture import GaussianMixture
  from torch import Tensor, nn
  from anomalib.models.ai_vad.features import FeatureType
  from anomalib.utils.metrics.min_max import MinMax
label_desc: Use image node_id 4 for calling the GroupedKNNEstimator obj's underlying member method code with example usage: obj.predict(features, group, n_neighbors, normalize) and returns: distances