lmdk_bgt.incremental: Initial commit
This commit is contained in:
parent
5f7c9d0945
commit
51943bbef3
@ -467,6 +467,67 @@ def discount(seq, lmdks, epsilon):
|
|||||||
return rls_data, bgts, skipped
|
return rls_data, bgts, skipped
|
||||||
|
|
||||||
|
|
||||||
|
def incremental(seq, lmdks, epsilon, diff_rt):
|
||||||
|
'''
|
||||||
|
Incremental sampling.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
seq - The point sequence.
|
||||||
|
lmdks - The landmarks.
|
||||||
|
epsilon - The available privacy budget.
|
||||||
|
diff_rt - Sampling rate difference.
|
||||||
|
Returns:
|
||||||
|
rls_data - The perturbed data.
|
||||||
|
bgts - The privacy budget allocation.
|
||||||
|
skipped - The number of skipped releases.
|
||||||
|
'''
|
||||||
|
# Uniform budget allocation
|
||||||
|
bgts = uniform(seq, lmdks, epsilon)
|
||||||
|
# Released
|
||||||
|
rls_data = [None]*len(seq)
|
||||||
|
# The sampling rate
|
||||||
|
# (publish with 50% chance)
|
||||||
|
samp_rt = .5
|
||||||
|
# Track landmarks
|
||||||
|
lmdk_cur = 0
|
||||||
|
# Track consecutive landmarks
|
||||||
|
lmdk_con = 0
|
||||||
|
# Track skipped releases
|
||||||
|
skipped = 0
|
||||||
|
for i, p in enumerate(seq):
|
||||||
|
# Check if current point is a landmark
|
||||||
|
if lmdk_lib.is_landmark(p, lmdks):
|
||||||
|
lmdk_cur += 1
|
||||||
|
# Increase sampling rate
|
||||||
|
samp_rt += (1 - samp_rt)*diff_rt
|
||||||
|
else:
|
||||||
|
# Decrease sampling rate
|
||||||
|
samp_rt -= samp_rt*diff_rt
|
||||||
|
# Get coordinates
|
||||||
|
loc = (p[1], p[2])
|
||||||
|
if i == 0 or lmdk_lib.should_sample(samp_rt):
|
||||||
|
# Add noise to original data
|
||||||
|
new_loc = lmdk_lib.add_polar_noise(loc, bgts[i])
|
||||||
|
rls_data[i] = [p[0], new_loc[0], new_loc[1], p[3]]
|
||||||
|
# Adjust sampling rate
|
||||||
|
if lmdk_lib.is_landmark(p, lmdks):
|
||||||
|
# Adjust consecutive landmarks tracking
|
||||||
|
lmdk_con += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
# Skip current release and approximate with previous
|
||||||
|
rls_data[i] = rls_data[i - 1]
|
||||||
|
if lmdk_lib.is_landmark(p, lmdks):
|
||||||
|
# Reset consecutive landmarks tracking
|
||||||
|
lmdk_con = 0
|
||||||
|
# Allocate the current budget to the following releases uniformly
|
||||||
|
for j in range(i + 1, len(seq)):
|
||||||
|
bgts[j] += bgts[i]/(len(lmdks) - lmdk_cur + 1)
|
||||||
|
# No budget was spent
|
||||||
|
bgts[i] = 0
|
||||||
|
return rls_data, bgts, skipped
|
||||||
|
|
||||||
|
|
||||||
def uniform_r(seq, lmdks, epsilon):
|
def uniform_r(seq, lmdks, epsilon):
|
||||||
# Released
|
# Released
|
||||||
rls_data = [None]*len(seq)
|
rls_data = [None]*len(seq)
|
||||||
|
Loading…
Reference in New Issue
Block a user