diff --git a/code/lib/lmdk_lib.py b/code/lib/lmdk_lib.py index d34ed17..4271001 100644 --- a/code/lib/lmdk_lib.py +++ b/code/lib/lmdk_lib.py @@ -48,6 +48,26 @@ def add_polar_noise(loc, epsilon): return new_loc +def randomized_response(r, epsilon): + ''' + Return the original response with probability p, + or flip the response with probability 1 - p. + [https://www.usenix.org/system/files/conference/usenixsecurity17/sec17-wang-tianhao.pdf] + + Parameters: + r - The original response (True/False). + epsilon - The privacy budget. + Returns: + The randomized response. + ''' + # Return the original value + if random.uniform(0, 1) <= math.exp(epsilon)/(math.exp(epsilon) + 1): + return r + # Flip the original value + else: + return not r + + def draw_line(line, x, label, marker): axis_x = list(range(len(x))) # plt.xticks(axis_x, x)