-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
153 lines (129 loc) · 3.68 KB
/
benchmark.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from dpgen import privatize
from dpgen.algorithms import sparse_vector_private, noisy_max_bq, partial_sum as partial_sum_fx, \
smart_sum as smart_sum_fx, adaptive_svt_private, numsvt
from dpgen.frontend import ListBound
from dpgen.frontend.annotation import output, is_private
def noisy_max(q: list[float], size: int):
i, bq, imax = 0, 0, 0
while i < size:
if q[i] > bq or i == 0:
imax = i
bq = q[i]
i = i + 1
output(imax)
def sparse_vector(q: list[float], size: int, t: float, n: int):
i, count = 0, 0
while i < size and count < n:
if q[i] >= t:
output(True)
count += 1
else:
output(False)
i = i + 1
def sparse_vector_inverse(q: list[float], size: int, t: float, n: int):
i, count = 0, 0
while i < size and count < n:
if q[i] >= t:
output(True)
else:
output(False)
count += 1
i = i + 1
def adaptive_sparse_vector(q: list[float], size: int, t: float, sigma: float):
i = 0
while is_private and i < size:
if q[i] - t >= sigma:
output(q[i] - t)
else:
if q[i] - t >= 0:
output(q[i] - t)
else:
output(0)
i = i + 1
def gap_sparse_vector(q: list[float], size: int, t: float, n: int):
i, count = 0, 0
while i < size and count < n:
if q[i] >= t:
output(q[i] - t)
count += 1
else:
output(False)
i = i + 1
def num_sparse_vector(q: list[float], size: int, t: float, n: int):
i, count = 0, 0
while i < size and count < n:
if q[i] >= t:
output(q[i])
count += 1
else:
output(False)
i = i + 1
def partial_sum(q: list[float], size: int):
i, vsum = 0, 0
while i < size:
vsum = vsum + q[i]
i = i + 1
output(vsum)
def smart_sum(q: list[float], size: int, t: int, m: int):
i, vnext, vsum = 0, 0, 0
while i < size and i <= t:
if (i + 1) % m == 0:
vnext = vsum + q[i]
vsum = 0
output(vnext)
else:
vnext = vnext + q[i]
vsum = vsum + q[i]
output(vnext)
i = i + 1
def main():
privatize(
sparse_vector,
sparse_vector_private.main,
privates={'q'},
constraint=lambda q, size, t, n: n < len(q) / 5,
original_bounds={'n': lambda q, t, n: (0, len(q))},
related_bounds={'q': ListBound.ALL_DIFFER}
)
privatize(
num_sparse_vector,
numsvt.main,
privates={'q'},
constraint=lambda q, size, t, n: n < len(q) / 5,
original_bounds={'n': lambda q, t, n: (0, len(q))},
related_bounds={'q': ListBound.ALL_DIFFER}
)
privatize(
smart_sum,
smart_sum_fx.main,
privates={'q'},
constraint=lambda q, size, t, m: t < m,
original_bounds={'m': lambda q, t, n: (0, len(q))},
related_bounds={'q': ListBound.ONE_DIFFER}
)
privatize(
partial_sum,
partial_sum_fx.main,
privates={'q'},
constraint=None,
original_bounds={},
related_bounds={'q': ListBound.ONE_DIFFER}
)
privatize(
adaptive_sparse_vector,
adaptive_svt_private.main,
privates={'q'},
constraint=None,
original_bounds={},
related_bounds={'q': ListBound.ONE_DIFFER}
)
privatize(
noisy_max,
noisy_max_bq.main,
privates={'q'},
constraint=None,
original_bounds={},
related_bounds={'q': ListBound.ALL_DIFFER}
)
if __name__ == '__main__':
main()