MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / get_updates

Method get_updates

tensorflow/python/keras/optimizers.py:393–426  ·  view source on GitHub ↗
(self, loss, params)

Source from the content-addressed store, hash-verified

391 self.initial_decay = decay
392
393 def get_updates(self, loss, params):
394 grads = self.get_gradients(loss, params)
395 shapes = [K.int_shape(p) for p in params]
396 accumulators = [K.zeros(shape) for shape in shapes]
397 delta_accumulators = [K.zeros(shape) for shape in shapes]
398 self.weights = accumulators + delta_accumulators
399 self.updates = [state_ops.assign_add(self.iterations, 1)]
400
401 lr = self.lr
402 if self.initial_decay > 0:
403 lr = lr * ( # pylint: disable=g-no-augmented-assignment
404 1. /
405 (1. +
406 self.decay * math_ops.cast(self.iterations, K.dtype(self.decay))))
407
408 for p, g, a, d_a in zip(params, grads, accumulators, delta_accumulators):
409 # update accumulator
410 new_a = self.rho * a + (1. - self.rho) * math_ops.square(g)
411 self.updates.append(state_ops.assign(a, new_a))
412
413 # use the new accumulator and the *old* delta_accumulator
414 update = g * K.sqrt(d_a + self.epsilon) / K.sqrt(new_a + self.epsilon)
415 new_p = p - lr * update
416
417 # Apply constraints.
418 if getattr(p, 'constraint', None) is not None:
419 new_p = p.constraint(new_p)
420
421 self.updates.append(state_ops.assign(p, new_p))
422
423 # update delta_accumulator
424 new_d_a = self.rho * d_a + (1 - self.rho) * math_ops.square(update)
425 self.updates.append(state_ops.assign(d_a, new_d_a))
426 return self.updates
427
428 def get_config(self):
429 config = {

Callers

nothing calls this directly

Calls 8

get_gradientsMethod · 0.45
assign_addMethod · 0.45
castMethod · 0.45
dtypeMethod · 0.45
squareMethod · 0.45
appendMethod · 0.45
assignMethod · 0.45
constraintMethod · 0.45

Tested by

no test coverage detected