code: Experiments for sel-eps
This commit is contained in:
		@ -29,13 +29,13 @@ def main(args):
 | 
				
			|||||||
  lmdks_pct = [0, 20, 40, 60, 80, 100]
 | 
					  lmdks_pct = [0, 20, 40, 60, 80, 100]
 | 
				
			||||||
  # The privacy budget
 | 
					  # The privacy budget
 | 
				
			||||||
  epsilon = 1.0
 | 
					  epsilon = 1.0
 | 
				
			||||||
  eps_pct = [20, 40, 60, 80]
 | 
					  eps_pct = [.201, .51, .725, .95]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  markers = [
 | 
					  markers = [
 | 
				
			||||||
    '^', # 20
 | 
					    '^',
 | 
				
			||||||
    'v', # 40
 | 
					    'v',
 | 
				
			||||||
    'D', # 60
 | 
					    'D',
 | 
				
			||||||
    's'  # 80
 | 
					    's'
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  print('\n##############################', d, '\n')
 | 
					  print('\n##############################', d, '\n')
 | 
				
			||||||
@ -51,7 +51,6 @@ def main(args):
 | 
				
			|||||||
  plt.xlim(x_i.min(), x_i.max())
 | 
					  plt.xlim(x_i.min(), x_i.max())
 | 
				
			||||||
  # The y axis
 | 
					  # The y axis
 | 
				
			||||||
  plt.ylabel('Mean absolute error (%)')  # Set y axis label.
 | 
					  plt.ylabel('Mean absolute error (%)')  # Set y axis label.
 | 
				
			||||||
  # plt.yscale('log')
 | 
					 | 
				
			||||||
  plt.ylim(0, 100)
 | 
					  plt.ylim(0, 100)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mae_evt = 0
 | 
					  mae_evt = 0
 | 
				
			||||||
@ -86,14 +85,13 @@ def main(args):
 | 
				
			|||||||
    plt.plot(
 | 
					    plt.plot(
 | 
				
			||||||
      x_i,
 | 
					      x_i,
 | 
				
			||||||
      mae,
 | 
					      mae,
 | 
				
			||||||
      label=str(e/100) + 'ε',
 | 
					      label='{0:.2f}'.format(e) + 'ε',
 | 
				
			||||||
      marker=markers[i_e],
 | 
					      marker=markers[i_e],
 | 
				
			||||||
      markersize=lmdk_lib.marker_size,
 | 
					      markersize=lmdk_lib.marker_size,
 | 
				
			||||||
      markeredgewidth=0,
 | 
					      markeredgewidth=0,
 | 
				
			||||||
      linewidth=lmdk_lib.line_width
 | 
					      linewidth=lmdk_lib.line_width
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
  plt.axhline(
 | 
					  plt.axhline(
 | 
				
			||||||
    y = mae_evt,
 | 
					    y = mae_evt,
 | 
				
			||||||
    color = '#212121',
 | 
					    color = '#212121',
 | 
				
			||||||
 | 
				
			|||||||
@ -27,13 +27,13 @@ def main(args):
 | 
				
			|||||||
  lmdks_th = [0, .54, .68, .88, 1.12, 10]
 | 
					  lmdks_th = [0, .54, .68, .88, 1.12, 10]
 | 
				
			||||||
  # The privacy budget
 | 
					  # The privacy budget
 | 
				
			||||||
  epsilon = 1.0
 | 
					  epsilon = 1.0
 | 
				
			||||||
  eps_pct = [20, 40, 60, 80]
 | 
					  eps_pct = [.01, .1, .25, .5]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  markers = [
 | 
					  markers = [
 | 
				
			||||||
    '^', # 20
 | 
					    '^',
 | 
				
			||||||
    'v', # 40
 | 
					    'v',
 | 
				
			||||||
    'D', # 60
 | 
					    'D',
 | 
				
			||||||
    's'  # 80
 | 
					    's'
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  print('\n##############################', d, '\n')
 | 
					  print('\n##############################', d, '\n')
 | 
				
			||||||
@ -47,8 +47,8 @@ def main(args):
 | 
				
			|||||||
  plt.xlim(x_i.min(), x_i.max())
 | 
					  plt.xlim(x_i.min(), x_i.max())
 | 
				
			||||||
  # The y axis
 | 
					  # The y axis
 | 
				
			||||||
  plt.ylabel('Mean absolute error (kWh)')  # Set y axis label.
 | 
					  plt.ylabel('Mean absolute error (kWh)')  # Set y axis label.
 | 
				
			||||||
  plt.yscale('log')
 | 
					  # plt.yscale('log')
 | 
				
			||||||
  plt.ylim(.1, 100000)
 | 
					  # plt.ylim(.1, 100000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  mae_evt = 0
 | 
					  mae_evt = 0
 | 
				
			||||||
  mae_usr = 0
 | 
					  mae_usr = 0
 | 
				
			||||||
@ -61,11 +61,10 @@ def main(args):
 | 
				
			|||||||
      lmdks = seq[seq[:, 1] < lmdks_th[i]]
 | 
					      lmdks = seq[seq[:, 1] < lmdks_th[i]]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      for _ in range(args.iter):
 | 
					      for _ in range(args.iter):
 | 
				
			||||||
 | 
					        lmdks_sel = lmdk_sel.find_lmdks_eps(seq, lmdks, epsilon*e)
 | 
				
			||||||
        lmdks = lmdk_sel.find_lmdks_eps(seq, lmdks, epsilon*e/100)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Uniform
 | 
					        # Uniform
 | 
				
			||||||
        rls_data, _ = lmdk_bgt.uniform_cons(seq, lmdks, epsilon*(1 - e/100))
 | 
					        rls_data, _ = lmdk_bgt.uniform_cons(seq, lmdks_sel, epsilon*(1 - e))
 | 
				
			||||||
        mae[i] += lmdk_bgt.mae_cons(seq, rls_data)/args.iter
 | 
					        mae[i] += lmdk_bgt.mae_cons(seq, rls_data)/args.iter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # Calculate once
 | 
					        # Calculate once
 | 
				
			||||||
@ -82,7 +81,7 @@ def main(args):
 | 
				
			|||||||
    plt.plot(
 | 
					    plt.plot(
 | 
				
			||||||
      x_i,
 | 
					      x_i,
 | 
				
			||||||
      mae,
 | 
					      mae,
 | 
				
			||||||
      label=str(e/100) + 'ε',
 | 
					      label='{0:.2f}'.format(e) + 'ε',
 | 
				
			||||||
      marker=markers[i_e],
 | 
					      marker=markers[i_e],
 | 
				
			||||||
      markersize=lmdk_lib.marker_size,
 | 
					      markersize=lmdk_lib.marker_size,
 | 
				
			||||||
      markeredgewidth=0,
 | 
					      markeredgewidth=0,
 | 
				
			||||||
@ -94,14 +93,14 @@ def main(args):
 | 
				
			|||||||
    color = '#212121',
 | 
					    color = '#212121',
 | 
				
			||||||
    linewidth=lmdk_lib.line_width
 | 
					    linewidth=lmdk_lib.line_width
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  plt.text(x_i[-1] + x_i[-1]*.01, mae_evt - mae_evt*.14, 'event')
 | 
					  plt.text(x_i[-1] + x_i[-1]*.01, mae_evt - mae_evt*.04, 'event')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  plt.axhline(
 | 
					  plt.axhline(
 | 
				
			||||||
    y = mae_usr,
 | 
					    y = mae_usr,
 | 
				
			||||||
    color = '#616161',
 | 
					    color = '#616161',
 | 
				
			||||||
    linewidth=lmdk_lib.line_width
 | 
					    linewidth=lmdk_lib.line_width
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
  plt.text(x_i[-1] + x_i[-1]*.01, mae_usr - mae_usr*.14, 'user')
 | 
					  plt.text(x_i[-1] + x_i[-1]*.01, mae_usr - mae_usr*.04, 'user')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  path = str('../../rslt/lmdk_sel_eps/' + d)
 | 
					  path = str('../../rslt/lmdk_sel_eps/' + d)
 | 
				
			||||||
  # Plot legend
 | 
					  # Plot legend
 | 
				
			||||||
 | 
				
			|||||||
@ -45,13 +45,13 @@ def main(args):
 | 
				
			|||||||
  bgt_conf = [
 | 
					  bgt_conf = [
 | 
				
			||||||
    {'epsilon': 1},
 | 
					    {'epsilon': 1},
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
  eps_pct = [20, 40, 60, 80]
 | 
					  eps_pct = [.01, .1, .25, .5]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  markers = [
 | 
					  markers = [
 | 
				
			||||||
    '^', # 20
 | 
					    '^',
 | 
				
			||||||
    'v', # 40
 | 
					    'v',
 | 
				
			||||||
    'D', # 60
 | 
					    'D',
 | 
				
			||||||
    's'  # 80
 | 
					    's'
 | 
				
			||||||
  ]
 | 
					  ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # The x axis
 | 
					  # The x axis
 | 
				
			||||||
@ -72,8 +72,6 @@ def main(args):
 | 
				
			|||||||
    plt.xlim(x_i.min(), x_i.max())
 | 
					    plt.xlim(x_i.min(), x_i.max())
 | 
				
			||||||
    # The y axis
 | 
					    # The y axis
 | 
				
			||||||
    plt.ylabel('Mean absolute error (m)')  # Set y axis label.
 | 
					    plt.ylabel('Mean absolute error (m)')  # Set y axis label.
 | 
				
			||||||
    plt.yscale('log')
 | 
					 | 
				
			||||||
    plt.ylim(1, 1000000)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mae_evt = 0
 | 
					    mae_evt = 0
 | 
				
			||||||
    mae_usr = 0
 | 
					    mae_usr = 0
 | 
				
			||||||
@ -88,10 +86,10 @@ def main(args):
 | 
				
			|||||||
        for bgt in bgt_conf:
 | 
					        for bgt in bgt_conf:
 | 
				
			||||||
          for _ in range(args.iter):
 | 
					          for _ in range(args.iter):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            lmdks = lmdk_sel.find_lmdks_eps(seq, lmdks, bgt['epsilon']*e/100)
 | 
					            lmdks_sel = lmdk_sel.find_lmdks_eps(seq, lmdks, bgt['epsilon']*e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Uniform
 | 
					            # Uniform
 | 
				
			||||||
            rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks, bgt['epsilon']*(1 - e/100))
 | 
					            rls_data_u, _ = lmdk_bgt.uniform_r(seq, lmdks_sel, bgt['epsilon']*(1 - e))
 | 
				
			||||||
            mae[i] += lmdk_bgt.mae(seq, rls_data_u)/args.iter
 | 
					            mae[i] += lmdk_bgt.mae(seq, rls_data_u)/args.iter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Calculate once
 | 
					            # Calculate once
 | 
				
			||||||
@ -108,7 +106,7 @@ def main(args):
 | 
				
			|||||||
      plt.plot(
 | 
					      plt.plot(
 | 
				
			||||||
        x_i,
 | 
					        x_i,
 | 
				
			||||||
        mae,
 | 
					        mae,
 | 
				
			||||||
        label=str(e/100) + 'ε',
 | 
					        label='{0:.2f}'.format(e) + 'ε',
 | 
				
			||||||
        marker=markers[i_e],
 | 
					        marker=markers[i_e],
 | 
				
			||||||
        markersize=lmdk_lib.marker_size,
 | 
					        markersize=lmdk_lib.marker_size,
 | 
				
			||||||
        markeredgewidth=0,
 | 
					        markeredgewidth=0,
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user