code: Add laplace noise

This commit is contained in:
Manos Katsomallos 2021-09-29 19:56:38 +02:00
parent 62ea90ecf7
commit dd3cff7b30

View File

@ -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)