def convex_combination(a, b, weight):
    """

    :param a: one summand (e.g., partial sum)
    :param b: another summand (e.g., the new datapoint)
    :param weight: the weight of the update (e.g., the inverse of the sample size)
    :return: the updated value (e.g., the new partial sum)

    >>> assert(np.mean([3,7]) == convex_combination(3,7,0.5))
    >>> assert(np.mean([1,1,1,2]) == convex_combination(1,2,0.25))

    """
    return (1-weight) * a + weight * b