@gradient_optimizer<EOL>def sag(nterms=<NUM_LIT:10>, lr=<NUM_LIT>):
xk = yield<EOL>gradients = deque([], nterms)<EOL>for k in count():<EOL><INDENT>grad = yield xk<EOL>gradients.append(grad)<EOL>xk -= lr * np.mean(gradients, axis=<NUM_LIT:0>)<EOL><DEDENT>
Stochastic Average Gradient (SAG)

Parameters
----------
nterms : int, optional
    Number of gradient evaluations to use in the average (Default: 10)

lr : float, optional
    (Default: 1e-3)