def backprop(y, y_pred, w, x):
    """
    Backpropagation to compute w gradients
    y : ground truth targets 
    y_pred : predicted targets 
    w : weights for the network
    x : inputs to the net 
    """
    # start from outer most
    y_grad = 2.0 * (y_pred - y)

    # inner layer grads 
    w_grad  = x.T.dot(y_grad * y_pred * (1 - y_pred))
    return w_grad