def rolling_variance(old,newValue):
    """Rolling variance computation according to  Welford's algorithm.
    https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_Online_algorithm

    Parameters
    ----------
    old : tuple containing the triplet
        count, mean, M2. Initialize with (0,0,0)
        on the first call
    newValue : new element to be added to the sample

    Returns
    -------
    type
        tuple containing the triplet
        count, mean, M2. To retrieve variance and
        sample variance compute M2/count and M2/(count-1),
        respectively

    Examples
    -------

    >>> a=range(10)
    >>> b=(0.,0.,0.)
    >>> for i in range(10):
    ...     b=rolling_variance(b,a[i])
    >>> b
    (10.0, 4.5, 82.5)


    """
    (count, mean, M2) = old
    count += 1
    delta = newValue - mean
    mean += delta / count
    delta2 = newValue - mean
    M2 += delta * delta2
    return (count, mean, M2)