|
Boost Users : |
From: Matt Holland (mdholland_at_[hidden])
Date: 2006-08-09 21:26:22
Hi all,
I'm having some difficulty understanding my options for seeding the
base generators in mersenne_twister.hpp. I'm interested in the array
initialization that is somewhat obtusely mentioned in the
documentation. In boost/random/mersenne_twister.hpp I see the
following relevant items:
template<class It> mersenne_twister(It& first, It last) {
seed(first,last); }
...
template<class It>
void seed(It& first, It last)
{
int j;
for(j = 0; j < n && first != last; ++j, ++first)
x[j] = *first;
i = n;
if(first == last && j < n)
throw std::invalid_argument("mersenne_twister::seed");
}
I gather that "It" is some kind of iterator, and the natural candidate
would be something like std::vector<uint32_t>::iterator, but not having
truly come to terms with templates, it is unclear to me how to actually
call this. The following minimal code snippet fails to compile with
g++ (gcc version 3.3 20030304 (Apple Computer, Inc. build 1671)).
Errors below.
#include <iostream>
#include <vector>
#include <boost/random.hpp>
typedef boost::mt19937 Mt19937BaseGenerator; // base generator
typedef boost::uniform_real<> UniformReal; // distribution
// variate generator
typedef boost::variate_generator<Mt19937BaseGenerator&, UniformReal>
Mt19937UniformRealGenerator;
int main() {
std::vector<uint32_t> seedVector(4);
seedVector[0] = 12345u; // make up some seeds
seedVector[1] = 98765u;
seedVector[2] = 12942u;
seedVector[3] = 20343u;
// attempt to seed with vector iterators
Mt19937BaseGenerator mt19937Generator(seedVector.begin(),
seedVector.end());
UniformReal distribution(0, 1);
Mt19937UniformRealGenerator myGen(mt19937Generator, distribution);
for (unsigned i = 0; i < 100; ++i) {
std::cout << myGen() << std::endl;
}
return 0;
}
mt19937Seed.cpp: In function `int main()':
mt19937Seed.cpp:18: error: no matching function for call to `
boost::random::mersenne_twister<uint32_t, 32, 624, 397, 31,
0x09908b0df, 11,
7, 0x09d2c5680, 15, 0x0efc60000, 18, 0x0c77666de>::mersenne_twister(
__gnu_cxx::__normal_iterator<uint32_t*, std::vector<uint32_t,
std::allocator<uint32_t> > >, __gnu_cxx::__normal_iterator<uint32_t*,
std::vector<uint32_t, std::allocator<uint32_t> > >)'
/sw/include/boost/random/mersenne_twister.hpp:43: error: candidates are:
boost::random::mersenne_twister<uint32_t, 32, 624, 397, 31,
0x09908b0df, 11,
7, 0x09d2c5680, 15, 0x0efc60000, 18,
0x0c77666de>::mersenne_twister(const
boost::random::mersenne_twister<uint32_t, 32, 624, 397, 31,
0x09908b0df, 11,
7, 0x09d2c5680, 15, 0x0efc60000, 18, 0x0c77666de>&)
/sw/include/boost/random/mersenne_twister.hpp:69: error:
boost::random::mersenne_twister<UIntType, w, n, m, r, a, u, s, b, t,
c, l,
val>::mersenne_twister(It&, It) [with It =
__gnu_cxx::__normal_iterator<uint32_t*, std::vector<uint32_t,
std::allocator<uint32_t> > >, UIntType = uint32_t, int w = 32, int n
= 624,
int m = 397, int r = 31, UIntType a = 0x09908b0df, int u = 11, int s
= 7,
UIntType b = 0x09d2c5680, int t = 15, UIntType c = 0x0efc60000, int
l = 18,
UIntType val = 0x0c77666de]
/sw/include/boost/random/mersenne_twister.hpp:68: error:
boost::random::mersenne_twister<UIntType, w, n, m, r, a, u, s, b, t,
c, l,
val>::mersenne_twister(UIntType) [with UIntType = uint32_t, int w =
32, int
n = 624, int m = 397, int r = 31, UIntType a = 0x09908b0df, int u =
11, int
s = 7, UIntType b = 0x09d2c5680, int t = 15, UIntType c =
0x0efc60000, int l
= 18, UIntType val = 0x0c77666de]
/sw/include/boost/random/mersenne_twister.hpp:60: error:
boost::random::mersenne_twister<UIntType, w, n, m, r, a, u, s, b, t,
c, l,
val>::mersenne_twister() [with UIntType = uint32_t, int w = 32, int
n = 624,
int m = 397, int r = 31, UIntType a = 0x09908b0df, int u = 11, int s
= 7,
UIntType b = 0x09d2c5680, int t = 15, UIntType c = 0x0efc60000, int
l = 18,
UIntType val = 0x0c77666de]
Any help? I always have a really hard time interpreting
template-related compiler errors.
Thanks,
Matt
-- Matt Holland Population Biology Graduate Group University of California Davis, CA 95616
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net