def apply_update(self, weights, gradient):
"""Update the running averages of gradients and weight updates,
and compute the Adadelta update for this step."""
if self.running_g2 is None:
self.running_g2 = [ np.zeros_like(g) for g in gradient ]
if self.running_dx2 is None:
self.running_dx2 = [ np.zeros_like(g) for g in gradient ]
self.running_g2 = self.running_average_square( self.running_g2, gradient )
new_weights = []
updates = []
for w, g, g2, dx2 in zip(weights, gradient, self.running_g2, self.running_dx2):
update = np.multiply( np.divide( self.sqrt_plus_epsilon(dx2), self.sqrt_plus_epsilon(g2) ), g )
new_weights.append( np.subtract( w, update ) )
updates.append(update)
self.running_dx2 = self.running_average_square( self.running_dx2, updates )
return new_weights
评论列表
文章目录