从C ++中的离散概率分布抽样 [英] Sampling from a discrete probability distribution in C++

查看:469
本文介绍了从C ++中的离散概率分布抽样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++的新手,并且由于缺乏可访问的,通用的概率处理工具(即Boost和标准库中缺乏的东西)而非常惊讶。我已经在其他语言做了很多科学编程,但标准和/或无处不在的第三方加载项总是包括全范围的概率工具。一个朋友认为Boost是C ++的普遍存在的附件,但是当我阅读Boost文档时,即使它似乎缺乏我认为非常基本的内置函数。



我找不到一个内置的,需要一些离散概率的数组,并产生一个根据这些概率选择的索引。我当然可以为此写我自己的功能,但我只是想检查我是否缺少一个标准的方法来做到这一点。



我必须在这样一个低级编写我自己的函数是一件坏事,我觉得,但我正在为一个更大的项目写一个新的模拟模块,在C ++中。我的通常的策略是用Python编写它,并将Python链接到C ++,但是因为其他几个人一旦完成它就必须管理这个代码,而且没有人知道Python,我认为更谨慎的是用C ++将它们传递给所有人。



更广泛地说,人们在C ++中对于从标准分布中抽样,特别是基本的多变量正态分布?

解决方案

(从注释中移除。)



您看过 Boost.Math.StatisticalDistributions 吗?具体来说,其离散概率分布? p>

Boost不是图书馆,而是图书馆的集合,因此有时可能很难找到您要查找的内容。但这不意味着它不在那里。 ; - ]


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 done a lot of scientific programming in other languages, but the standard and/or ubiquitious third party add-ons always include a full range of probability tools. A friend billed up Boost to be the equivalent ubiquitous add-on for C++, but as I read the Boost documentation, even it seems to have a dearth of what I would consider extremely elementary built-ins.

I cannot find a built in that takes some sort of array of discrete probabilities and produces an index chosen according to those probabilities. I can of course write my own function for this, but I just wanted to check whether I am missing a standard way to do this.

Having to write my own functions at such a low-level is a bad thing, I feel, but I am writing a new simulation module for a larger project that is all in C++. My usual go-to tactic would be to write it in Python and link the Python to the C++, but because several other people are going to have to manage this code once I finish it, and none of them know Python, I think it would be more prudent to deliver it to them all in C++.

More generally, what do people do in C++ for things like sampling from standard distributions, in particular something as basic as a multi-variate normal distribution?

解决方案

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

这篇关于从C ++中的离散概率分布抽样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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