optim/onn/optimizer_base.py

20 lines
367 B
Python
Raw Normal View History

2018-01-21 14:04:25 -08:00
import numpy as np
from .float import _f
2018-01-21 14:04:25 -08:00
2018-01-22 11:40:36 -08:00
2018-01-21 14:04:25 -08:00
class Optimizer:
def __init__(self, lr=0.1):
2018-01-22 11:40:36 -08:00
self.lr = _f(lr) # learning rate
2019-02-04 19:15:28 -08:00
self.base_rate = self.lr
2018-01-21 14:04:25 -08:00
self.reset()
def reset(self):
2019-02-04 19:15:28 -08:00
self.lr = self.base_rate
2018-01-21 14:04:25 -08:00
def compute(self, dW, W):
return -self.lr * dW
def update(self, dW, W):
W += self.compute(dW, W)