Sampling from a discrete probability distribution in C++

前端 未结 5 546
故里飘歌
故里飘歌 2021-01-06 04:47

I am new to C++ and extremely surprised by the lack of accessible, common probability manipulation tools (i.e. the lack of things in Boost and the standard library). I\'ve d

相关标签:
5条回答
  • 2021-01-06 05:06

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

    0 讨论(0)
  • 2021-01-06 05:08

    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.

    0 讨论(0)
  • 2021-01-06 05:11

    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

    0 讨论(0)
  • 2021-01-06 05:19

    (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. ;-]

    0 讨论(0)
  • 2021-01-06 05:32

    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.

    0 讨论(0)
提交回复
热议问题