code: Ready for copenhagen
This commit is contained in:
@ -343,6 +343,61 @@ def adaptive(seq, lmdks, epsilon, inc_rt, dec_rt):
|
||||
return rls_data, bgts, skipped
|
||||
|
||||
|
||||
def adaptive_cont(seq, lmdks, epsilon, inc_rt, dec_rt):
|
||||
'''
|
||||
Adaptive budget allocation.
|
||||
|
||||
Parameters:
|
||||
seq - The point sequence.
|
||||
lmdks - The landmarks.
|
||||
epsilon - The available privacy budget.
|
||||
inc_rt - Sampling rate increase rate.
|
||||
dec_rt - Sampling rate decrease rate.
|
||||
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
|
||||
samp_rt = 1
|
||||
# Track landmarks
|
||||
lmdk_cur = 0
|
||||
# Track skipped releases
|
||||
skipped = 0
|
||||
for i, p in enumerate(seq):
|
||||
# Check if current point is a landmark
|
||||
r = p[2] in lmdks
|
||||
if r:
|
||||
lmdk_cur += 1
|
||||
if lmdk_lib.should_sample(samp_rt) or i == 0:
|
||||
# Add noise to original data
|
||||
o = lmdk_lib.randomized_response(r, bgts[i])
|
||||
rls_data[i] = [r, o]
|
||||
# Adjust sampling rate
|
||||
if i > 0:
|
||||
if rls_data[i - 1][1] == o:
|
||||
# Decrease
|
||||
samp_rt -= samp_rt*dec_rt
|
||||
else:
|
||||
# Increase
|
||||
samp_rt += (1 - samp_rt)*inc_rt
|
||||
else:
|
||||
skipped += 1
|
||||
# Skip current release and approximate with previous
|
||||
rls_data[i] = rls_data[i - 1]
|
||||
if r:
|
||||
# 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 skip(seq, lmdks, epsilon):
|
||||
'''
|
||||
Skip landmarks.
|
||||
|
Reference in New Issue
Block a user