Boost logo

Boost :

Subject: Re: [boost] Low discrepancy sequences (Boost.Random)
From: Justinas V. D. (jvd_at_[hidden])
Date: 2010-04-11 02:48:40

2010.04.09 23:46, Steven Watanabe rašė:
> What exactly would this constructor do? It looks to me as though,
> if it jest set the initial state, then (for a one-dimensional generator)
> the effective result would be as though you xor'ed the initial state
> with the normal values of the generator.

This could used, for example, to initialize nextq to specific values
that nextq would be unlikely to acquire otherwise. This scenario is
admittedly a little bit contrived.

> The following test case breaks because min and max are not defined
> correctly
> #include <boost/random/niederreiter_base2.hpp>
> #include <boost/test/unit_test.hpp>
> BOOST_AUTO_TEST_CASE(test_niederreiter_base2_1d) {
> boost::niederreiter_base2_1d gen;
> for(int i = 0; i < 100; ++i) {
> int val = gen();
> BOOST_CHECK_GE(val, (gen.min)());
> BOOST_CHECK_LE(val, (gen.max)());
> }
> }

Patched version in Vault. The fix was very trivial.

> Finally, since the algorithm does a lot of bit-twiddling,
> would uint32_t be more appropriate than int?

You mean those typedefs of niederreiter_base2? Does not really matter.
You could, for example instantiate template class niederreiter_base2
like this: niederreiter_base2<long, D, 1, (1 << 63)> gen; [1]
Scaling down to the [0, 1]^D unit hypercube you would get more
precision this way. (Of course, you could use uint32_t, too, and the
typedef would look like this: niederreiter_base2<uint32_t, D, 1, (1U
<< 32) /*!*/> [2], but g++ complains about left shift count >= width
of type, and spits out a warning in the instantiation site.) I think
this option could be best left to users, who know what they want.

Speaking of discard member function, I improved it in a way that makes
more sense to me. According to the draft, discard(z) ought to behave
as if z consecutive operator() invocations were executed. I refined
this to be Dimension*z, so discard(z) now actually discards z
consecutive s-dimensional vectors (s = Dimension). In 1-dimensional
case the behaviour is the same as dictated by the standard.


[1] On x86_64 platform long has 64 bits.
[2] Tested with long and uint32_t, too, and aforementioned examples
would produce the exact same sequence as int instantiation (scaled
down to [0, 1]^D with uniform_real), the only difference being
precision of division.

Boost list run by bdawes at, gregod at, cpdaniel at, john at