如何从 C++ 中的二元正态分布和学生 T 分布生成随机样本?
从二元正态分布和学生 T 分布生成随机样本的最佳方法是什么?在这两种情况下,sigma 都是 1,均值 0 - 所以我真正感兴趣的唯一参数是相关性(以及学生 t 的自由度)。我需要 C++ 中的解决方案,因此不幸的是我不能使用 MatLab 或 Mathematica 中已经实现的函数。
what is the best approach to generate random samples from bivariate normal and student T distributions? In both cases sigma is one, mean 0 - so the only parameter I am really interested in is correlation (and degrees of freedom for student t). I need to have the solution in C++, so I can't unfortunately use already implemented functions from MatLab or Mathematica.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 GNU GSL 库。有关二元正态分布,请参阅此处:
http://www .gnu.org/software/gsl/manual/html_node/The-Bivariate-Gaussian-Distribution.html
和学生的 t 分布:
http://www.gnu.org/software/gsl/manual/html_node/The-t_002ddistribution.html
他们直接使用。
You can use the GNU GSL libraries. See here for Bivariate normal:
http://www.gnu.org/software/gsl/manual/html_node/The-Bivariate-Gaussian-Distribution.html
and Student's t-distribution here:
http://www.gnu.org/software/gsl/manual/html_node/The-t_002ddistribution.html
They are straight forward to use.
对于具有协方差统一和零均值的二元正态,只需绘制两个单变量正态。
如果你想绘制一个具有均值(m1,m2),标准差(s1,s2)和相关性 rho 的二元正态,那么绘制两个单位单变量正态 X 和 Y 并设置
然后 u 和 v 按照你的意愿分布。
对于学生 T,您必须绘制一个正态变量 N 和一个 chi^2 变量 V。然后,N / sqrt(V) 具有 T 分布。
要绘制 chi^2,您应该使用包。或者查看《数值食谱》第 7 章,了解如何从 Gamma 分布中进行绘制(xhi^2 是 Gamma 的一个特例)。
For a bivariate normal with covariance unity and zero mean, just draw two univariate normals.
If you want to draw a bivariate normal with means (m1, m2), standard deviations (s1, s2) and correlation rho, then draw two unit univariate normals X and Y and set
Then u and v are distributed as you wish.
For the Student T, you have to draw a normal variate N and a chi^2 variate V. Then, N / sqrt(V) has T distribution.
To draw the chi^2, you should use a package. Or have a look at Numerical Recipes chapter 7 for how to draw from a Gamma distribution (xhi^2 is a special case of Gamma).
您应该查看 Boost 库随机分布 - 请参阅 http://www.boost.org/doc/libs/1_41_0/libs/random/random-distributions.html。我发现一旦您了解了它们的基本概念,它们就非常容易使用。不幸的是,我对统计数据的了解不够,无法告诉您它们是否完全满足您的需求。
You should take a look at the Boost libraries random distributions - see http://www.boost.org/doc/libs/1_41_0/libs/random/random-distributions.html. I've found them very easy to use, once you wrap your head around their basic concepts. Unfortunately, I don't know enough about statistics to tell you whether they will exactly meet your needs.