Skip to content

Commit 4f5249e

Browse files
committed
Adding correct version of notebook
1 parent 3b7122b commit 4f5249e

File tree

1 file changed

+77
-28
lines changed

1 file changed

+77
-28
lines changed

notebooks/attack_database_reconstruction.ipynb

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"name": "stdout",
112112
"output_type": "stream",
113113
"text": [
114-
"Model accuracy (on the test dataset): 1.0\n"
114+
"Model accuracy (on the test dataset): 0.9666666666666667\n"
115115
]
116116
}
117117
],
@@ -156,21 +156,9 @@
156156
"cell_type": "code",
157157
"execution_count": 6,
158158
"metadata": {},
159-
"outputs": [
160-
{
161-
"ename": "ImportError",
162-
"evalue": "cannot import name 'DatabaseReconstruction'",
163-
"output_type": "error",
164-
"traceback": [
165-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
166-
"\u001b[0;31mImportError\u001b[0m Traceback (most recent call last)",
167-
"\u001b[0;32m<ipython-input-6-2dd2e9a7664c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mart\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mattacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minference\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mDatabaseReconstruction\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mdbrecon\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mDatabaseReconstruction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnon_private_art\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdbrecon\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreconstruct\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_public\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my_public\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
168-
"\u001b[0;31mImportError\u001b[0m: cannot import name 'DatabaseReconstruction'"
169-
]
170-
}
171-
],
159+
"outputs": [],
172160
"source": [
173-
"from art.attacks.inference import DatabaseReconstruction\n",
161+
"from art.attacks.inference.reconstruction import DatabaseReconstruction\n",
174162
"\n",
175163
"dbrecon = DatabaseReconstruction(non_private_art)\n",
176164
"\n",
@@ -186,9 +174,17 @@
186174
},
187175
{
188176
"cell_type": "code",
189-
"execution_count": null,
177+
"execution_count": 7,
190178
"metadata": {},
191-
"outputs": [],
179+
"outputs": [
180+
{
181+
"name": "stdout",
182+
"output_type": "stream",
183+
"text": [
184+
"Inference RMSE: 5.789723287688911e-08\n"
185+
]
186+
}
187+
],
192188
"source": [
193189
"print(\"Inference RMSE: {}\".format(\n",
194190
" np.sqrt(((x_train[target_row] - x) ** 2).sum() / x_train.shape[1])))"
@@ -203,9 +199,20 @@
203199
},
204200
{
205201
"cell_type": "code",
206-
"execution_count": null,
202+
"execution_count": 8,
207203
"metadata": {},
208-
"outputs": [],
204+
"outputs": [
205+
{
206+
"data": {
207+
"text/plain": [
208+
"True"
209+
]
210+
},
211+
"execution_count": 8,
212+
"metadata": {},
213+
"output_type": "execute_result"
214+
}
215+
],
209216
"source": [
210217
"np.argmax(y) == y_train[target_row]"
211218
]
@@ -233,9 +240,20 @@
233240
},
234241
{
235242
"cell_type": "code",
236-
"execution_count": null,
243+
"execution_count": 9,
237244
"metadata": {},
238-
"outputs": [],
245+
"outputs": [
246+
{
247+
"data": {
248+
"text/plain": [
249+
"0.7"
250+
]
251+
},
252+
"execution_count": 9,
253+
"metadata": {},
254+
"output_type": "execute_result"
255+
}
256+
],
239257
"source": [
240258
"from diffprivlib import models\n",
241259
"\n",
@@ -261,7 +279,7 @@
261279
},
262280
{
263281
"cell_type": "code",
264-
"execution_count": null,
282+
"execution_count": 10,
265283
"metadata": {},
266284
"outputs": [],
267285
"source": [
@@ -279,9 +297,17 @@
279297
},
280298
{
281299
"cell_type": "code",
282-
"execution_count": null,
300+
"execution_count": 11,
283301
"metadata": {},
284-
"outputs": [],
302+
"outputs": [
303+
{
304+
"name": "stdout",
305+
"output_type": "stream",
306+
"text": [
307+
"Inference RMSE (with differential privacy): 2.2594246979517965\n"
308+
]
309+
}
310+
],
285311
"source": [
286312
"print(\"Inference RMSE (with differential privacy): {}\".format(\n",
287313
" np.sqrt(((x_train[target_row] - x_dp) ** 2).sum() / x_train.shape[1])))"
@@ -296,11 +322,23 @@
296322
},
297323
{
298324
"cell_type": "code",
299-
"execution_count": null,
325+
"execution_count": 12,
300326
"metadata": {
301327
"scrolled": false
302328
},
303-
"outputs": [],
329+
"outputs": [
330+
{
331+
"data": {
332+
"text/plain": [
333+
"(array([[4.80000094, 3.00000298, 1.39999864, 0.30000296]]),\n",
334+
" array([6.4, 2.7, 5.3, 1.9]))"
335+
]
336+
},
337+
"execution_count": 12,
338+
"metadata": {},
339+
"output_type": "execute_result"
340+
}
341+
],
304342
"source": [
305343
"x_dp, x_train[target_row]"
306344
]
@@ -314,9 +352,20 @@
314352
},
315353
{
316354
"cell_type": "code",
317-
"execution_count": null,
355+
"execution_count": 13,
318356
"metadata": {},
319-
"outputs": [],
357+
"outputs": [
358+
{
359+
"data": {
360+
"text/plain": [
361+
"(0, 2)"
362+
]
363+
},
364+
"execution_count": 13,
365+
"metadata": {},
366+
"output_type": "execute_result"
367+
}
368+
],
320369
"source": [
321370
"np.argmax(y_dp), y_train[target_row]"
322371
]

0 commit comments

Comments
 (0)