MNT Reduce cyclomatic complexity in _stochastic_optimizers.py
@@ -140,21 +140,21 @@ class SGDOptimizer(BaseOptimizer):
(time_step + 1) ** self.power_t)
def trigger_stopping(self, msg, verbose):
- if self.lr_schedule == 'adaptive':
- if self.learning_rate > 1e-6:
- self.learning_rate /= 5.
+ if self.lr_schedule != 'adaptive':
if verbose:
- print(msg + " Setting learning rate to %f" %
- self.learning_rate)
- return False
- else:
+ print(msg + " Stopping.")
+ return True
+
+ if self.learning_rate <= 1e-6:
if verbose:
print(msg + " Learning rate too small. Stopping.")
return True
- else:
+
+ self.learning_rate /= 5.
if verbose:
- print(msg + " Stopping.")
- return True
+ print(msg + " Setting learning rate to %f" %
+ self.learning_rate)
+ return False
def _get_updates(self, grads):
"""Get the values used to update params with given gradients
