old_contents: import numpy as np
  
  def calculate_class_weights(Y, n_classes, method="paszke", c=1.02):
      # CLASS PROBABILITIES - based on empirical observation of data
      ids, counts = np.unique(Y, return_counts=True)
      n_pixels = Y.size
      p_class = np.zeros(n_classes)
      p_class[ids] = counts/n_pixels
  
      # CLASS WEIGHTS
      if method == "paszke":
          weights = 1/np.log(c+p_class)
      elif method == "eigen":
          assert False, "TODO: Implement eigen method"
          # TODO: Implement eigen method
          # where class_freq is the number of pixels of class c divided by
          # the total number of pixels in images where c is actually present,
          # and median freq is the median of these frequencies.
      elif method in {"eigen2", "logeigen2"}:
          epsilon = 1e-8 # to prevent division by 0
          median = np.median(p_class)
          weights = median/(p_class+epsilon)
          if method == "logeigen2":
              weights = np.log(weights+1)
      else:
          assert False, "Incorrect choice for method"
  
      return weights
  
new_contents: import numpy as np
  
  # ==============================================================================
  #                                                        CALCULATE_CLASS_WEIGHTS
  # ==============================================================================
  def calculate_class_weights(Y, n_classes, method="paszke", c=1.02):
      """ Given the training data labels Calculates the class weights.
  
      Args:
          Y:      (numpy array) The training labels as class id integers.
                  The shape does not matter, as long as each element represents
                  a class id (ie, NOT one-hot-vectors).
          n_classes: (int) Number of possible classes.
          method: (str) The type of class weighting to use.
  
                  - "paszke" = use the method from from Paszke et al 2016
                              `1/ln(c + class_probability)`
                  - "eigen"  = use the method from Eigen & Fergus 2014.
                               `median_freq/class_freq`
                               where `class_freq` is based only on images that
                               actually contain that class.
                  - "eigen2" = Similar to `eigen`, except that class_freq is
                               based on the frequency of the class in the
                               entire dataset, not just images where it occurs.
                  -"logeigen2" = takes the log of "eigen2" method, so that
                              incredibly rare classes do not completely overpower
                              other values.
          c:      (float) Coefficient to use, when using paszke method.
  
      Returns:
          weights:    (numpy array) Array of shape [n_classes] assigning a
                      weight value to each class.
  
      References:
          Eigen & Fergus 2014: https://arxiv.org/abs/1411.4734
          Paszke et al 2016: https://arxiv.org/abs/1606.02147
      """
      # CLASS PROBABILITIES - based on empirical observation of data
      ids, counts = np.unique(Y, return_counts=True)
      n_pixels = Y.size
      p_class = np.zeros(n_classes)
      p_class[ids] = counts/n_pixels
  
      # CLASS WEIGHTS
      if method == "paszke":
          weights = 1/np.log(c+p_class)
      elif method == "eigen":
          assert False, "TODO: Implement eigen method"
          # TODO: Implement eigen method
          # where class_freq is the number of pixels of class c divided by
          # the total number of pixels in images where c is actually present,
          # and median freq is the median of these frequencies.
      elif method in {"eigen2", "logeigen2"}:
          epsilon = 1e-8 # to prevent division by 0
          median = np.median(p_class)
          weights = median/(p_class+epsilon)
          if method == "logeigen2":
              weights = np.log(weights+1)
      else:
          assert False, "Incorrect choice for method"
  
      return weights
  
subject: Add docstring for calculate_class_weights()