class_docstr: Container class to run and log the change of distance ratios
  between intra-class distances and inter-class distances.
class_docstr_tok: ["Container","class","to","run","and","log","the","change","of","distance","ratios","between","intra-class","distances","and","inter-class","distances","."]
docstr: Compute distance ratios of intra- and interclass distance.
  
  Args:
      model: PyTorch Network, network that produces the resp. embeddings.
      epoch: Current epoch.
  Returns:
      Nothing!
docstr_tok: ["Compute","distance","ratios","of","intra-","and","interclass","distance",".","Args",":","model",":","PyTorch","Network",",","network","that","produces","the","resp",".","embeddings",".","epoch",":","Current","epoch",".","Returns",":","Nothing","!"]
code: def measure(self, model, epoch):
      """
      Compute distance ratios of intra- and interclass distance.
  
      Args:
          model: PyTorch Network, network that produces the resp. embeddings.
          epoch: Current epoch.
      Returns:
          Nothing!
      """
      if epoch % self.update_epochs:
          return
  
      self.epochs.append(epoch)
  
      torch.cuda.empty_cache()
  
      _ = model.eval()
  
      # Compute Embeddings
      with torch.no_grad():
          feature_coll, target_coll = [], []
          data_iter = tqdm(
              self.checkdata, desc="Estimating Data Distances..."
          )
          for idx, data in enumerate(data_iter):
              input_img, target = data[1], data[0]
              features = model(input_img.to(self.pars.device))
              feature_coll.extend(
                  features.cpu().detach().numpy().tolist()
              )
              target_coll.extend(target.numpy().tolist())
  
      feature_coll = np.vstack(feature_coll).astype("float32")
      target_coll = np.hstack(target_coll).reshape(-1)
      avail_labels = np.unique(target_coll)
  
      # Compute indixes of embeddings for each class.
      class_positions = []
      for lab in avail_labels:
          class_positions.append(np.where(target_coll == lab)[0])
  
      # Compute average intra-class distance and center of mass.
      com_class, dists_class = [], []
      for class_pos in class_positions:
          dists = distance.cdist(
              feature_coll[class_pos], feature_coll[class_pos], "cosine"
          )
          dists = np.sum(dists) / (len(dists) ** 2 - len(dists))
          # dists = np.linalg.norm(np.std(feature_coll_aux[class_pos],axis=0).reshape(1,-1)).reshape(-1)
          com = normalize(
              np.mean(feature_coll[class_pos], axis=0).reshape(1, -1)
          ).reshape(-1)
          dists_class.append(dists)
          com_class.append(com)
  
      # Compute mean inter-class distances by the class-coms.
      mean_inter_dist = distance.cdist(
          np.array(com_class), np.array(com_class), "cosine"
      )
      mean_inter_dist = np.sum(mean_inter_dist) / (
          len(mean_inter_dist) ** 2 - len(mean_inter_dist)
      )
  
      # Compute distance ratio
      mean_class_dist = np.mean(np.array(dists_class) / mean_inter_dist)
      self.mean_class_dists.append(mean_class_dist)
  
      self.update(mean_class_dist)
  
imports: import warnings
  import csv
  import pickle
  import time
  import auxiliaries
  import matplotlib.pyplot
  import numpy
  import torch
  import torch.multiprocessing
  import torch.nn
  from scipy.spatial import distance
  from sklearn.preprocessing import normalize
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling the DistanceMeasure obj's underlying member method code with example usage: obj.measure(model, epoch) without return types