class_docstr: Classification module for KDE-based anomaly detection.
  
  Args:
      n_pca_components (int, optional): Number of PCA components. Defaults to 16.
      feature_scaling_method (FeatureScalingMethod, optional): Scaling method applied to features before passing to
          KDE. Options are `norm` (normalize to unit vector length) and `scale` (scale to max length observed in
          training).
      max_training_points (int, optional): Maximum number of training points to fit the KDE model. Defaults to 40000.
class_docstr_tok: ["Classification","module","for","KDE-based","anomaly","detection",".","Args",":","n_pca_components","(","int",",","optional",")",":","Number","of","PCA","components",".","Defaults","to","16.","feature_scaling_method","(","FeatureScalingMethod",",","optional",")",":","Scaling","method","applied","to","features","before","passing","to","KDE",".","Options","are","`","norm","`","(","normalize","to","unit","vector","length",")","and","`","scale","`","(","scale","to","max","length","observed","in","training",")",".","max_training_points","(","int",",","optional",")",":","Maximum","number","of","training","points","to","fit","the","KDE","model",".","Defaults","to","40000","."]
docstr: Compute the KDE scores.
  
  The scores calculated from the KDE model are converted to densities. If `as_log_likelihood` is set to true then
      the log of the scores are calculated.
  
  Args:
      features (Tensor): Features to which the PCA model is fit.
      as_log_likelihood (bool | None, optional): If true, gets log likelihood scores. Defaults to False.
  
  Returns:
      (Tensor): Score
docstr_tok: ["Compute","the","KDE","scores",".","The","scores","calculated","from","the","KDE","model","are","converted","to","densities",".","If","`","as_log_likelihood","`","is","set","to","true","then","the","log","of","the","scores","are","calculated",".","Args",":","features","(","Tensor",")",":","Features","to","which","the","PCA","model","is","fit",".","as_log_likelihood","(","bool","|","None",",","optional",")",":","If","true",",","gets","log","likelihood","scores",".","Defaults","to","False",".","Returns",":","(","Tensor",")",":","Score"]
code: def compute_kde_scores(
      self, features: Tensor, as_log_likelihood: bool | None = False
  ) -> Tensor:
      """Compute the KDE scores.
  
      The scores calculated from the KDE model are converted to densities. If `as_log_likelihood` is set to true then
          the log of the scores are calculated.
  
      Args:
          features (Tensor): Features to which the PCA model is fit.
          as_log_likelihood (bool | None, optional): If true, gets log likelihood scores. Defaults to False.
  
      Returns:
          (Tensor): Score
      """
  
      features = self.pca_model.transform(features)
      features, _ = self.pre_process(features, self.max_length)
      # Scores are always assumed to be passed as a density
      kde_scores = self.kde_model(features)
  
      # add small constant to avoid zero division in log computation
      kde_scores += 1e-300
  
      if as_log_likelihood:
          kde_scores = torch.log(kde_scores)
  
      return kde_scores
  
file_path: anomalib/src/anomalib/models/components/classification/kde_classifier.py
imports: from __future__ import annotations
  import logging
  import random
  from enum import Enum
  import torch
  from torch import Tensor, nn
  from anomalib.models.components import PCA, GaussianKDE
label_desc: Use image node_id 4 for calling the KDEClassifier obj's underlying member method code with example usage: obj.compute_kde_scores(features, as_log_likelihood) and returns: kde_scores