def __call__(self, input_data, weights):
'''
input_data in this case is a numpy array with batch_size on axis 1
and weights is a matrix with 1 column
'''
if self.state is None:
self.state = np.ones_like(weights)
if self.velocity is None:
self.velocity = np.zeros_like(weights)
gradient = - input_data.mean(axis=1)
self.state[:] = self.decay_rate * self.state + \
(1.0 - self.decay_rate) * np.square(gradient)
self.velocity = self.velocity * self.momentum + \
self.learning_rate * gradient / np.sqrt(self.state + self.epsilon) + \
self.learning_rate * self.wdecay * weights
weights[:] = weights - self.velocity
return weights
评论列表
文章目录