使用 Python 进行多元分布 [英] Multivariate distributions with Python

查看:77
本文介绍了使用 Python 进行多元分布的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算了一个取决于两个变量的概率密度函数.我想使用这个多元分布来生成一些随机数,这些随机数出现的概率与 PDF 成正比.

I have computed a probability density function that depends on two variables. I want to use this multivariate distribution to generate some random numbers that occur with a probability proportional to the PDF.

看起来,SciPy 目前只支持单变量分布.是否有任何简单的方法或易于使用的包允许 2d 分布?

As it seems, SciPy currently only supports univariate distributions. Are there any simple methods or easy-to-use packages that allow 2d-distributions?

作为一种解决方法,我可能会尝试在感兴趣的域上创建随机数并将其丢弃或保留与我的 PDF 相关的机会,但仍然可能有其他选择.随机数生成不一定要很快.

As a workaround, I might try creating random numbers on the domain of interest and throwing them away or keeping them with a chance related to my PDF, but still there might be other options. The random number generation does not have to be fast.

感谢您的帮助!

根据答案(非常感谢!),我修改了一些代码,您可能会在 this gist.如果您使用 sin^2*Gauss PDF 运行此示例,则将在 PDF 上绘制满足给定条件(在圆圈内)的 2000 个随机随机变量.也许这对其他人也有帮助.

Based on the answers (thanks a lot!), I hacked in some code the you may find in this gist. If you run this example with a sin^2*Gauss PDF, 2000 random random variates that fulfil a given condition (be inside a circle) will be plotted over the PDF. Maybe that's helpful for others, too.

推荐答案

所以你有一个 PDF F(x,y) 并且你想要生成 x 对> 和 y 根据此 PDF 分发?

So you have a PDF F(x,y) and you want to generate the pairs of x and y distributed according to this PDF?

我会说除非你可以使用多变量版本的反演技术(wiki),拒绝抽样是要走的路.

I'd say unless you can use the multivariate version of the inversion technique (wiki), the rejection sampling is the way to go.

这篇关于使用 Python 进行多元分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆