lmdk_lib: Randomized response

This commit is contained in:
Manos Katsomallos 2021-09-29 01:03:50 +02:00
parent b408b55d56
commit ecd7719616

View File

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