-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mechanism.py
72 lines (55 loc) · 2.06 KB
/
Mechanism.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from query import Type
from privacy.func import Strategy
from numpy import linalg as LA
class Mechanism:
"""privacy mechanism"""
def __init__(self):
self.query = ""
self.method = ""
self.alpha = 0
self.beta = 0
self.real_cost = 0
self.est_cost = 0
self.lap_b = 0
self.return_msg = Type.ReturnMsgType.SUCCESS
self.strategy = 0
self.strategy_sens = 0
self.strategy_pinv = 0
self.m_type = ""
def set_q(self, q):
self.query = q
self.m_type = q.m_type
def set_method(self, t):
self.method = t
def set_alpha(self, a):
self.alpha = a
def set_beta(self, b):
self.beta = b
def set_real_cost(self, c):
self.real_cost = c
def set_est_cost(self, c):
self.est_cost = c
def set_lap_b(self, b):
self.lap_b = b
def set_return_qd(self):
self.return_msg = Type.ReturnMsgType.QD
# for SM only
def set_strategy_h2(self):
self.strategy = Strategy.gen_strategy_h2(len(self.query.domain_hist)).toarray()
self.strategy_sens = LA.norm(self.strategy, 1)
self.strategy_pinv = LA.pinv(self.strategy)
# print("DEBUG: h2= ", self.strategy)
# print("DEBUG: h2= ", len(self.strategy), len(self.strategy[0]))
# print("DEBUG: h2_sens= ", self.strategy_sens)
def set_strategy_w(self):
# copy the workload matrix as the strategy
self.strategy = list(self.query.query_matrix)
self.strategy_sens = LA.norm(self.strategy, 1)
self.strategy_pinv = LA.pinv(self.strategy)
assert self.strategy_sens == self.query.get_sensitivity()
# print("DEBUG: w_strategy= ", len(self.strategy), len(self.strategy[0]))
# print("DEBUG: w_strategy_sens= ", self.strategy_sens)
def run(self):
print("DEBUG: alpha=", self.alpha, "\tbeta=", self.beta)
# return self.method(self.query, self.alpha, self.beta)
self.method(self)