code: Add laplace noise
This commit is contained in:
		@ -68,6 +68,21 @@ def randomized_response(r, epsilon):
 | 
				
			|||||||
    return not r
 | 
					    return not r
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def add_laplace_noise(value, sens, epsilon):
 | 
				
			||||||
 | 
					  '''
 | 
				
			||||||
 | 
					    Add random noise to a data value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Parameteres:
 | 
				
			||||||
 | 
					      value   - The value to add noise to.
 | 
				
			||||||
 | 
					      sens    - The query function sensitivity.
 | 
				
			||||||
 | 
					      epsilon - The privacy budget. 
 | 
				
			||||||
 | 
					    Returns:
 | 
				
			||||||
 | 
					      The value with the noise.
 | 
				
			||||||
 | 
					  '''
 | 
				
			||||||
 | 
					  return np.random.laplace(value, sens/epsilon)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def draw_line(line, x, label, marker):
 | 
					def draw_line(line, x, label, marker):
 | 
				
			||||||
  axis_x = list(range(len(x)))
 | 
					  axis_x = list(range(len(x)))
 | 
				
			||||||
  # plt.xticks(axis_x, x)
 | 
					  # plt.xticks(axis_x, x)
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user