From bcbb0c9553d3e15470ef78b18c697d9f8be945e3 Mon Sep 17 00:00:00 2001 From: woodyx218 Date: Wed, 22 Jan 2020 10:42:27 +0800 Subject: [PATCH] Add files via upload --- tutorials/adult_tutorial.py | 9 +++++---- tutorials/imdb_tutorial.py | 10 +++++----- tutorials/movielens_tutorial.py | 10 +++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/tutorials/adult_tutorial.py b/tutorials/adult_tutorial.py index 0e6c546..4867792 100644 --- a/tutorials/adult_tutorial.py +++ b/tutorials/adult_tutorial.py @@ -43,6 +43,7 @@ flags.DEFINE_integer('epochs', 20, 'Number of epochs') flags.DEFINE_integer('max_mu', 2, 'GDP upper limit') flags.DEFINE_string('model_dir', None, 'Model directory') +sampling_batch = 256 microbatches = 256 num_examples = 29305 @@ -136,11 +137,11 @@ def main(unused_argv): shuffle=False) # Training loop. - steps_per_epoch = num_examples // microbatches + steps_per_epoch = num_examples // sampling_batch test_accuracy_list = [] for epoch in range(1, FLAGS.epochs + 1): for step in range(steps_per_epoch): - whether = np.random.random_sample(num_examples) > (1-microbatches/num_examples) + whether = np.random.random_sample(num_examples) > (1-sampling_batch/num_examples) subsampling = [i for i in np.arange(num_examples) if whether[i]] global microbatches microbatches = len(subsampling) @@ -162,8 +163,8 @@ def main(unused_argv): # Compute the privacy budget expended so far. if FLAGS.dpsgd: - eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, 256, 1e-5) - mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, 256) + eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch, 1e-5) + mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch) print('For delta=1e-5, the current epsilon is: %.2f' % eps) print('For delta=1e-5, the current mu is: %.2f' % mu) diff --git a/tutorials/imdb_tutorial.py b/tutorials/imdb_tutorial.py index babf0ad..03a1a34 100644 --- a/tutorials/imdb_tutorial.py +++ b/tutorials/imdb_tutorial.py @@ -43,7 +43,7 @@ flags.DEFINE_integer('epochs', 25, 'Number of epochs') flags.DEFINE_integer('max_mu', 2, 'GDP upper limit') flags.DEFINE_string('model_dir', None, 'Model directory') - +sampling_batch = 512 microbatches = 512 max_features = 10000 @@ -137,12 +137,12 @@ def main(unused_argv): shuffle=False) # Training loop. - steps_per_epoch = num_examples // microbatches + steps_per_epoch = num_examples // sampling_batch test_accuracy_list = [] for epoch in range(1, FLAGS.epochs + 1): for step in range(steps_per_epoch): - whether = np.random.random_sample(num_examples) > (1-microbatches/num_examples) + whether = np.random.random_sample(num_examples) > (1-sampling_batch/num_examples) subsampling = [i for i in np.arange(num_examples) if whether[i]] global microbatches microbatches = len(subsampling) @@ -164,8 +164,8 @@ def main(unused_argv): # Compute the privacy budget expended so far. if FLAGS.dpsgd: - eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, microbatches, 1e-5) - mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, microbatches) + eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch, 1e-5) + mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch) print('For delta=1e-5, the current epsilon is: %.2f' % eps) print('For delta=1e-5, the current mu is: %.2f' % mu) diff --git a/tutorials/movielens_tutorial.py b/tutorials/movielens_tutorial.py index 2dc625a..af4e189 100644 --- a/tutorials/movielens_tutorial.py +++ b/tutorials/movielens_tutorial.py @@ -44,7 +44,7 @@ flags.DEFINE_integer('epochs', 25, 'Number of epochs') flags.DEFINE_integer('max_mu', 2, 'GDP upper limit') flags.DEFINE_string('model_dir', None, 'Model directory') - +sampling_batch = 10000 microbatches = 10000 num_examples = 800167 @@ -171,11 +171,11 @@ def main(unused_argv): shuffle=False) # Training loop. - steps_per_epoch = num_examples // microbatches + steps_per_epoch = num_examples // sampling_batch test_accuracy_list = [] for epoch in range(1, FLAGS.epochs + 1): for step in range(steps_per_epoch): - whether = np.random.random_sample(num_examples) > (1-microbatches/num_examples) + whether = np.random.random_sample(num_examples) > (1-sampling_batch/num_examples) subsampling = [i for i in np.arange(num_examples) if whether[i]] global microbatches microbatches = len(subsampling) @@ -197,8 +197,8 @@ def main(unused_argv): # Compute the privacy budget expended so far. if FLAGS.dpsgd: - eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, microbatches, 1e-6) - mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, microbatches) + eps = compute_eps_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch, 1e-6) + mu = compute_mu_poisson(epoch, FLAGS.noise_multiplier, num_examples, sampling_batch) print('For delta=1e-6, the current epsilon is: %.2f' % eps) print('For delta=1e-6, the current mu is: %.2f' % mu)