Sampling from a discrete probability distribution in C++

最后都变了- 提交于 2019-11-30 22:44:38

(Moved from comment.)

Did you look at Boost.Math.StatisticalDistributions? Specifically, its Discrete Probability Distributions?

Boost is not a library, it's a collection of libraries, so it can sometimes be difficult to find exactly what you're looking for – but that doesn't mean it isn't there. ;-]

Perhaps I'm misunderstanding your intention, but it seems to me what you want is simply std::discrete_distribution.

As mentioned, you'll want to look at boost/math/distributions and friends to meet your needs.

Here's a very good, detailed tutorial on getting these working for you in Boost. You may also want to throw your weight behind stan as well, which looks quite promising within this space.

You should do less C++ bashing, and more question asking - we try to be helpful and respectful on SO. Questions like yours are often tagged as inflammatory.

Boost::math seems to provide exactly what you're looking for: https://www.quantnet.com/cplusplus-statistical-distributions-boost/ - I'm not 100% sure about how well it handles multi-variate distributions though (nor am I an expert on statistics).

Get it here: http://www.boost.org/doc/libs/1_49_0/libs/math/doc/html/index.html

Boost's math libraries are pretty good for working with different distributions, but if you are only interested in sampling (as in the problem you mentioned in your post), then looking at the boost Random libraries might be more germane to your task. This link shows how to simulate rolling a weighted die, for example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!