MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / update

Method update

numpy_ml/neural_nets/optimizers/optimizers.py:322–361  ·  view source on GitHub ↗

Compute the RMSProp update for a given parameter. Parameters ---------- param : :py:class:`ndarray ` of shape (n, m) The value of the parameter to be updated param_grad : :py:class:`ndarray ` of shape (n, m)

(self, param, param_grad, param_name, cur_loss=None)

Source from the content-addressed store, hash-verified

320 )
321
322 def update(self, param, param_grad, param_name, cur_loss=None):
323 """
324 Compute the RMSProp update for a given parameter.
325
326 Parameters
327 ----------
328 param : :py:class:`ndarray <numpy.ndarray>` of shape (n, m)
329 The value of the parameter to be updated
330 param_grad : :py:class:`ndarray <numpy.ndarray>` of shape (n, m)
331 The gradient of the loss function with respect to `param_name`
332 param_name : str
333 The name of the parameter
334 cur_loss : float or None
335 The training or validation loss for the current minibatch. Used for
336 learning rate scheduling e.g., by
337 :class:`~numpy_ml.neural_nets.schedulers.KingScheduler`.
338 Default is None.
339
340 Returns
341 -------
342 updated_params : :py:class:`ndarray <numpy.ndarray>` of shape (n, m)
343 The value of `param` after applying the RMSProp update.
344 """
345 C = self.cache
346 H = self.hyperparameters
347 eps, decay, clip_norm = H["eps"], H["decay"], H["clip_norm"]
348 lr = self.lr_scheduler(self.cur_step, cur_loss)
349
350 if param_name not in C:
351 C[param_name] = np.zeros_like(param_grad)
352
353 # scale gradient to avoid explosion
354 t = np.inf if clip_norm is None else clip_norm
355 if norm(param_grad) > t:
356 param_grad = param_grad * t / norm(param_grad)
357
358 C[param_name] = decay * C[param_name] + (1 - decay) * param_grad ** 2
359 update = lr * param_grad / (np.sqrt(C[param_name]) + eps)
360 self.cache = C
361 return param - update
362
363
364class Adam(OptimizerBase):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected