code: def multidim_scaling(
      d_pair: dict,
      n_components: int = 2,
      use_metric: bool = True,
      standardize_cat_vars: bool = True,
      feature_range: tuple = None,
      smooth: float = 1.0,
      center: bool = True,
      update_feature_range: bool = True,
  ) -> Tuple[dict, tuple]:
      """
      Apply multidimensional scaling to pairwise distance matrices.
  
      Parameters
      ----------
      d_pair
          Dict with as keys the column index of the categorical variables and as values
          a pairwise distance matrix for the categories of the variable.
      n_components
          Number of dimensions in which to immerse the dissimilarities.
      use_metric
          If True, perform metric MDS; otherwise, perform nonmetric MDS.
      standardize_cat_vars
          Standardize numerical values of categorical variables if True.
      feature_range
          Tuple with min and max ranges to allow for perturbed instances. Min and max ranges can be floats or
          numpy arrays with dimension (1 x nb of features) for feature-wise ranges.
      smooth
          Smoothing exponent between 0 and 1 for the distances. Lower values of l will smooth the difference in
          distance metric between different features.
      center
          Whether to center the scaled distance measures. If False, the min distance for each feature
          except for the feature with the highest raw max distance will be the lower bound of the
          feature range, but the upper bound will be below the max feature range.
      update_feature_range
          Update feature range with scaled values.
  
      Returns
      -------
      Dict with multidimensional scaled version of pairwise distance matrices.
      """
      d_abs = {}
      d_min, d_max = 1e10, 0
      for k, v in d_pair.items():
          # distance smoothening
          v **= smooth
          # fit multi-dimensional scaler
          mds = MDS(
              n_components=n_components,
              max_iter=5000,
              eps=1e-9,
              random_state=0,
              n_init=4,
              dissimilarity="precomputed",
              metric=use_metric,
          )
          d_fit = mds.fit(v)
          emb = d_fit.embedding_  # coordinates in embedding space
          # use biggest single observation Frobenius norm as origin
          origin = np.argsort(np.linalg.norm(emb, axis=1))[-1]
          # calculate distance from origin for each category
          d_origin = np.linalg.norm(
              emb - emb[origin].reshape(1, -1), axis=1
          )
          # assign to category
          d_abs[k] = d_origin
          # update min and max distance
          d_min_k, d_max_k = d_origin.min(), d_origin.max()
          d_min = d_min_k if d_min_k < d_min else d_min
          d_max = d_max_k if d_max_k > d_max else d_max
  
      d_abs_scaled = {}
      new_feature_range = tuple([f.copy() for f in feature_range])
      for k, v in d_abs.items():
          if (
              standardize_cat_vars
          ):  # scale numerical values for the category
              d_scaled = (v - v.mean()) / (v.std() + 1e-12)
          else:  # scale by overall min and max
              try:
                  rng = (feature_range[0][0, k], feature_range[1][0, k])
              except TypeError:
                  raise TypeError(
                      "Feature-wise min and max ranges need to be specified."
                  )
              d_scaled = (v - d_min) / (d_max - d_min) * (
                  rng[1] - rng[0]
              ) + rng[0]
              if (
                  center
              ):  # center the numerical feature values between the min and max feature range
                  d_scaled -= 0.5 * (d_scaled.max() + d_scaled.min())
          if update_feature_range:
              new_feature_range[0][0, k] = d_scaled.min()
              new_feature_range[1][0, k] = d_scaled.max()
          d_abs_scaled[
              k
          ] = d_scaled  # scaled distance from the origin for each category
  
      if update_feature_range:
          feature_range = new_feature_range
  
      return d_abs_scaled, feature_range
  
file_path: alibi-detect/alibi_detect/utils/distance.py
imports: import numpy
  from sklearn.manifold import MDS
  from typing import Any, Dict, Tuple
label_desc: Use image node_id 6 for calling a global function with example usage: multidim_scaling(d_pair, n_components, use_metric, standardize_cat_vars, feature_range, smooth, center, update_feature_range) and returns: d_abs_scaled,  feature_range