python概率编程
Introduction
介绍
We often hear something like this on weather forecast programs: the chance of raining tomorrow is 80%. What does that mean? It is often hard to give meaning to this kind of statement, especially from a frequentist perspective: there is no reasonable way to repeat the raining/not raining experiment an infinite (or very big) number of times.
我们经常在天气预报节目中听到这样的消息:明天下雨的机会是80%。 那是什么意思? 通常很难对这种陈述赋予意义,尤其是从常客的角度:没有合理的方法可以无限次(或非常大)地重复下雨/不下雨实验。
The Bayesian approach provides a solution for this type of statement. The following sentence, taken from the book Probabilistic Programming & Bayesian Methods for Hackers, perfectly summarizes one of the key ideas of the Bayesian perspective.
贝叶斯方法为这种陈述提供了一种解决方案。 以下句子摘自《 概率编程与黑客贝叶斯方法 》一书,完美地总结了贝叶斯观点的关键思想之一。
The Bayesian world-view interprets probability as measure of believability in an event, that is, how confident we are in an event occurring.
贝叶斯世界观将概率解释为事件中可信度的度量,即我们对事件发生的信心。
In other words, in the Bayesian approach, we can never be absolutely sure about our *beliefs*, but can definitely say how confident we are about the relevant events. Furthermore, as more data is collected, we can become more confident about our beliefs.
换句话说,在贝叶斯方法中,我们永远无法绝对确定自己的“信念”,但可以肯定地说出我们对相关事件的信心。 此外,随着收集到更多数据,我们可以对自己的信念更加自信。
As a scientist, I am trained to believe in the data and always be critical about almost everything. Naturally, I find Bayesian inference to be rather intuitive.
作为一名科学家,我受过训练以相信数据,并且对几乎所有事物都至关重要。 自然,我发现贝叶斯推理是相当直观的。
However, it is often computationally and conceptually challenging to work with Bayesian inference. Often, a lot of long and complicated mathematical computations are required to get things done. Even as a mathematician, I occasionally find these computations tedious; especially when I need a quick overview of the problem that I want to solve.
但是,使用贝叶斯推断在计算和概念上通常具有挑战性。 通常,完成工作需要大量漫长而复杂的数学计算。 即使作为数学家,我有时也会发现这些计算很乏味; 特别是当我需要快速了解要解决的问题时。
Luckily, my mentor Austin Rochford recently introduced me to a wonderful package called PyMC3 that allows us to do numerical Bayesian inference. In this article, I will give a quick introduction to PyMC3 through a concrete example.
幸运的是,我的导师Austin Rochford最近向我介绍了一个名为PyMC3的出色程序包,该程序包使我们能够进行数值贝叶斯推理。 在本文中,我将通过一个具体示例快速介绍PyMC3。
A concrete example