docstr: Defines the optimization loss
docstr_tok: ["Defines","the","optimization","loss"]
code: def do_loss_initializations(
      self,
      yloss_type="hinge_loss",
      diversity_loss_type="dpp_style:inverse_dist",
      feature_weights="inverse_mad",
  ):
      """Defines the optimization loss"""
  
      # define the loss parts
      self.yloss_type = yloss_type
      self.diversity_loss_type = diversity_loss_type
  
      self.loss_weights = [
          self.yloss_type,
          self.diversity_loss_type,
          feature_weights,
      ]
  
      # loss part 1: y-loss
      self.yloss = self.compute_yloss(self.yloss_type)
  
      # loss part 2: similarity between CFs and original instance
      if feature_weights == "inverse_mad":
          normalized_mads = self.data_interface.get_valid_mads(
              normalized=True
          )
          feature_weights = {}
          for feature in normalized_mads:
              feature_weights[feature] = round(
                  1 / normalized_mads[feature], 2
              )
  
      feature_weights_list = []
      for feature in self.data_interface.ohe_encoded_feature_names:
          if feature in feature_weights:
              feature_weights_list.append(feature_weights[feature])
          else:
              feature_weights_list.append(1.0)
      feature_weights_list = [feature_weights_list]
  
      self.feature_weights = tf.Variable(self.minx, dtype=tf.float32)
      self.dice_sess.run(
          tf.assign(
              self.feature_weights,
              np.array(feature_weights_list, dtype=np.float32),
          )
      )
  
      self.proximity_loss = self.compute_proximity_loss()
  
      # loss part 3: diversity between CFs
      if self.total_random_inits > 0:
          # random initialization method
          self.diversity_loss = tf.constant(0.0, dtype=tf.float32)
      else:
          self.diversity_loss = self.compute_diversity_loss(
              self.diversity_loss_type
          )
  
      # loss part 4: diversity between CFs
      self.regularization_loss = self.compute_regularization_loss()
  
      # final loss:
      self.loss = tf.add(
          tf.subtract(
              tf.add(
                  self.yloss,
                  tf.scalar_mul(self.weights[0], self.proximity_loss),
              ),
              tf.scalar_mul(self.weights[1], self.diversity_loss),
          ),
          tf.scalar_mul(self.weights[2], self.regularization_loss),
      )
  
imports: import collections
  import copy
  import random
  import timeit
  import numpy
  import tensorflow
  from dice_ml import diverse_counterfactuals
  from dice_ml.counterfactual_explanations import CounterfactualExplanations
  from dice_ml.explainer_interfaces.explainer_base import ExplainerBase
label_desc: Use image node_id 12 for calling the DiceTensorFlow1 obj's underlying member method code with example usage: obj.do_loss_initializations(yloss_type, diversity_loss_type, feature_weights) without return types