python蒙特卡洛_Python:从零开始的汉密尔顿蒙特卡洛

python蒙特卡洛

If your experience with Markov Chain Monte Carlo (MCMC) methods has been anything like mine, it’s been an endless search for answers. Every time you get an answer to one question, a dozen more pop up! You’re continuously learning how much you don’t know. I recently accepted a full time role as data scientist at an organization that makes extensive use of Bayesian Statistics and by extension, MCMC methods. So I decided to go to war with this branch of mathematics once and for all! For a detailed review of Metropolis, Metropolis-Hastings, and Hamiltonian Monte Carlo, please visit my public Google Colab Notebook :)

如果您对Markov Chain Monte Carlo(MCMC)方法的经验像我的一样,那将是无穷无尽的寻找答案的方法。 每次您得到一个问题的答案时,就会弹出更多答案! 您正在不断学习不知道的地方。 我最近在一家组织中担任数据科学家的专职职位,该组织广泛使用贝叶斯统计数据,并广泛使用MCMC方法。 因此,我决定一劳永逸地与这个数学分支交战! 有关Metropolis,Metropolis-Hastings Hamiltonian Monte Carlo的详细评论,请访问我的公开Goog​​le Colab笔记本 :)

I’ll revisit the key ideas behind Metropolis-Hastings (MH) before diving into the new material because Hamiltonian Monte Carlo (HMC) is an extension of MH.

在介绍新材料之前,我将回顾Metropolis-Hastings(MH)背后的关键思想,因为汉密尔顿·蒙特卡洛(HMC)是MH的扩展。

大都市-哈丁斯 (Metropolis-Hastings)

Metropolis-Hastings is a glorified random walk. You need four elements: A starting point, a target distribution, a proposal distribution, and an impartial judge (a random event.) The target distribution can be any distribution you’d like to sample from; all you need is the probability density function (PDF). Likewise, the proposal distribution can be any PDF (although the math is simpler if the distribution is symmetric.) The whole idea is start at the random point using the proposal distribution. Append it to an array. Feed this point into the target’s PDF to get the probability density (aka likelihood). Now, generate a disturbance via the proposal distribution, add it the the current location, assigning this variable a new name, and evaluate its likelihood, as well, via the target’s PDF. Compare the likelihoods

Metropolis-Hastings是光荣的随机漫步。 您需要四个元素:起点,目标分布,建议分布和公正的判断(随机事件)。目标分布可以是您要从中采样的任何分布; 您只需要概率密度函数(PDF)。 同样,提案分发可以是任何PDF(尽管如果分发是对称的,那么数学会更简单。)整个想法是使用提案分发从随机点开始的。 将其追加到数组。 将这一点输入到目标的PDF中以获取概率密度(也就是可能性)。 现在,通过提案分配生成干扰,将其添加到当前位置,为该变量分配一个新名称,并通过目标的PDF评估其可能性。 比较可能性

acceptance = target_PDF(proposed)/target_PDF(current)

acceptance = target_PDF(proposed)/target_PDF(current)

This number will fall anywhere in the range [0, inf). If it’s less than 1, there’s an x% chance that you move. Anything above 1 is guaranteed movement. This is where the “impartial judge” comes in. Observe a random event (typically a number in [0,1] sampled from a uniform distribution.) If this number is less than or equal to acceptance, you move to the proposed point. Else, you stay at the previous location. Append the winner to the array. And that’s it to the Metropolis algorithm.

该数字将落在[0,inf)范围内的任何位置。 如果小于1,则有x%的机会移动。 任何高于1的值都可以保证运动。 这就是“公正判断”的出现。观察一个随机事件(通常是从均匀分布中抽样的[0,1]中的数字。)如果该数字小于或等于接受,则移至建议的点。 否则,您将停留在先前的位置。 将优胜者添加到数组中。 这就是Metropolis算法。

Things are slightly more complicated if the proposal distribution is asymmetric. If you sample movements from a normal distribution, uniform distribution, etc this step is unne

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值