00001 #define WANT_STREAM
00002 #define WANT_MATH
00003 #include "include.h"
00004 #include "newran.h"
00005
00006 #ifdef use_namespace
00007 using namespace NEWRAN;
00008 #endif
00009
00010 void Histogram(Random*, int);
00011
00012
00013 Real phi(Real x)
00014 { return (fabs(x)>8.0) ? 0 : 0.398942280 * exp(-x*x / 2); }
00015
00016 Real NORMAL10(Real x) { return 0.5*phi(0.5*(x-10.0)); }
00017
00018 Real UNIF(Real x) { return (x>=0.0 && x<=1.0) ? 1.0 : 0.0; }
00019
00020 Real TRIANG(Real x) { return (x>1.0) ? 0.0 : 1.0-x; }
00021
00022
00023
00024 void test1(int n)
00025 {
00026 Normal nn;
00027 Uniform uniform;
00028 { for (int i=0; i<20; i++) cout << nn.Next() << "\n" << flush; }
00029 { Constant c(5.0); Histogram(&c, n); }
00030 { Uniform u; Histogram(&u, n); }
00031 { SumRandom sr=uniform(3)-1.5; Histogram(&sr, n); }
00032 { SumRandom sr=uniform-uniform; Histogram(&sr, n); }
00033 { Normal normal; Histogram(&normal, n); }
00034 { Cauchy cauchy; Histogram(&cauchy, n); }
00035 { AsymGenX normal10(NORMAL10, 10.0); Histogram(&normal10, n); }
00036 cout << "Mean and variance should be 10.0 and 4.0" << endl;
00037 { AsymGenX uniform2(UNIF,0.5); Histogram(&uniform2, n); }
00038 cout << "Mean and variance should be 0.5 and 0.083333" << endl;
00039 { SymGenX triang(TRIANG); Histogram(&triang, n); }
00040 cout << "Mean and variance should be 0 and 0.16667" << endl;
00041 { Poisson p(0.25); Histogram(&p, n); }
00042 { Poisson p(10.0); Histogram(&p, n); }
00043 { Poisson p(16.0); Histogram(&p, n); }
00044 { Binomial b(18,0.3); Histogram(&b, n); }
00045 { Binomial b(19,0.3); Histogram(&b, n); }
00046 { Binomial b(20,0.3); Histogram(&b, n); }
00047 { Binomial b(58,0.3); Histogram(&b, n); }
00048 { Binomial b(59,0.3); Histogram(&b, n); }
00049 { Binomial b(60,0.3); Histogram(&b, n); }
00050 { Binomial b(18,0.05); Histogram(&b, n); }
00051 { Binomial b(19,0.05); Histogram(&b, n); }
00052 { Binomial b(20,0.05); Histogram(&b, n); }
00053 { Binomial b(98,0.01); Histogram(&b, n); }
00054 { Binomial b(99,0.01); Histogram(&b, n); }
00055 { Binomial b(100,0.01); Histogram(&b, n); }
00056 { Binomial b(18,0.95); Histogram(&b, n); }
00057 { Binomial b(19,0.95); Histogram(&b, n); }
00058 { Binomial b(20,0.95); Histogram(&b, n); }
00059 { Binomial b(98,0.99); Histogram(&b, n); }
00060 { Binomial b(99,0.99); Histogram(&b, n); }
00061 { Binomial b(100,0.99); Histogram(&b, n); }
00062 { NegativeBinomial nb(100,6.0); Histogram(&nb, n); }
00063 { NegativeBinomial nb(11,9.0); Histogram(&nb, n); }
00064 { NegativeBinomial nb(11,1.9); Histogram(&nb, n); }
00065 { NegativeBinomial nb(11,0.10); Histogram(&nb, n); }
00066 { NegativeBinomial nb(1.5,1.9); Histogram(&nb, n); }
00067 { NegativeBinomial nb(1.0,1.9); Histogram(&nb, n); }
00068 { NegativeBinomial nb(0.3,19); Histogram(&nb, n); }
00069 { NegativeBinomial nb(0.3,1.9); Histogram(&nb, n); }
00070 { NegativeBinomial nb(0.3,0.05); Histogram(&nb, n); }
00071 { NegativeBinomial nb(100.8,0.18); Histogram(&nb, n); }
00072 { ChiSq c(1,2.0); Histogram(&c, n); }
00073 { ChiSq c(2,2.0); Histogram(&c, n); }
00074 { ChiSq c(3,2.0); Histogram(&c, n); }
00075 { ChiSq c(4,2.0); Histogram(&c, n); }
00076 { ChiSq c(1 ); Histogram(&c, n); }
00077 { ChiSq c(2 ); Histogram(&c, n); }
00078 { ChiSq c(3 ); Histogram(&c, n); }
00079 { ChiSq c(4 ); Histogram(&c, n); }
00080 { Gamma g1(1.0); Histogram(&g1, n); }
00081 { Gamma g2(0.5); Histogram(&g2, n); }
00082 { Gamma g3(1.01); Histogram(&g3, n); }
00083 { Gamma g4(2.0); Histogram(&g4, n); }
00084 { Pareto p1(0.5); Histogram(&p1, n); }
00085 { Pareto p2(1.5); Histogram(&p2, n); }
00086 { Pareto p3(2.5); Histogram(&p3, n); }
00087 { Pareto p4(4.5); Histogram(&p4, n); }
00088 Real probs[]={.1,.3,.05,.11,.05,.04,.05,.05,.1,.15};
00089 Real val[]={2,3,4,6,8,12,16,24,32,48};
00090 { DiscreteGen discrete(10,probs); Histogram(&discrete, n); }
00091 { DiscreteGen discrete(10,probs,val); Histogram(&discrete, n); }
00092 }