'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):

    lr = self._get_lr(index)
    wd = self._get_wd(index)
    self._update_count(index)
    grad = ((grad * self.rescale_grad) + (wd * weight))
    if (not self.centered):
        (n,) = state
        if (self.clip_gradient is not None):
            grad = mx.nd.clip(grad, (- self.clip_gradient), self.clip_gradient)
        n[:] = (((1 - self.gamma1) * (grad * grad)) + (self.gamma1 * n))
        weight[:] -= ((lr * grad) / mx.nd.sqrt((n + self.epsilon)))
    else:
        (n, g, delta) = state
        if (self.clip_gradient is not None):
            grad = mx.nd.clip(grad, (- self.clip_gradient), self.clip_gradient)
        n[:] = (((1 - self.gamma1) * (grad * grad)) + (self.gamma1 * n))
        g[:] = (((1 - self.gamma1) * grad) + (self.gamma1 * g))
        delta[:] = ((self.gamma2 * delta) - ((lr * grad) / mx.nd.sqrt(((n - (g * g)) + self.epsilon))))
        weight[:] += delta
    if self.clip_weights:
        mx.ndarray.clip(weight, (- self.clip_weights), self.clip_weights, out=weight)
