code: def select_instance(
      X_training: modALinput,
      X_pool: modALinput,
      X_uncertainty: np.ndarray,
      mask: np.ndarray,
      metric: Union[str, Callable],
      n_jobs: Union[int, None],
  ) -> Tuple[np.ndarray, modALinput, np.ndarray]:
      """
      Core iteration strategy for selecting another record from our unlabeled records.
  
      Given a set of labeled records (X_training) and unlabeled records (X_pool) with uncertainty scores (X_uncertainty),
      we'd like to identify the best instance in X_pool that best balances uncertainty and dissimilarity.
  
      Refer to Cardoso et al.'s "Ranked batch-mode active learning":
          https://www.sciencedirect.com/science/article/pii/S0020025516313949
  
      TODO:
          - Add notebook for Active Learning bake-off (passive vs interactive vs batch vs ranked batch)
  
      Args:
          X_training: Mix of both labeled and unlabeled records.
          X_pool: Unlabeled records to be selected for labeling.
          X_uncertainty: Uncertainty scores for unlabeled records to be selected for labeling.
          mask: Mask to exclude previously selected instances from the pool.
          metric: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`.
          n_jobs: This parameter is passed to :func:`~sklearn.metrics.pairwise.pairwise_distances`.
  
      Returns:
          Index of the best index from X chosen to be labelled; a single record from our unlabeled set that is considered
          the most optimal incremental record for including in our query set.
      """
      X_pool_masked = X_pool[mask]
  
      # Extract the number of labeled and unlabeled records.
      n_labeled_records, *rest = X_training.shape
      n_unlabeled, *rest = X_pool_masked.shape
  
      # Determine our alpha parameter as |U| / (|U| + |D|). Note that because we
      # append to X_training and remove from X_pool within `ranked_batch`,
      # :alpha: is not fixed throughout our model's lifetime.
      alpha = n_unlabeled / (n_unlabeled + n_labeled_records)
  
      # Compute pairwise distance (and then similarity) scores from every unlabeled record
      # to every record in X_training. The result is an array of shape (n_samples, ).
  
      if n_jobs == 1 or n_jobs is None:
          _, distance_scores = pairwise_distances_argmin_min(
              X_pool_masked.reshape(n_unlabeled, -1),
              X_training.reshape(n_labeled_records, -1),
              metric=metric,
          )
      else:
          distance_scores = pairwise_distances(
              X_pool_masked.reshape(n_unlabeled, -1),
              X_training.reshape(n_labeled_records, -1),
              metric=metric,
              n_jobs=n_jobs,
          ).min(axis=1)
  
      similarity_scores = 1 / (1 + distance_scores)
  
      # Compute our final scores, which are a balance between how dissimilar a given record
      # is with the records in X_uncertainty and how uncertain we are about its class.
      scores = (
          alpha * (1 - similarity_scores)
          + (1 - alpha) * X_uncertainty[mask]
      )
  
      # Isolate and return our best instance for labeling as the one with the largest score.
      best_instance_index_in_unlabeled = np.argmax(scores)
      n_pool, *rest = X_pool.shape
      unlabeled_indices = [i for i in range(n_pool) if mask[i]]
      best_instance_index = unlabeled_indices[
          best_instance_index_in_unlabeled
      ]
      mask[best_instance_index] = 0
      return best_instance_index, X_pool[[best_instance_index]], mask
  
file_path: modAL/modAL/batch.py
imports: from typing import Callable, Optional, Tuple, Union
  import numpy
  import scipy.sparse
  from sklearn.metrics.pairwise import pairwise_distances, pairwise_distances_argmin_min
  from modAL.models.base import BaseCommittee, BaseLearner
  from modAL.uncertainty import classifier_uncertainty
  from modAL.utils.data import data_shape, data_vstack, modALinput
label_desc: Use image node_id 2 for calling a global function with example usage: select_instance(X_training, X_pool, X_uncertainty, mask, metric, n_jobs) and returns: best_instance_index,  X_pool,  mask