增量计算平均数

2020-12-30  本文已影响0人  何哀何欢

\overline x_2 = \frac{x_1 + x_2} {2}
\overline x_3 = \frac{x_1 + x_2 + x_3} {3}
\overline x_n = \frac{x_1 + \dots + x_n} {n}
\dots
我们想要的是通过之前的平均值,求新的平均值:
\overline x_n = \overline x_{n-1} + y \qquad (1)
只要知道了y的算法,就可以实现只要已有平均值 \overline x_{n-1} 和 新添加值x_n,就可以算出新的平均值\overline x_n
y= \overline x_n - \overline x_{n-1}

\overline x_2\overline x_3 带入公式:
\begin{align} y &= \frac{x_1 + x_2 + x_3} {3} - \frac{x_1 + x_2} {2} \\ y &= \dots \\ y &= \frac{\overline x_2}{3} - \frac{x_3}{3} \\ y &= \frac{\overline x_2 - x_3}{3} \\ y &= \frac{\overline x_{n-1} - {x_n}}{n} \end{align}

带入公式(1)
\overline x_n = \overline x_{n-1} - \frac{\overline x_{n-1} + x_n}{n}

上一篇 下一篇

猜你喜欢

热点阅读