'Update the parameters.
Parameters
index : int
An unique integer key used to index the parameters
weight : NDArray
weight ndarray
grad : NDArray
grad ndarray
state : NDArray or other objects returned by init_state
The auxiliary state used in optimization.'

def update(self, index, weight, grad, state):

    assert isinstance(weight, NDArray)
    assert isinstance(grad, NDArray)
    (lr, momentum) = self._get_lr(index)
    wd = self._get_wd(index)
    self._update_count(index)
    grad = (grad * self.rescale_grad)
    if (self.clip_gradient is not None):
        grad = clip(grad, (- self.clip_gradient), self.clip_gradient)
    if state:
        mom = state
        mom[:] *= momentum
        mom[:] += (((- lr) * (1.0 - momentum)) * (grad + (wd * weight)))
        weight[:] += mom
    else:
        assert (self.momentum == 0.0)
        weight[:] += ((- lr) * (grad + (self.wd * weight)))
