c++ - Boost vs. .Net random number generators -


i developed same algorithm (baum-welch estimating parameters of hidden markov model) both in f# (.net) , c++. in both cases developed same test generates random test data known distribution , uses algorithm estimate parameters, , makes sure converges known right answer.

the problem test works fine in f# case, fails converge in c++ implementation. compared both algorithms on real-world data , give same results, guess generation of test data broken in c++ case. hence question: random number generator comes .net 4 (i think default version vs2010)?

in f# using:

let random = new random() let randomnormal () = //for standard normal random variable     let u1 = random.nextdouble()     let u2 = random.nextdouble()     let r = sqrt (-2. * (log u1))     let theta = 2. * system.math.pi * u2     r * (sin theta) //random.nextdouble() uniform random variable on [0-1] 

in c++ use standard boost classes:

class hmmgenerator { public:     hmmgenerator() :          rng(37), //the seed change result, doesn't  make work          normalgenerator(rng, boost::normal_distribution<>(0.0, 1.0)),          uniformgenerator(rng, boost::uniform_01<>()) {}//other stuff here private:     boost::mt19937 rng;     boost::variate_generator<boost::mt19937&,                             boost::normal_distribution<> > normalgenerator;     boost::variate_generator<boost::mt19937&,                             boost::uniform_01<> > uniformgenerator; }; 

should expect different results using these 2 ways of generating random numbers?

edit: also, generator used in .net available in boost (ideally same parameters), run in c++ , compare outcomes?

hence question: random number generator comes .net 4 (i think default version vs2010)?

from the documentation on random

the current implementation of random class based on donald e. knuth's subtractive random number generator algorithm. more information, see d. e. knuth. "the art of computer programming, volume 2: seminumerical algorithms". addison-wesley, reading, ma, second edition, 1981.

.

should expect different results using these 2 ways of generating random numbers?

the mersenne-twister algorithm you're using in c++ considered respectable, compared other off-the-shelf random generators.

i suspect discrepancy in codes lie elsewhere.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -