lmdk_lib: Randomized response
This commit is contained in:
parent
b408b55d56
commit
ecd7719616
@ -48,6 +48,26 @@ def add_polar_noise(loc, epsilon):
|
|||||||
return new_loc
|
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):
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user