Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Random question
From: gast128 (gast128_at_[hidden])
Date: 2010-03-09 05:48:14


Steven Watanabe <watanabesj <at> gmail.com> writes:

>
> AMDG
>
> gast128 wrote:
> > a colleague of my asked me to drop a question on the forum about the
following
> > case:
> >
> > He produces 1000 samples with the following code:
> >
> > boost::normal_distribution<double> n1(1, sqrt(4.0));
> > boost::variate_generator< boost::minstd_rand,
> > boost::normal_distribution<double> > g1(boost::minstd_rand(), n1);
> >
> > He also calulates the covariance. It should be something like (4 0) but
he
> > got (4.1 8.3). This 4 is correct, but the 8.3 not. Anyone an idea?
> >
> >
> > Note (again): post from a colleague; i didn't try it myself.
> >
>
> I thought that covariance was a two variable statistic.
> What exactly is being tested?
>
> In Christ,
> Steven Watanabe

Yes u are right, the matrices should be [4 0; 0 16], while the measured values
were [ 4.1 8.3; 8.3 16.6 ]. However my colleaque also found out that applying
a seed first to the engine solved the problem.

unsigned int first_seed = static_cast<unsigned int>(time(0));
boost::variate_generator< boost::minstd_rand, boost::uniform_int<> >
generatorSeed(boost::minstd_rand(), boost::uniform_int<>(0, UINT_MAX/2));

generatorSeed.engine().seed(first_seed);
g1.engine().seed(static_cast<unsigned int>(generatorSeed()));
g2.engine().seed(static_cast<unsigned int>(generatorSeed()));


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