2011-10-26 3 views
6

boost::random::discrete_distributionstd::vector<double>으로 초기화하고 싶습니다.std :: vector를 사용하여 boost :: random :: discrete_distribution을 초기화하는 방법?

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

을 한 후 완벽하게 작동합니다

내 문제는 내가 공식 예에서와 같이 배열을 초기화하는 경우이다.

그러나 std::vector으로 초기화하면 확률 1.0의 요소가 하나만있는 것처럼 동작합니다.

boost::random::discrete_distribution<>을 벡터로 초기화하는 올바른 방법은 무엇입니까?

답변

10

클래스에는 takes an iterator range 인 생성자가있는 것 같습니다. 이것은 다음과 같은 벡터와 함께 사용됩니다 :

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

이것을 해결하는 방법을 알고 있습니까? [link] (https://stackoverflow.com/questions/48013802/how-to-set-a-vector-of-discrete-distribution-c) 그것은 거의 동일하지만, 분포 벡터를 가지고 있습니다. –

관련 문제