diff --git a/privacy/bolton/losses.py b/privacy/bolton/losses.py index 9bd15e8..d38c7cd 100644 --- a/privacy/bolton/losses.py +++ b/privacy/bolton/losses.py @@ -40,6 +40,7 @@ class StrongConvexMixin: def radius(self): """Radius, R, of the hypothesis space W. + W is a convex set that forms the hypothesis space. Returns: @@ -114,7 +115,7 @@ class StrongConvexHuber(losses.Loss, StrongConvexMixin): Args: reg_lambda: Weight regularization constant - C: Penalty parameter C of the loss term + c_arg: Penalty parameter C of the loss term radius_constant: constant defining the length of the radius delta: delta value in huber loss. When to switch from quadratic to absolute deviation. @@ -147,7 +148,7 @@ class StrongConvexHuber(losses.Loss, StrongConvexMixin): ) def call(self, y_true, y_pred): - """Computes loss + """Computes loss. Args: y_true: Ground truth values. One hot encoded using -1 and 1. @@ -262,13 +263,13 @@ class StrongConvexBinaryCrossentropy( def call(self, y_true, y_pred): """Computes loss. - Args: - y_true: Ground truth values. - y_pred: The predicted values. + Args: + y_true: Ground truth values. + y_pred: The predicted values. - Returns: - Loss values per sample. - """ + Returns: + Loss values per sample. + """ loss = super(StrongConvexBinaryCrossentropy, self).call(y_true, y_pred) loss = loss * self.C return loss diff --git a/privacy/bolton/losses_test.py b/privacy/bolton/losses_test.py index 44a8d11..713bd7c 100644 --- a/privacy/bolton/losses_test.py +++ b/privacy/bolton/losses_test.py @@ -369,11 +369,11 @@ class HuberTests(keras_parameterized.TestCase): def test_calculation(self, logits, y_true, delta, result): """Test the call method to ensure it returns the correct value. - Args: - logits: unscaled output of model - y_true: label - delta: - result: correct loss calculation value + Args: + logits: unscaled output of model + y_true: label + delta: + result: correct loss calculation value """ logits = tf.Variable(logits, False, dtype=tf.float32) y_true = tf.Variable(y_true, False, dtype=tf.float32) diff --git a/privacy/bolton/models.py b/privacy/bolton/models.py index 7efd59d..a5d6159 100644 --- a/privacy/bolton/models.py +++ b/privacy/bolton/models.py @@ -80,13 +80,13 @@ class BoltonModel(Model): # pylint: disable=abstract-method **kwargs): # pylint: disable=arguments-differ """See super class. Default optimizer used in Bolton method is SGD. - Args: - optimizer: The optimizer to use. This will be automatically wrapped - with the Bolton Optimizer. - loss: The loss function to use. Must be a StrongConvex loss (extend the - StrongConvexMixin). - kernel_initializer: The kernel initializer to use for the single layer. - kwargs: kwargs to keras Model.compile. See super. + Args: + optimizer: The optimizer to use. This will be automatically wrapped + with the Bolton Optimizer. + loss: The loss function to use. Must be a StrongConvex loss (extend the + StrongConvexMixin). + kernel_initializer: The kernel initializer to use for the single layer. + kwargs: kwargs to keras Model.compile. See super. """ if not isinstance(loss, StrongConvexMixin): raise ValueError('loss function must be a Strongly Convex and therefore ' @@ -200,6 +200,7 @@ class BoltonModel(Model): # pylint: disable=abstract-method Bolton paper for more description. n_samples: number of individual samples in x steps_per_epoch: + **kwargs: **kwargs """ if class_weight is None: class_weight = self.calculate_class_weights(class_weight) diff --git a/privacy/bolton/models_test.py b/privacy/bolton/models_test.py index daeba1a..f5365fe 100644 --- a/privacy/bolton/models_test.py +++ b/privacy/bolton/models_test.py @@ -275,7 +275,8 @@ def _do_fit(n_samples, loss: instance of TestLoss distribution: distribution to get noise from. - Returns: BoltonModel instsance + Returns: + BoltonModel instsance """ clf = models.BoltonModel(n_outputs) clf.compile(optimizer, loss) diff --git a/privacy/bolton/optimizers.py b/privacy/bolton/optimizers.py index 8910889..a18c636 100644 --- a/privacy/bolton/optimizers.py +++ b/privacy/bolton/optimizers.py @@ -184,7 +184,7 @@ class Bolton(optimizer_v2.OptimizerV2): Args: input_dim: the input dimensionality for the weights - output_dim the output dimensionality for the weights + output_dim: the output dimensionality for the weights Returns: Noise in shape of layer's weights to be added to the weights. @@ -236,7 +236,8 @@ class Bolton(optimizer_v2.OptimizerV2): Args: name: - Returns: attribute from Bolton if specified to come from self, else + Returns: + attribute from Bolton if specified to come from self, else from _internal_optimizer. """ if name == '_private_attributes' or name in self._private_attributes: @@ -254,7 +255,7 @@ class Bolton(optimizer_v2.OptimizerV2): ) def __setattr__(self, key, value): - """ Set attribute to self instance if its the internal optimizer. + """Set attribute to self instance if its the internal optimizer. Reroute everything else to the _internal_optimizer. @@ -333,6 +334,9 @@ class Bolton(optimizer_v2.OptimizerV2): tensor with dim == n_classes. n_samples: number of rows/individual samples in the training set batch_size: batch size used. + + Returns: + self """ if epsilon <= 0: raise ValueError('Detected epsilon: {0}. ' @@ -354,8 +358,8 @@ class Bolton(optimizer_v2.OptimizerV2): def __exit__(self, *args): """Exit call from with statement. - used to + Used to: 1.reset the model and fit parameters passed to the optimizer to enable the Bolton Privacy guarantees. These are reset to ensure that any future calls to fit with the same instance of the optimizer @@ -363,6 +367,9 @@ class Bolton(optimizer_v2.OptimizerV2): 2.call post-fit methods normalizing/projecting the model weights and adding noise to the weights. + + Args: + *args: *args """ self.project_weights_to_r(True) for layer in self.layers: