问题描述
我想用 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!