def update_grad_w(grad, grad_old, grad_new):
    """Update the global gradient for W

    Parameters
    ----------
    grad: theano tensor
        The global gradient

    grad_old: theano tensor
        The previous value of the local gradient

    grad_new: theano tensor
        The new version of the local gradient

    Returns
    -------
    grad: theano tensor
        New value of the global gradient
    """
    return grad - grad_old + grad_new