fig, ax = new_ax(6.6, 4.4)
mu, sigma, n = 1.0, 1.0, 400
x = RNG.normal(mu, sigma, n) # one shared sample stream
k = np.arange(1, n + 1)
ax.axhline(mu, color=GREY, lw=0.9, ls="--", zorder=2)
for alpha, colour in ((0.30, COL["orange"]), (0.10, COL["sky"])):
w = mean_estimation_path(x, alpha, w0=5.0)
ax.plot(np.arange(n + 1), w, color=colour, lw=1.0, alpha=0.9, zorder=3)
# stationary std of the constant-step recursion: sigma * sqrt(a/(2-a))
band = sigma * np.sqrt(alpha / (2 - alpha))
ax.fill_between([0, n], mu - band, mu + band, color=colour, alpha=0.10, zorder=1)
w = mean_estimation_path(x, 1.0 / k, w0=5.0)
ax.plot(np.arange(n + 1), w, color=COL["vermilion"], lw=2.2, zorder=5)
ax.set_xlim(0, n * 1.13) # headroom on the right for the E[X] tag
ax.set_ylim(-0.6, 5.3)
ax.set_xlabel(r"iteration $k$")
ax.set_ylabel(r"$w_k$")
# Direct labels live in the empty upper-right quadrant, clear of the paths.
label_at(ax, n * 1.015, mu + 0.28, r"$\mathbb{E}[X]$", color=INK, fontsize=9.5)
label_at(ax, n * 0.50, 4.75, r"constant $\alpha=0.3$", color=COL["orange"], fontsize=9.5)
label_at(ax, n * 0.50, 4.25, r"constant $\alpha=0.1$", color=COL["sky"], fontsize=9.5)
label_at(ax, n * 0.50, 3.75, r"$\alpha_k=1/k$", color=COL["vermilion"], fontsize=9.5)
label_at(
ax,
n * 0.50,
3.20,
"shaded: stationary band\n" r"$\sigma\sqrt{\alpha/(2-\alpha)}$",
color=GREY,
fontsize=8.5,
va="top",
)
ax.set_title(r"Why $\sum_k \alpha_k^2 < \infty$ is the condition that makes it settle")
plt.show()