class_docstr: Implementation of the top-k intersection by Theiner et al., 2021.
  
  The TopKIntersection implements the pixel-wise intersection between a ground truth target object mask and
  an "explainer" mask, the binarized version of the explanation. High scores are desired, as the
  overlap between the ground truth object mask and the attribution mask should be maximal.
  
  References:
      1) Jonas Theiner et al.: "Interpretable Semantic Photo
      Geolocalization." arXiv preprint arXiv:2104.14995 (2021).
  
  Attributes:
      -  _name: The name of the metric.
      - _data_applicability: The data types that the metric implementation currently supports.
      - _models: The model types that this metric can work with.
      - score_direction: How to interpret the scores, whether higher/ lower values are considered better.
      - evaluation_category: What property/ explanation quality that this metric measures.
class_docstr_tok: ["Implementation","of","the","top-k","intersection","by","Theiner","et","al.",",","2021",".","The","TopKIntersection","implements","the","pixel-wise","intersection","between","a","ground","truth","target","object","mask","and","an","``","explainer","''","mask",",","the","binarized","version","of","the","explanation",".","High","scores","are","desired",",","as","the","overlap","between","the","ground","truth","object","mask","and","the","attribution","mask","should","be","maximal",".","References",":","1",")","Jonas","Theiner","et","al",".",":","``","Interpretable","Semantic","Photo","Geolocalization",".","''","arXiv","preprint","arXiv:2104.14995","(","2021",")",".","Attributes",":","-","_name",":","The","name","of","the","metric",".","-","_data_applicability",":","The","data","types","that","the","metric","implementation","currently","supports",".","-","_models",":","The","model","types","that","this","metric","can","work","with",".","-","score_direction",":","How","to","interpret","the","scores",",","whether","higher\/","lower","values","are","considered","better",".","-","evaluation_category",":","What","property\/","explanation","quality","that","this","metric","measures","."]
docstr: Evaluate instance gets model and data for a single instance as input and returns the evaluation result.
  
  Parameters
  ----------
  a: np.ndarray
      The explanation to be evaluated on an instance-basis.
  s: np.ndarray
      The segmentation to be evaluated on an instance-basis.
  
  Returns
  -------
  float
      The evaluation results.
docstr_tok: ["Evaluate","instance","gets","model","and","data","for","a","single","instance","as","input","and","returns","the","evaluation","result",".","Parameters","--","--","--","--","--","a",":","np.ndarray","The","explanation","to","be","evaluated","on","an","instance-basis",".","s",":","np.ndarray","The","segmentation","to","be","evaluated","on","an","instance-basis",".","Returns","--","--","--","-","float","The","evaluation","results","."]
code: def evaluate_instance(
      self,
      a: np.ndarray,
      s: np.ndarray,
  ):
      """
      Evaluate instance gets model and data for a single instance as input and returns the evaluation result.
  
      Parameters
      ----------
      a: np.ndarray
          The explanation to be evaluated on an instance-basis.
      s: np.ndarray
          The segmentation to be evaluated on an instance-basis.
  
      Returns
      -------
      float
          The evaluation results.
      """
  
      if np.sum(s) == 0:
          warn.warn_empty_segmentation()
          return np.nan
  
      # Prepare shapes.
      s = s.astype(bool)
      top_k_binary_mask = np.zeros(a.shape)
  
      # Sort and create masks.
      sorted_indices = np.argsort(a, axis=None)
      np.put_along_axis(
          top_k_binary_mask, sorted_indices[-self.k :], 1, axis=None
      )
      top_k_binary_mask = top_k_binary_mask.astype(bool)
  
      # Top-k intersection.
      tki = 1.0 / self.k * np.sum(np.logical_and(s, top_k_binary_mask))
  
      # Concept influence (with size of object normalised tki score).
      if self.concept_influence:
          tki = np.prod(s.shape) / np.sum(s) * tki
  
      return tki
  
file_path: Quantus/quantus/metrics/localisation/top_k_intersection.py
imports: import sys
  from typing import Any, Callable, Dict, List, Optional
  import numpy
  from quantus.helpers import asserts, warn
  from quantus.helpers.enums import DataType, EvaluationCategory, ModelType, ScoreDirection
  from quantus.metrics.base import Metric
label_desc: Use image node_id 3 for calling the TopKIntersection obj's underlying member method code with example usage: obj.evaluate_instance(a, s) and returns: tki, np