class_docstr: Generate Anomaly Heatmap.
class_docstr_tok: ["Generate","Anomaly","Heatmap","."]
docstr: Compute score based on the distance.
  
  Args:
      distance (Tensor): Distance tensor computed using target oriented
          features.
      scale (tuple[int, int]): Height and width of the largest feature
          map.
  
  Returns:
      Tensor: Score value.
docstr_tok: ["Compute","score","based","on","the","distance",".","Args",":","distance","(","Tensor",")",":","Distance","tensor","computed","using","target","oriented","features",".","scale","(","tuple","[","int",",","int","]",")",":","Height","and","width","of","the","largest","feature","map",".","Returns",":","Tensor",":","Score","value","."]
code: def compute_score(
      self, distance: Tensor, scale: tuple[int, int]
  ) -> Tensor:
      """Compute score based on the distance.
  
      Args:
          distance (Tensor): Distance tensor computed using target oriented
              features.
          scale (tuple[int, int]): Height and width of the largest feature
              map.
  
      Returns:
          Tensor: Score value.
      """
      distance = torch.sqrt(distance)
      distance = distance.topk(
          self.num_nearest_neighbors, largest=False
      ).values
      distance = (F.softmin(distance, dim=-1)[:, :, 0]) * distance[
          :, :, 0
      ]
      distance = distance.unsqueeze(-1)
  
      score = rearrange(
          distance, "b (h w) c -> b c h w", h=scale[0], w=scale[1]
      )
      return score.detach()
  
file_path: anomalib/src/anomalib/models/cfa/anomaly_map.py
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from einops import rearrange
  from omegaconf import ListConfig
  from torch import Tensor, nn
  from anomalib.models.components import GaussianBlur2d
label_desc: Use image node_id 2 for calling the AnomalyMapGenerator obj's underlying member method code with example usage: obj.compute_score(distance, scale) and returns: score