def update(cur_aggregate, new_value):
    """For a new value new_value, compute the new count, new mean, the new m_2.
    * mean accumulates the mean of the entire dataset.
    * m_2 aggregates the squared distance from the mean.
    * count aggregates the number of samples seen so far.
    """
    (count, mean, m_2) = cur_aggregate
    count = count + 1
    delta = new_value - mean
    mean = mean + delta / count
    delta2 = new_value - mean
    m_2 = m_2 + delta * delta2
    return (count, mean, m_2)