def experiment5(): print('experiment5') n = 256 """Want to show that we can satisfy sharing incentive by running the entire workload together, but weighting the workload of each analyst in inverse proportion to the sensitivity of their workload """ """ This time we try scaling the big workload matrix""" #using experiment 1 as an example W1 = matrix.EkteloMatrix(np.random.rand(32, n)) W2 = matrix.EkteloMatrix(np.random.rand(32, n)) #W1 = workload.Prefix(n) #W2 = workload.Total(n) #W2 = workload.Identity(n) W = [W1, W2] #workload 1 with half the budget pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W1) print("Workload 1 with half the budget") err1 = error.expected_error(W1, pid.strategy(), eps=0.5) print(err1) pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W2) print("Workload 2 with half the budget") err2 = error.expected_error(W2, pid.strategy(), eps=0.5) print(err2) #both workloads together pid = fairtemplates.PIdentity(max(1, n // 16), n) pid.optimize(W) print("Both workloads with all the budgets") err1all = error.expected_error(W1, pid.strategy(), eps=1) err2all = error.expected_error(W2, pid.strategy(), eps=1) print("W1") print(err1all) print("W2") print(err2all) print("Are either of the analysts violating sharing incentive") print((err1all >= err1) or (err2all >= err2)) """Optimizing on egalitarian doesn't work either. it seems to be spending most of its time optimizing the more difficult queries. In fact it seems to be getting almost the exact same error should it have just optimized on the first one """ """ note results change if it's just total vs identity for the second workload.
def example1(): """ Optimize AllRange workload using PIdentity template and report the expected error """ print('Example 1') W = workload.AllRange(256) pid = templates.PIdentity(16, 256) res = pid.optimize(W) err = error.rootmse(W, pid.strategy()) err2 = error.rootmse(W, workload.Identity(256)) print(err, err2)
def experiment3(): print('experiment3') n = 256 """Want to show that we can satisfy sharing incentive by running the entire workload together, but weighting the workload of each analyst in inverse proportion to the sensitivity of their workload """ #using experiment 1 as an example W1 = workload.AllRange(n) #W2 = workload.Total(n) W2 = workload.Identity(n) W = workload.VStack([ matrix.EkteloMatrix(np.multiply(W1.matrix, (1 / W1.sensitivity()))), matrix.EkteloMatrix(np.multiply(W2.matrix, (1 / W2.sensitivity()))) ]) #workload 1 with half the budget pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W1) print("Workload 1 with half the budget") err1 = error.expected_error(W1, pid.strategy(), eps=0.5) print(err1) pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W2) print("Workload 2 with half the budget") err2 = error.expected_error(W2, pid.strategy(), eps=0.5) print(err2) #both workloads together pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W) print("Both workloads with all the budgets") err1all = error.expected_error(W1, pid.strategy(), eps=1) err2all = error.expected_error(W2, pid.strategy(), eps=1) print("W1") print(err1all) print("W2") print(err2all) print("Are either of the analysts violating sharing incentive") print((err1all >= err1) or (err2all >= err2)) """ Issue when you independently scale each matrix then merge you some of the
def experiment4(): print('experiment4') n = 256 """Want to show that we can satisfy sharing incentive by running the entire workload together, but weighting the workload of each analyst in inverse proportion to the sensitivity of their workload """ """ This time we try scaling the big workload matrix""" #using experiment 1 as an example W1 = workload.AllRange(n) #W2 = workload.Total(n) W2 = workload.Identity(n) W = workload.VStack([W1, W2]) W = matrix.EkteloMatrix((np.multiply(W.matrix, (1 / W.sensitivity())))) #workload 1 with half the budget pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W1) print("Workload 1 with half the budget") err1 = error.expected_error(W1, pid.strategy(), eps=0.5) print(err1) pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W2) print("Workload 2 with half the budget") err2 = error.expected_error(W2, pid.strategy(), eps=0.5) print(err2) #both workloads together pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W) print("Both workloads with all the budgets") err1all = error.expected_error(W1, pid.strategy(), eps=1) err2all = error.expected_error(W2, pid.strategy(), eps=1) print("W1") print(err1all) print("W2") print(err2all) print("Are either of the analysts violating sharing incentive") print((err1all >= err1) or (err2all >= err2)) """Doesn't work either. May work when the number of analysts scales too high.
def test_pidentity(self): pid = templates.PIdentity(2, 8) pid._set_workload(workload.Prefix(8)) x0 = self.prng.rand(16) func = lambda p: pid._loss_and_grad(p)[0] grad = lambda p: pid._loss_and_grad(p)[1] err = check_grad(func, grad, x0) print(err) self.assertTrue(err <= 1e-5)
def experiment1(): print('Experiment1') n = 256 """ We want an example to show that naively running HDMM on the entire workload ignoring identities of individual analysts does not satisfy sharing incentive. Intuitively, this should happen when one analyst has a much smaller/easier workload than the other analysts, such that their errors dominate the optimization """ W1 = workload.AllRange(n) W2 = workload.Total(n) #W2 = workload.IdentityTotal(n) W = workload.VStack([W1, W2]) #workload 1 with half the budget pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W1) print("Workload 1 with half the budget") err1 = error.expected_error(W1, pid.strategy(), eps=0.5) print(err1) pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W2) print("Workload 2 with half the budget") err2 = error.expected_error(W2, pid.strategy(), eps=0.5) print(err2) #both workloads together pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W) print("Both workloads with all the budgets") err1all = error.expected_error(W1, pid.strategy(), eps=1) err2all = error.expected_error(W2, pid.strategy(), eps=1) print("W1") print(err1all) print("W2") print(err2all) print("Are either of the analysts violating sharing incentive") print((err1all >= err1) or (err2all >= err2))
def experiment2(): print("experiment2") n = 256 """ We want to show that fixing this problem by partitioning the privacy budget and running each workload independently can make all of the agents worse off in terms of error (should be easy to see when the analysts have similar workloads).""" W1 = workload.Total(n) W1 = np.multiply(W1, 1.1) W2 = workload.Total(n) W = workload.VStack([W1, W2]) #workload 1 with half the budget pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W1) print("Workload 1 with half the budget") err1 = error.expected_error(W1, pid.strategy(), eps=0.5) print(err1) pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W2) print("Workload 2 with half the budget") err2 = error.expected_error(W2, pid.strategy(), eps=0.5) print(err2) #both workloads together pid = templates.PIdentity(max(1, n // 16), n) pid.optimize(W) print("Both workloads with all the budgets") err1all = error.expected_error(W1, pid.strategy(), eps=1) err2all = error.expected_error(W2, pid.strategy(), eps=1) print("W1") print(err1all) print("W2") print(err2all) print("Are both agents worse off by seperating their strategy") print((err1all < err1) and (err1all < err2))
def optimize(self, restarts = 25): W = self.W if type(self.domain) is tuple: # kron or union kron workload ns = self.domain ps = [max(1, n//16) for n in ns] kron = templates.KronPIdentity(ps, ns) optk, lossk = kron.restart_optimize(W, restarts) marg = templates.Marginals(ns) optm, lossm = marg.restart_optimize(W, restarts) # multiplicative factor puts losses on same scale if lossk <= lossm: self.strategy = optk else: self.strategy = optm else: n = self.domain pid = templates.PIdentity(max(1, n//16), n) optp, loss = pid.restart_optimize(W, restarts) self.strategy = optp