forked from HongshengHu/source-inference-FL
/
testlaplace.py
16 lines (12 loc) · 1.05 KB
/
testlaplace.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import numpy as np
from utils.differential_privacy import add_laplace_noise
# Example usage
original_data = [-0.7570070624351501, -3.921947479248047, 2.576183795928955, 0.40031731128692627, -0.6036755442619324, -4.666325569152832, -2.5149288177490234, -4.3778395652771, -1.6322020292282104, 5.242119312286377] # Replace with your data
epsilon = 1 # Privacy budget for each element
lower_bound = min(original_data) # Adjust as per your data range
upper_bound = max(original_data) # Adjust as per your data range
noisy_data = add_laplace_noise(original_data, epsilon, lower_bound, upper_bound)
print(original_data)
print(noisy_data)
# flat_list:[-0.7570070624351501, -3.921947479248047, 2.576183795928955, 0.40031731128692627, -0.6036755442619324, -4.666325569152832, -2.5149288177490234, -4.3778395652771, -1.6322020292282104, 5.242119312286377]
# noised_list:[5.066565297877848, 4.8775640905412825, 4.4039015279724625, 9.905550805516217, -22.171473033430637, -2.729137650090255, 9.56071524971529, -8.339841728959271, 2.400700976561846, 1.702835333825174]