def task(args):
  import diffpri as dp
  n, d, e = args
  logging.info("n = %d, d = %d, e = %s", n, d, e)
  if n == 0 or np.isinf(e): # no pv data -> no clipping
    wx = 0.0
    wy = 0.0
  else:
    wx, wy = dp.omega(n,d,e,mcmc)
  ensure_dir_exists("drugsens_params/clipping")
  with open("drugsens_params/clipping/wx_n%d_d%d_e%s.txt" % (n, d, e), 'w') as f:
    f.write("%s" % wx)
  with open("drugsens_params/clipping/wy_n%d_d%d_e%s.txt" % (n, d, e), 'w') as f:
    f.write("%s" % wy)
if len(sys.argv) > 1:
	test = int(sys.argv[1])
else:
	print('No test specified as a command line argument. Choose 0 or 1.')
	sys.exit()

if test == 0:
	nx = len(eps)
	WX = np.zeros(nx,dtype=np.float)
	WY = np.zeros(nx,dtype=np.float)
	for i in range(len(eps)):
		e = eps[i]
		n_pv = 500
		n = n_pv	
		w_x,w_y = dp.omega(n,d,e,mcmc)
		WX[i] = w_x
		WY[i] = w_y
	np.savetxt(csvpath+'A-WX.csv',WX,delimiter=',')
	np.savetxt(csvpath+'A-WY.csv',WY,delimiter=',')

if test == 1:
	nx = len(pv_size)
	WX = np.zeros(nx,dtype=np.float)
	WY = np.zeros(nx,dtype=np.float)
	for i in range(len(pv_size)):
		n_pv = pv_size[i]
		n = n_pv	
		e = 2.0
		if i == 0: # no pv data -> no clipping
			WX[i] = 0.0
Beispiel #3
0
## NOTE: set these to match the values in tensor.py
#privacy budget: lists of similar length
eps = [1.0, 3.0, 5.0, 7.5, 10.0]
delta_list = np.zeros(shape=len(eps)) + 10e-4
np.random.seed(1)
ny = len(pv_size)
csvpath = ''  # path for output csv files
privacy_for_marg_var = .3  # .3 in the paper

nx = len(eps)
WX = np.zeros((ny, nx), dtype=np.float)
WY = np.zeros((ny, nx), dtype=np.float)
print('Finding optimal projection threshold...')
for i in range(len(pv_size)):
    for j in range(len(eps)):
        n = pv_size[i]
        d = 10

        e = eps[j] * (1 - privacy_for_marg_var)
        delta = delta_list[j] * (1 - privacy_for_marg_var)

        w_x, w_y = dp.omega(n, d, e, delta, method='corr', ln=10)
        WX[i, j] = w_x
        WY[i, j] = w_y

print('WX:\n' + str(WX))
print('WY:\n' + str(WY))
print('done!')
np.savetxt(csvpath + 'C-WX.csv', WX, delimiter=',')
np.savetxt(csvpath + 'C-WY.csv', WY, delimiter=',')
	# Budget split
	p1 = p[k]
	p2 = p[m]
	p3 = 1.0-p1-p2
	
	# Check if split is sensible
	t1 = minp <= p1 and p1 <= maxp
	t2 = minp <= p2 and p2 <= maxp
	t3 = minp <= p3 and p3 <= maxp

	if not all([t1,t2,t3]):
		continue

	# Clipping omega and thresholds
	w_x,w_y = dp.omega(n,d,eps,True,ln=ln,p1=p1,p2=p2,p3=p3)
	c1 = sx * w_x
	c2 = sy * w_y

	# Clip data
	xc,yc = dp.clip(x,y,c1,c2)

	# Perturbed suff.stats.
	xx = dp.nxx(xc) + W*(c1**2.0)/p1
	xy = dp.nxy(xc,yc) + L*c1*c2/p2
	yy = dp.nyy(yc) + V*(c2**2.0)/p3

	# Prediction
	pred = dp.doADVI(n,xx,xy,yy,x)

	# Precision