如何初始化boost :: random :: discrete_distribution使用std :: vector? [英] How to initialize boost::random::discrete_distribution using std::vector?

查看:188
本文介绍了如何初始化boost :: random :: discrete_distribution使用std :: vector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 std :: vector< double> 初始化 boost :: random :: discrete_distribution

我的问题是,如果我用数组初始化它,就像官方示例:

My problem is that if I initialize it with an array, like in the official example:

double probabilities[] = {
    0.5, 0.1, 0.1, 0.1, 0.1, 0.1
};
boost::random::discrete_distribution<> dist(probabilities);

然而,如果我用一个 std :: vector 初始化它,它的行为就像它只有一个元素可能性为1.0。

However if I initialize it with a std::vector, then it behaves like if it has only one element with probability 1.0.

你能告诉我什么是初始化正确的方法boost :: random :: discrete_distribution< c $ c>有一个向量?

Can you tell me what is the right way of initializing a boost::random::discrete_distribution<> with a vector?

推荐答案

类似乎有一个构造函数获取迭代器范围。这将与这样的向量一起使用:

The class seems to have a constructor that takes an iterator range. This would be used with a vector like this:

std::vector<double> probs = ...;
boost::random::discrete_distribution<> dist(probs.begin(), probs.end());

这篇关于如何初始化boost :: random :: discrete_distribution使用std :: vector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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