code: def get_distortion_compas(vold, vnew):
      """Distortion function for the compas dataset. We set the distortion
      metric here. See section 4.3 in supplementary material of
      http://papers.nips.cc/paper/6988-optimized-pre-processing-for-discrimination-prevention
      for an example
  
      Note:
          Users can use this as templates to create other distortion functions.
  
      Args:
          vold (dict) : {attr:value} with old values
          vnew (dict) : dictionary of the form {attr:value} with new values
  
      Returns:
          d (value) : distortion value
      """
      # Distortion cost
      distort = {}
      distort["two_year_recid"] = pd.DataFrame(
          {"No recid.": [0.0, 2.0], "Did recid.": [2.0, 0.0]},
          index=["No recid.", "Did recid."],
      )
      distort["age_cat"] = pd.DataFrame(
          {
              "Less than 25": [0.0, 1.0, 2.0],
              "25 to 45": [1.0, 0.0, 1.0],
              "Greater than 45": [2.0, 1.0, 0.0],
          },
          index=["Less than 25", "25 to 45", "Greater than 45"],
      )
      distort["c_charge_degree"] = pd.DataFrame(
          {"M": [0.0, 2.0], "F": [1.0, 0.0]}, index=["M", "F"]
      )
      distort["priors_count"] = pd.DataFrame(
          {
              "0": [0.0, 1.0, 2.0],
              "1 to 3": [1.0, 0.0, 1.0],
              "More than 3": [2.0, 1.0, 0.0],
          },
          index=["0", "1 to 3", "More than 3"],
      )
      distort["sex"] = pd.DataFrame(
          {0.0: [0.0, 2.0], 1.0: [2.0, 0.0]}, index=[0.0, 1.0]
      )
      distort["race"] = pd.DataFrame(
          {0.0: [0.0, 2.0], 1.0: [2.0, 0.0]}, index=[0.0, 1.0]
      )
  
      total_cost = 0.0
      for k in vold:
          if k in vnew:
              total_cost += distort[k].loc[vnew[k], vold[k]]
  
      return total_cost
  
imports: import numpy
  import pandas
label_desc: Use image node_id 3 for calling a global function with example usage: get_distortion_compas(vold, vnew) and returns: total_cost