# 2.3 指数加权平均数（Exponentially weighted averages）

半年内伦敦市的气温变化：

![](/files/-Le0ceTd1g6p7VPs0lJg)

> 温度数据有noise，抖动较大

如果希望看到半年内气温的整体变化趋势，可以通过移动平均（moving average）的方法来对每天气温进行平滑处理

设$$V\_0=0$$，当成第0天的气温值

第一天的气温与第0天的气温有关：

$$
V\_1=0.9V\_0+0.1\theta\_1
$$

第二天的气温与第一天的气温有关：

$$
\begin{aligned}V\_2
\=&0.9V\_1+0.1\theta\_2\\
\=&0.9(0.9V\_0+0.1\theta\_1)+0.1\theta\_2\\
\=&0.9^2V\_0+0.9\cdot0.1\theta\_1+0.1\theta\_2
\end{aligned}
$$

第三天的气温与第二天的气温有关：

$$
\begin{aligned}V\_3
\=&0.9V\_2+0.1\theta\_3\\
\=&0.9(0.9^2V\_0+0.9\cdot0.1\theta\_1+0.1\theta\_2)+0.1\theta\_3\\
\=&0.9^3V\_0+0.9^2\cdot 0.1\theta\_1+0.9\cdot 0.1\theta\_2+0.1\theta\_3
\end{aligned}
$$

第$$t$$天与第$$t-1$$天的气温迭代关系为：

$$
\begin{aligned}V\_t
\=&0.9V\_{t-1}+0.1\theta\_t\\
\=&0.9^tV\_0+0.9^{t-1}\cdot0.1\theta\_1+0.9^{t-2}\cdot 0.1\theta\_2+\cdots+0.9\cdot0.1\theta\_{t-1}+0.1\theta\_t
\end{aligned}
$$

经过移动平均处理得到的气温如下图红色曲线所示：

![](/files/-Le0ceThf4uzeKGg4MFM)

这种滑动平均算法称为指数加权平均（exponentially weighted average）。一般形式为：

$$
V\_t=\beta V\_{t-1}+(1-\beta)\theta\_t
$$

$$\beta$$值决定了指数加权平均的天数，近似表示为：

$$
\frac{1}{1-\beta}
$$

当$$\beta=0.9$$，则$$\frac{1}{1-\beta}=10$$，表示将前10天进行指数加权平均。当$$\beta=0.98$$，则$$\frac{1}{1-\beta}=50$$，表示将前50天进行指数加权平均。$$\beta$$值越大，则指数加权平均的天数越多，平均后的趋势线就越平缓，但是同时也会向右平移

绿色曲线和黄色曲线分别表示了$$\beta=0.98$$和$$\beta=0.5$$时，指数加权平均的结果

![](/files/-Le0ceTj8sgm-huvDV7o)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-er-men-ke-gai-shan-shen-ceng-shen-jing-wang-luo-chao-can-shu-tiao-shi-zheng-ze-hua-yi-ji-you-hua/improving-deep-neural-networks/optimization-algorithms/23-zhi-shu-jia-quan-ping-jun-shu-ff08-exponentially-weighted-averages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
