code: def density_estimation(dists, nbrs, labels, **kwargs):
      """use supervised density defined on neigborhood"""
      num, k_knn = dists.shape
      conf = np.ones((num,), dtype=np.float32)
      ind_array = labels[nbrs] == np.expand_dims(labels, 1).repeat(
          k_knn, 1
      )
      pos = ((1 - dists[:, 1:]) * ind_array[:, 1:]).sum(1)
      neg = ((1 - dists[:, 1:]) * (1 - ind_array[:, 1:])).sum(1)
      conf = (pos - neg) * conf
      conf /= k_knn - 1
      return conf
  
imports: from itertools import groupby
  import numpy
  import torch
  from tqdm import tqdm
label_desc: Use image node_id 1 for calling a global function with example usage: density_estimation(dists, nbrs, labels) and returns: conf