class_docstr: BoltOn episilon-delta differential privacy model.
  
  The privacy guarantees are dependent on the noise that is sampled. Please
  see the paper linked below for more details.
  
  Uses 4 key steps to achieve privacy guarantees:
  1. Adds noise to weights after training (output perturbation).
  2. Projects weights to R after each batch
  3. Limits learning rate
  4. Use a strongly convex loss function (see compile)
  
  For more details on the strong convexity requirements, see:
  Bolt-on Differential Privacy for Scalable Stochastic Gradient
  Descent-based Analytics by Xi Wu et al.
docstr: Calculates class weighting to be used in training.
  
  Args:
    class_weights: str specifying type, array giving weights, or None.
    class_counts: If class_weights is not None, then an array of the number of
      samples for each class
    num_classes: If class_weights is not None, then the number of classes.
  
  Returns:
    class_weights as 1D tensor, to be passed to model's fit method.
docstr_tok: ["Calculates","class","weighting","to","be","used","in","training",".","Args",":","class_weights",":","str","specifying","type",",","array","giving","weights",",","or","None",".","class_counts",":","If","class_weights","is","not","None",",","then","an","array","of","the","number","of","samples","for","each","class","num_classes",":","If","class_weights","is","not","None",",","then","the","number","of","classes",".","Returns",":","class_weights","as","1D","tensor",",","to","be","passed","to","model","'s","fit","method","."]
code: def calculate_class_weights(
      self, class_weights=None, class_counts=None, num_classes=None
  ):
      """Calculates class weighting to be used in training.
  
      Args:
        class_weights: str specifying type, array giving weights, or None.
        class_counts: If class_weights is not None, then an array of the number of
          samples for each class
        num_classes: If class_weights is not None, then the number of classes.
  
      Returns:
        class_weights as 1D tensor, to be passed to model's fit method.
      """
      # Value checking
      class_keys = ["balanced"]
      is_string = False
      if isinstance(class_weights, str):
          is_string = True
          if class_weights not in class_keys:
              raise ValueError(
                  "Detected string class_weights with "
                  "value: {0}, which is not one of {1}."
                  "Please select a valid class_weight type"
                  "or pass an array".format(class_weights, class_keys)
              )
          if class_counts is None:
              raise ValueError(
                  "Class counts must be provided if using "
                  "class_weights=%s" % class_weights
              )
          class_counts_shape = tf.Variable(
              class_counts, trainable=False, dtype=self._dtype
          ).shape
          if len(class_counts_shape) != 1:
              raise ValueError(
                  "class counts must be a 1D array."
                  "Detected: {0}".format(class_counts_shape)
              )
          if num_classes is None:
              raise ValueError(
                  "num_classes must be provided if using "
                  "class_weights=%s" % class_weights
              )
      elif class_weights is not None:
          if num_classes is None:
              raise ValueError(
                  "You must pass a value for num_classes if "
                  "creating an array of class_weights"
              )
      # performing class weight calculation
      if class_weights is None:
          class_weights = 1
      elif is_string and class_weights == "balanced":
          num_samples = sum(class_counts)
          weighted_counts = tf.dtypes.cast(
              tf.math.multiply(num_classes, class_counts), self._dtype
          )
          class_weights = tf.Variable(
              num_samples, dtype=self._dtype
          ) / tf.Variable(weighted_counts, dtype=self._dtype)
      else:
          class_weights = _ops.convert_to_tensor_v2(class_weights)
          if len(class_weights.shape) != 1:
              raise ValueError(
                  "Detected class_weights shape: {0} instead of "
                  "1D array".format(class_weights.shape)
              )
          if class_weights.shape[0] != num_classes:
              raise ValueError(
                  "Detected array length: {0} instead of: {1}".format(
                      class_weights.shape[0], num_classes
                  )
              )
      return class_weights
  
file_path: privacy/tensorflow_privacy/privacy/bolt_on/models.py
imports: import tensorflow.compat.v1
  from tensorflow.compat.v1.python.framework import ops
  from tensorflow.compat.v1.python.keras import optimizers
  from tensorflow.compat.v1.python.keras.models import Model
  from tensorflow_privacy.privacy.bolt_on.losses import StrongConvexMixin
  from tensorflow_privacy.privacy.bolt_on.optimizers import BoltOn
label_desc: Use image node_id 6 for calling the BoltOnModel obj's underlying member method code with example usage: obj.calculate_class_weights(class_weights, class_counts, num_classes) and returns: class_weights