# 5.2.4 变分推断在认知理论中的应用：自由能原理

上一节已经介绍了贝叶斯脑假说，即认为大脑是通过贝叶斯推断来完成各种任务的。我们大脑认识这个世界的方式就是根据观察到的感知状态 $$s$$ 来对环境的潜状态 $$\phi$$做推断，也就是求解后验概率 $$p(\phi|s)$$。这是认知科学中所有贝叶斯模型的基本思想。

如同本节开头所说，由于后验概率的求解具有一定难度，我们选择用变分分布 $$q(\phi)$$来近似它。尽管符号有所不同，但经过同样的推导过程，我们可以得到与 [5.2.1](/compmodcogpsy/di-wu-zhang-jin-si-tui-duan/5.2-bian-fen-tui-duan/5.2.1-bian-fen-tui-duan-jie-shao.md) 中公式（5）类似的公式。

$$
log(p(s))=\int{log(\frac{p(\phi,s)}{q(\phi)})q(\phi)d\phi}-\int{log(\frac{p(\phi|s)}{q(\phi)})q(\phi)d\phi} \tag{8}
$$

我们令 $$F(s)$$等于公式右边第一项的负数，也是证据下界ELBO的负数。右边第二项，也正是变分分布 $$q(\phi)$$和后验概率 $$p(\phi|s)$$的KL散度。

$$
F(s)=-\int{log(\frac{p(\phi,s)}{q(\phi)})q(\phi)d\phi} \tag{9}
$$

$$
D\_{KL}\[q(\phi)||p(\phi|s)]=-\int{log(\frac{p(\phi|s)}{q(\phi)})q(\phi)d\phi} \tag{10}
$$

那么公式可以重新表示成

$$
log(p(s))=-F(s)+D\_{KL}\[q(\phi)||p(\phi|s)]\F(s)=-log(p(s))+D\_{KL}\[q(\phi)||p(\phi|s)] \tag{11}
$$

当 $$q(\phi)$$和后验概率 $$p(\phi|s)$$越接近，两者的KL散度也就越小（注意 $$D\_{KL}\[q(\phi)||p(\phi|s)]>=0$$）。同时，虽然我们不知道 $$-log(p(s))$$的值是多少，但肯定是个常数，因为给定一种感知状态 $$s$$，外部世界产生它的概率是恒定的，只不过我们无法获悉。所以当 $$D\_{KL}\[q(\phi)||p(\phi|s)]$$越小， $$F(s)$$也就越小；反之也成立，如果我们优化使得 $$F(s)$$越小，那么 $$D\_{KL}\[q(\phi)||p(\phi|s)]$$也就越小。这里的 $$F(s)$$就是自由能，最小化自由能就等价于最小化KL散度。

Karl Friston所提出的最小自由能原理，**本质上就是认为我们大脑在做贝叶斯推断的时候，并非直接求解复杂的后验分布，而是用变分推断的形式用一个简单的近似分布去逼近后验分布**。这也符合常理，我们每天看着太阳东升西落，但我们很难从这简单的观测中推断出地球以太阳为中心转动的精确轨迹方程，更可能会认为太阳在以地球为中心做圆周运动，这正是我们大脑在用一种有偏差但简单的近似分布去认识真实的世界。

（是否还需要说明完整的公式，即客观世界模型m，大脑内在模型u等内容）

$$
F(s,u) = -log(s|m) + D\_{KL}\[q(\phi|u)||p(\phi|s,m)] \tag{12}
$$

Karl Friston的自由能理论与预测性编码、最优控制、主动推断等多个概念存在复杂的关系，这里仅是简单介绍了自由能与变分推断相关的内容，读者有兴趣的话，可以阅读参考文献：

* Friston, K.(2010). The free-energy principle: a unified brain theory? *Nature Review Neuroscience,* 11, 127–138. <https://doi.org/10.1038/nrn2787>


---

# 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://ruyuanzhang.gitbook.io/compmodcogpsy/di-wu-zhang-jin-si-tui-duan/5.2-bian-fen-tui-duan/5.2.4-bian-fen-tui-duan-zai-ren-zhi-li-lun-zhong-de-ying-yong-zi-you-neng-yuan-li.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.
