%description: Test mean and variance of random variates from different distributions. This doesn't guarantee that the shape of the distributions is also OK, but at least it's a guard against simple programming errors. Test 1: discrete distributions Test 2: continuous distributions FIXME: These tests are very fragile. They depend on the floating-point arithmetic and the default printing of doubles being EXACTLY THE SAME on all machines. They also break if anything changes in the underlying RNGs. !!! THIS TEST IS CURRENTLY OUT OF ORDER (%contains always matches) !!! The dist/ dir can be used to test the functions. %activity: #define MEAN_AND_VARIANCE(f) \ {\ cStdDev s; for (int i=0; i bernoulli(p) MEAN_AND_VARIANCE(binomial(1, 0.2,rng)); // m=1 MEAN_AND_VARIANCE(binomial(2, 0.2,rng)); // m=0.4 MEAN_AND_VARIANCE(binomial(10,0.2,rng)); // m=2 MEAN_AND_VARIANCE(binomial(10,0,rng)); // m=0 (always fail) MEAN_AND_VARIANCE(binomial(10,1.0,rng)); // m=10 (always success) EV << endl; MEAN_AND_VARIANCE(geometric(0.5,rng)); // m=1 MEAN_AND_VARIANCE(geometric(0.9,rng)); MEAN_AND_VARIANCE(geometric(0.1,rng)); EV << endl; // negbinomial(n,p) // if (n==1) --> geometric(p) // if (p==1.0) --> always 0 MEAN_AND_VARIANCE(negbinomial(0,0.9,rng)); MEAN_AND_VARIANCE(negbinomial(10,0.9,rng)); MEAN_AND_VARIANCE(negbinomial(1,0.5,rng)); // same as geom() MEAN_AND_VARIANCE(negbinomial(1,0.1,rng)); // same as geom() MEAN_AND_VARIANCE(negbinomial(5,0.1,rng)); EV << endl; // hypergeometric (a,b,n) //MEAN_AND_VARIANCE(hypergeometric(5,5,1,rng)); //MEAN_AND_VARIANCE(hypergeometric(5,5,2,rng)); //MEAN_AND_VARIANCE(hypergeometric(0,10,1,rng)); //MEAN_AND_VARIANCE(hypergeometric(10,0,1,rng)); //MEAN_AND_VARIANCE(hypergeometric(5,5,9,rng)); //EV << endl; // poisson(lambda): both mean and variance equal to lambda MEAN_AND_VARIANCE(poisson(1,rng)); MEAN_AND_VARIANCE(poisson(0.01,rng)); MEAN_AND_VARIANCE(poisson(25,rng)); MEAN_AND_VARIANCE(poisson(50,rng)); MEAN_AND_VARIANCE(poisson(1000,rng)); EV << endl; %contains: stdout intuniform