Fixing new pylint errors.

This commit is contained in:
Christopher Choquette Choo 2019-07-27 14:14:05 -04:00
parent 92f97ae32c
commit 71c4a11eb9
5 changed files with 61 additions and 63 deletions

View file

@ -56,7 +56,7 @@ class StrongConvexMixin:
Args:
class_weight: the class weights as scalar or 1d tensor, where its
dimensionality is equal to the number of outputs.
dimensionality is equal to the number of outputs.
Returns:
Beta
@ -115,7 +115,7 @@ class StrongConvexHuber(losses.Loss, StrongConvexMixin):
C: 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.
absolute deviation.
reduction: reduction type to use. See super class
name: Name of the loss instance
dtype: tf datatype to use for tensor conversions.

View file

@ -180,20 +180,20 @@ class BoltonModel(Model): # pylint: disable=abstract-method
n_samples=None,
steps_per_epoch=None,
**kwargs): # pylint: disable=arguments-differ
"""Fit with a generator..
"""Fit with a generator.
This method is the same as fit except for when the passed dataset
is a generator. See super method and fit for more details.
Args:
n_samples: number of individual samples in x
noise_distribution: the distribution to get noise from.
epsilon: privacy parameter, which trades off utility and privacy. See
Bolton paper for more description.
class_weight: the class weights to be used. Can be a scalar or 1D tensor
whose dim == n_classes.
See the super method for descriptions on the rest of the arguments.
Args:
n_samples: number of individual samples in x
noise_distribution: the distribution to get noise from.
epsilon: privacy parameter, which trades off utility and privacy. See
Bolton paper for more description.
class_weight: the class weights to be used. Can be a scalar or 1D tensor
whose dim == n_classes.
See the super method for descriptions on the rest of the arguments.
"""
if class_weight is None:
class_weight = self.calculate_class_weights(class_weight)
@ -227,14 +227,14 @@ class BoltonModel(Model): # pylint: disable=abstract-method
num_classes=None):
"""Calculates class weighting to be used in training.
Args:
class_weights: str specifying type, array giving weights, or None.
class_counts: If class_weights is not None, then an array of
the number of samples for each class
num_classes: If class_weights is not None, then the number of
classes.
Returns:
class_weights as 1D tensor, to be passed to model's fit method.
Args:
class_weights: str specifying type, array giving weights, or None.
class_counts: If class_weights is not None, then an array of
the number of samples for each class
num_classes: If class_weights is not None, then the number of
classes.
Returns:
class_weights as 1D tensor, to be passed to model's fit method.
"""
# Value checking
class_keys = ['balanced']

View file

@ -43,7 +43,7 @@ class TestLoss(losses.Loss, StrongConvexMixin):
W is a convex set that forms the hypothesis space.
Returns:
Returns:
radius
"""
return _ops.convert_to_tensor_v2(1, dtype=tf.float32)
@ -70,7 +70,7 @@ class TestLoss(losses.Loss, StrongConvexMixin):
Args:
class_weight: class weights used
Returns:
Returns:
L
"""
return _ops.convert_to_tensor_v2(1, dtype=tf.float32)
@ -175,12 +175,12 @@ class InitTests(keras_parameterized.TestCase):
},
])
def test_compile(self, n_outputs, loss, optimizer):
"""test compilation of BoltonModel.
"""Test compilation of BoltonModel.
Args:
n_outputs: number of output neurons
loss: instantiated TestLoss instance
optimizer: instanced TestOptimizer instance
optimizer: instantiated TestOptimizer instance
"""
# test compilation of valid tf.optimizer and tf.loss
with self.cached_session():
@ -206,7 +206,7 @@ class InitTests(keras_parameterized.TestCase):
Args:
n_outputs: number of output neurons
loss: instantiated TestLoss instance
optimizer: instanced TestOptimizer instance
optimizer: instantiated TestOptimizer instance
"""
# test compilaton of invalid tf.optimizer and non instantiated loss.
with self.cached_session():
@ -262,17 +262,17 @@ def _do_fit(n_samples,
"""Instantiate necessary components for fitting and perform a model fit.
Args:
n_samples: number of samples in dataset
input_dim: the sample dimensionality
n_outputs: number of output neurons
epsilon: privacy parameter
generator: True to create a generator, False to use an iterator
batch_size: batch_size to use
reset_n_samples: True to set _samples to None prior to fitting.
False does nothing
optimizer: instance of TestOptimizer
loss: instance of TestLoss
distribution: distribution to get noise from.
n_samples: number of samples in dataset
input_dim: the sample dimensionality
n_outputs: number of output neurons
epsilon: privacy parameter
generator: True to create a generator, False to use an iterator
batch_size: batch_size to use
reset_n_samples: True to set _samples to None prior to fitting.
False does nothing
optimizer: instance of TestOptimizer
loss: instance of TestLoss
distribution: distribution to get noise from.
Returns: BoltonModel instsance
"""
@ -329,8 +329,8 @@ class FitTests(keras_parameterized.TestCase):
"""Tests fitting of BoltonModel.
Args:
generator: True for generator test, False for iterator test.
reset_n_samples: True to reset the n_samples to None, False does nothing
generator: True for generator test, False for iterator test.
reset_n_samples: True to reset the n_samples to None, False does nothing
"""
loss = TestLoss(1, 1, 1)
optimizer = Bolton(TestOptimizer(), loss)
@ -398,10 +398,10 @@ class FitTests(keras_parameterized.TestCase):
"""Tests fitting with invalid parameters, which should raise an error.
Args:
generator: True to test with generator, False is iterator
reset_n_samples: True to reset the n_samples param to None prior to
passing it to fit
distribution: distribution to get noise from.
generator: True to test with generator, False is iterator
reset_n_samples: True to reset the n_samples param to None prior to
passing it to fit
distribution: distribution to get noise from.
"""
with self.assertRaises(ValueError):
loss = TestLoss(1, 1, 1)
@ -505,21 +505,20 @@ class FitTests(keras_parameterized.TestCase):
'num_classes': 2,
'err_msg': 'Detected array length:'},
])
def test_class_errors(self,
class_weights,
class_counts,
num_classes,
err_msg):
"""Tests the BOltonModel calculate_class_weights method.
This test passes invalid params which should raise the expected errors.
Args:
class_weights: the class_weights to use
class_counts: count of number of samples for each class
num_classes: number of outputs neurons
err_msg:
class_weights: the class_weights to use.
class_counts: count of number of samples for each class.
num_classes: number of outputs neurons.
err_msg: The expected error message.
"""
clf = models.BoltonModel(1, 1)
with self.assertRaisesRegexp(ValueError, err_msg): # pylint: disable=deprecated-method

View file

@ -310,12 +310,11 @@ class Bolton(optimizer_v2.OptimizerV2):
Args:
noise_distribution: the noise distribution to pick.
see _accepted_distributions and get_noise for
possible values.
see _accepted_distributions and get_noise for possible values.
epsilon: privacy parameter. Lower gives more privacy but less utility.
layers: list of Keras/Tensorflow layers. Can be found as model.layers
class_weights: class_weights used, which may either be a scalar or 1D
tensor with dim == n_classes.
tensor with dim == n_classes.
n_samples number of rows/individual samples in the training set
batch_size: batch size used.
"""

View file

@ -209,7 +209,7 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
args: args to optimizer fn
result: the expected result
test_attr: None if the fn returns the test result. Otherwise, this is
the attribute of Bolton to check against result with.
the attribute of Bolton to check against result with.
"""
tf.random.set_seed(1)
@ -303,9 +303,9 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
"""Tests the context manager functionality of the optimizer.
Args:
noise: noise distribution to pick
epsilon: epsilon privacy parameter to use
class_weights: class_weights to use
noise: noise distribution to pick
epsilon: epsilon privacy parameter to use
class_weights: class_weights to use
"""
@tf.function
def test_run():
@ -336,9 +336,9 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
"""Tests the context domains.
Args:
noise: noise distribution to pick
epsilon: epsilon privacy parameter to use
err_msg: the expected error message
noise: noise distribution to pick
epsilon: epsilon privacy parameter to use
err_msg: the expected error message
"""
@ -456,7 +456,7 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
])
def test_not_reroute_fn(self, fn, args):
"""Test function is not rerouted.
Test that a fn that should not be rerouted to the internal optimizer is
in fact not rerouted.
@ -495,7 +495,7 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
])
def test_reroute_attr(self, attr):
"""Test a function is rerouted.
Test that attribute of internal optimizer is correctly rerouted to the
internal optimizer.
@ -514,7 +514,7 @@ class BoltonOptimizerTest(keras_parameterized.TestCase):
])
def test_attribute_error(self, attr):
"""Test rerouting of attributes.
Test that attribute of internal optimizer is correctly rerouted to the
internal optimizer
@ -561,7 +561,7 @@ class SchedulerTest(keras_parameterized.TestCase):
])
def test_call(self, step, res):
"""Test call.
Test that attribute of internal optimizer is correctly rerouted to the
internal optimizer