diff --git a/code/lib/lmdk_lib.py b/code/lib/lmdk_lib.py index 07a0c3f..2d1255d 100644 --- a/code/lib/lmdk_lib.py +++ b/code/lib/lmdk_lib.py @@ -68,6 +68,21 @@ def randomized_response(r, epsilon): 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): axis_x = list(range(len(x))) # plt.xticks(axis_x, x)