import numpy as np
from .Optimizers import Optimizer

class Momentum(Optimizer):
    def __init__ (self, lr=0.01, momentum=0.9):
        super().__init__(lr);
        self.momentum = momentum
        self.v = None
    def update(self, params, grads):
        if self.v is None:
          self.v = {}
        for key, val in params.items():
          self.v[key] = np.zeros_like(val)
        for key in params.keys():
          self.v[key] = self.momentum*self.v[key] - self.lr*grads[key]
          params[key] += self.v[key]