lmdk_sel: Tested the Eucl distance in exp_mech
This commit is contained in:
		@ -11,33 +11,34 @@ from matplotlib import pyplot as plt
 | 
			
		||||
import time
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
'''
 | 
			
		||||
  The scoring function.
 | 
			
		||||
 | 
			
		||||
  Parameters:
 | 
			
		||||
    data - The data.
 | 
			
		||||
    option - The option to evaluate.
 | 
			
		||||
  Returns:
 | 
			
		||||
    The score for the option.
 | 
			
		||||
'''
 | 
			
		||||
def score(data, option):
 | 
			
		||||
  '''
 | 
			
		||||
    The scoring function.
 | 
			
		||||
 | 
			
		||||
    Parameters:
 | 
			
		||||
      data - The data.
 | 
			
		||||
      option - The option to evaluate.
 | 
			
		||||
    Returns:
 | 
			
		||||
      The score for the option.
 | 
			
		||||
  '''
 | 
			
		||||
  return (option.sum() - data.sum())
 | 
			
		||||
  # return lmdk_lib.get_norm(data, option)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
'''
 | 
			
		||||
  The exponential mechanism.
 | 
			
		||||
 | 
			
		||||
  Parameters:
 | 
			
		||||
    x - The data.
 | 
			
		||||
    R - The possible outputs.
 | 
			
		||||
    u - The scoring function.
 | 
			
		||||
    delta - The sensitivity of the scoring function.
 | 
			
		||||
    epsilon - The privacy budget.
 | 
			
		||||
  Returns:
 | 
			
		||||
    res - A randomly sampled output.
 | 
			
		||||
    pr - The PDF of all possible outputs.
 | 
			
		||||
'''
 | 
			
		||||
def exponential(x, R, u, delta, epsilon):
 | 
			
		||||
  '''
 | 
			
		||||
    The exponential mechanism.
 | 
			
		||||
 | 
			
		||||
    Parameters:
 | 
			
		||||
      x - The data.
 | 
			
		||||
      R - The possible outputs.
 | 
			
		||||
      u - The scoring function.
 | 
			
		||||
      delta - The sensitivity of the scoring function.
 | 
			
		||||
      epsilon - The privacy budget.
 | 
			
		||||
    Returns:
 | 
			
		||||
      res - A randomly sampled output.
 | 
			
		||||
      pr - The PDF of all possible outputs.
 | 
			
		||||
  '''
 | 
			
		||||
  # Calculate the score for each element of R
 | 
			
		||||
  scores = [u(x, r) for r in R]
 | 
			
		||||
  # Normalize the scores between 0 and 1
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user