Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tensorflow_privacy/privacy/logistic_regression/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ py_test(
name = "single_layer_softmax_test",
size = "medium",
srcs = ["single_layer_softmax_test.py"],
shard_count = 4,
deps = [
":datasets",
":single_layer_softmax",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest

from absl.testing import absltest
from absl.testing import parameterized
from tensorflow_privacy.privacy.logistic_regression import datasets
from tensorflow_privacy.privacy.logistic_regression import single_layer_softmax
Expand All @@ -27,13 +26,17 @@ class SingleLayerSoftmaxTest(parameterized.TestCase):
(10000, 1000, 3, 40, 4, 0.1),
(10000, 1000, 4, 40, 4, 0.1),
)
def test_single_layer_softmax(self, num_train, num_test, dimension, epochs,
num_classes, tolerance):
(train_dataset, test_dataset) = datasets.synthetic_linearly_separable_data(
num_train, num_test, dimension, num_classes)
def test_single_layer_softmax(
self, num_train, num_test, dimension, epochs, num_classes, tolerance
):
train_dataset, test_dataset = datasets.synthetic_linearly_separable_data(
num_train, num_test, dimension, num_classes
)
_, accuracy = single_layer_softmax.single_layer_softmax_classifier(
train_dataset, test_dataset, epochs, num_classes, 'sgd')
train_dataset, test_dataset, epochs, num_classes, 'sgd'
)
self.assertAlmostEqual(accuracy[-1], 1, delta=tolerance)


if __name__ == '__main__':
unittest.main()
absltest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ def get_multilabel_test_input_with_sample_weights(n_train, n_test):
logits_test=rng.randn(n_test, num_classes) + 0.2,
labels_train=get_multihot_labels_for_test(n_train, num_classes),
labels_test=get_multihot_labels_for_test(n_test, num_classes),
sample_weight_train=rng.randn(n_train, 1),
sample_weight_test=rng.randn(n_test, 1))
sample_weight_train=rng.rand(n_train, 1),
sample_weight_test=rng.rand(n_test, 1),
)


def get_test_input_logits_only(n_train, n_test):
Expand All @@ -101,8 +102,9 @@ def get_test_input_logits_only_with_sample_weights(n_train, n_test):
return AttackInputData(
logits_train=rng.randn(n_train, 5) + 0.2,
logits_test=rng.randn(n_test, 5) + 0.2,
sample_weight_train=rng.randn(n_train, 1),
sample_weight_test=rng.randn(n_test, 1))
sample_weight_train=rng.rand(n_train, 1),
sample_weight_test=rng.rand(n_test, 1),
)


class MockTrainedAttacker(object):
Expand Down