def momentum_averager(momentum=0.9):
    """First order running averager with momentum.
    y_n = momentum*y_{n-1} + (1-momentum)*x_n"""
    def avg():
        y = yield
        while True:
            x = yield y
            y = momentum*y + (1-momentum)*x

    return avg