code: def information_density(
      X: modALinput, metric: Union[str, Callable] = "euclidean"
  ) -> np.ndarray:
      """
      Calculates the information density metric of the given data using the given metric.
  
      Args:
          X: The data for which the information density is to be calculated.
          metric: The metric to be used. Should take two 1d numpy.ndarrays for argument.
  
      Todo:
          Should work with all possible modALinput.
          Perhaps refactor the module to use some stuff from sklearn.metrics.pairwise
  
      Returns:
          The information density for each sample.
      """
      # inf_density = np.zeros(shape=(X.shape[0],))
      # for X_idx, X_inst in enumerate(X):
      #     inf_density[X_idx] = sum(similarity_measure(X_inst, X_j) for X_j in X)
      #
      # return inf_density/X.shape[0]
  
      similarity_mtx = 1 / (1 + pairwise_distances(X, X, metric=metric))
  
      return similarity_mtx.mean(axis=1)
  
imports: from typing import Callable, Union
  import numpy
  from scipy.spatial.distance import cosine, euclidean
  from sklearn.metrics.pairwise import pairwise_distances
  from modAL.utils.data import modALinput
label_desc: Use image node_id 2 for calling a global function with example usage: information_density(X, metric) and returns: similarity_mtx