def incrementalAverageUpdate(avg, sample, sample_number):
    """
    :param avg: the old average
    :param sample: the new sample to update the average with
    :param sample_number: the current sample number (#samples observed so far+1)

    Updates an average incrementally.

    """
    return avg + (sample - avg) / (sample_number * 1.)