From 9fe7106475ada1eebdb195e354df4671ecd6fc85 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 20 Jun 2017 17:10:36 -0400 Subject: [PATCH] privacy calculator --- priv_calc.py | 47 ++++++++++++++++++++++++++++++ privacy_accountant/__init__.pyc | Bin 145 -> 146 bytes privacy_accountant/accountant.pyc | Bin 17011 -> 17030 bytes privacy_accountant/utils.pyc | Bin 5262 -> 5269 bytes 4 files changed, 47 insertions(+) create mode 100644 priv_calc.py diff --git a/priv_calc.py b/priv_calc.py new file mode 100644 index 0000000..49cf19d --- /dev/null +++ b/priv_calc.py @@ -0,0 +1,47 @@ +import tensorflow as tf +from privacy_accountant import accountant, utils +import argparse +import time + +import pickle as pkl + +def calc_priv(noise, epochs, training_size, batch_size): + privacy_history = [] + with tf.Session() as sess: + eps = tf.placeholder(tf.float32) + delta = tf.placeholder(tf.float32) + + num_batches = epochs * (training_size / batch_size) + target_eps = [0.125,0.25,0.5,1,2,4,8] + priv_accountant = accountant.GaussianMomentsAccountant(training_size) + + print('accum privacy, batches: ' + str(num_batches)) + priv_start_time = time.clock() + privacy_accum_op = priv_accountant.accumulate_privacy_spending( + [None, None], args.noise, batch_size) + tf.global_variables_initializer().run() + for index in range(num_batches): + with tf.control_dependencies([privacy_accum_op]): + spent_eps_deltas = priv_accountant.get_privacy_spent( + sess, target_eps=target_eps) + privacy_history.append(spent_eps_deltas) + sess.run([privacy_accum_op]) + + print('priv time: ', time.clock() - priv_start_time) + + if spent_eps_deltas[-3][1] > 0.0001: + raise Exception('spent privacy') + + pkl.dump(privacy_history, open('./privacy/' + str(noise) + '_' + + str(epochs) + '_' + str(training_size) + '_' + str(batch_size) + + '.p', 'wb')) + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("--noise", type=float, default=8) + parser.add_argument("--epochs", type=int, default=500) + parser.add_argument("--training_size", type=int, default=6000) + parser.add_argument("--batch_size", type=int, default=1) + args = parser.parse_args() + + calc_priv(args.noise, args.epochs, args.training_size, args.batch_size) diff --git a/privacy_accountant/__init__.pyc b/privacy_accountant/__init__.pyc index 0c6adb8e20df99e9a3cddf4e6026894f0b32a1ac..382fe3129693849a7d0a2f4656c89a9c94e6b983 100644 GIT binary patch delta 30 lcmbQpIEj&i`7QblQ*hcZ02G&XGIrl;^|{T6Pp~! zUxO-SzL{5GArHFPJDGS!R56RqeR9`WP{qtAIk0YCshomt%Vs~dC}i!MH>w|HM$3=H}i`MIf+<(+Ic^RpYXq6k@RZsF-;LKT`E z!e4_VqHk)kSx8_34~me@<{vUqj7UQAP8OS|$X#PW5&~&lqnv?e`sOe-42_@Edzn!+ zPClr;0##)5YMm+$gwSSv(~roOf$UGRnvZUbvt0~A&t#yBCO@=$hbAKEFbPfMse>(= NNQ&b|BoTS1bO4VqWb*(3 diff --git a/privacy_accountant/utils.pyc b/privacy_accountant/utils.pyc index 4596230f6c3ecb8648e88c76401f4627d72e9496..ed8307f7e5ec86a82f8062064902f19dac5a8129 100644 GIT binary patch delta 151 zcmeCvoT|ye{F#^QVUuU%Mh<@_E(-<*2K~_D)S}|e2~4%f{K*MS#+xNsyI7FafW_`} ereTOR@_k}NSGQhZ0=jvVtA*F0DVv-sq6q+aJ1SHF delta 140 zcmbQL*{8|D{F#@l-1SGqMh<@_PICqZ2K|iu+|