docstr: Given the features contained in a result, it retrieves metadata such as the precision and
  coverage of the result and partial anchors and examples where the result/partial anchors
  apply and yield the same prediction as on the instance to be explained (`covered_true`)
  or a different prediction (`covered_false`).
  
  Parameters
  ----------
  features
      Sorted indices of features in result.
  success
      Indicates whether an anchor satisfying precision threshold was met or not.
  batch_size
      Number of samples among which positive and negative examples for partial anchors are
      selected if partial anchors have not already been explicitly sampled.
  
  Returns
  -------
  Anchor dictionary with result features and additional metadata.
docstr_tok: ["Given","the","features","contained","in","a","result",",","it","retrieves","metadata","such","as","the","precision","and","coverage","of","the","result","and","partial","anchors","and","examples","where","the","result\/partial","anchors","apply","and","yield","the","same","prediction","as","on","the","instance","to","be","explained","(","`","covered_true","`",")","or","a","different","prediction","(","`","covered_false","`",")",".","Parameters","--","--","--","--","--","features","Sorted","indices","of","features","in","result",".","success","Indicates","whether","an","anchor","satisfying","precision","threshold","was","met","or","not",".","batch_size","Number","of","samples","among","which","positive","and","negative","examples","for","partial","anchors","are","selected","if","partial","anchors","have","not","already","been","explicitly","sampled",".","Returns","--","--","--","-","Anchor","dictionary","with","result","features","and","additional","metadata","."]
code: def get_anchor_metadata(
      self, features: tuple, success, batch_size: int = 100
  ) -> dict:
      """
      Given the features contained in a result, it retrieves metadata such as the precision and
      coverage of the result and partial anchors and examples where the result/partial anchors
      apply and yield the same prediction as on the instance to be explained (`covered_true`)
      or a different prediction (`covered_false`).
  
      Parameters
      ----------
      features
          Sorted indices of features in result.
      success
          Indicates whether an anchor satisfying precision threshold was met or not.
      batch_size
          Number of samples among which positive and negative examples for partial anchors are
          selected if partial anchors have not already been explicitly sampled.
  
      Returns
      -------
      Anchor dictionary with result features and additional metadata.
      """
  
      state = self.state
      anchor: dict = {
          "feature": [],
          "mean": [],
          "precision": [],
          "coverage": [],
          "examples": [],
          "all_precision": 0,
          "num_preds": state["data"].shape[0],
          "success": success,
      }
      current_t: tuple = tuple()
      # draw pos and negative example where partial result applies if not sampled during search
      to_resample, to_resample_idx = [], []
      for f in state["t_order"][features]:
          current_t = self._sort(
              current_t + (f,), allow_duplicates=False
          )
          mean = (
              state["t_positives"][current_t]
              / state["t_nsamples"][current_t]
          )
          anchor["feature"].append(f)
          anchor["mean"].append(mean)
          anchor["precision"].append(mean)
          anchor["coverage"].append(state["t_coverage"][current_t])
  
          # add examples where result does or does not hold
          if current_t in state["t_covered_true"]:
              exs = {
                  "covered_true": state["t_covered_true"][current_t],
                  "covered_false": state["t_covered_false"][current_t],
                  "uncovered_true": np.array([]),
                  "uncovered_false": np.array([]),
              }
              anchor["examples"].append(exs)
          else:
              to_resample.append(current_t)
              # sampling process relies on ordering
              state["t_order"][current_t] = list(current_t)
              to_resample_idx.append(len(anchor["examples"]))
              anchor["examples"].append("placeholder")
              # if the anchor was not sampled, the coverage is not estimated
              anchor["coverage"][-1] = "placeholder"
  
      # If partial anchors have not been sampled, resample to find examples
      if to_resample:
          _, _ = self.draw_samples(to_resample, batch_size)
  
          while to_resample:
              feats, example_idx = (
                  to_resample.pop(),
                  to_resample_idx.pop(),
              )
              anchor["examples"][example_idx] = {
                  "covered_true": state["t_covered_true"][feats],
                  "covered_false": state["t_covered_false"][feats],
                  "uncovered_true": np.array([]),
                  "uncovered_false": np.array([]),
              }
              # update result with true coverage
              anchor["coverage"][example_idx] = state["t_coverage"][
                  feats
              ]
  
      return anchor
  
imports: import copy
  import logging
  from collections import defaultdict, namedtuple
  from typing import Callable, Dict, List, Optional, Set, Tuple
  import numpy
  from alibi.utils.distributions import kl_bernoulli
label_desc: Use image node_id 14 for calling the AnchorBaseBeam obj's underlying member method code with example usage: obj.get_anchor_metadata(features, success, batch_size) and returns: anchor