#include "include.h"#include "newran.h"Include dependency graph for tryrand1.cpp:

Go to the source code of this file.
Defines | |
| #define | WANT_STREAM |
| #define | WANT_MATH |
Functions | |
| void | Histogram (Random *, int) |
| Real | phi (Real x) |
| Real | NORMAL10 (Real x) |
| Real | UNIF (Real x) |
| Real | TRIANG (Real x) |
| void | test1 (int n) |
|
|
Definition at line 2 of file tryrand1.cpp. |
|
|
Definition at line 1 of file tryrand1.cpp. |
|
||||||||||||
|
Definition at line 16 of file hist.cpp.
00017 {
00018 int i,j; int count[20];
00019 Real* a = new Real[n];
00020 for (i = 0; i < n; i++) a[i] = rx->Next();
00021 Real amax = a[0]; Real amin = a[0]; Real mean = a[0]; Real sd = 0;
00022 for (i = 1; i < n; i++)
00023 {
00024 if (amin > a[i]) amin = a[i]; else if (amax < a[i]) amax = a[i];
00025 mean += a[i];
00026 }
00027 mean /= n;
00028 for (i = 0; i < 20; i++) count[i]=0;
00029 for (i = 0; i < n; i++)
00030 {
00031 Real rat= (amax != amin) ? (a[i] - amin)/(amax - amin) : 1.0;
00032 j = (int)( 19.999 * rat ); count[j]++;
00033 Real diff = a[i] - mean; sd += diff*diff;
00034 }
00035 sd = sqrt(sd/(n-1));
00036 j = 0;
00037 for (i = 0; i < 20; i++) { if (j < count[i]) j = count[i]; }
00038 if (j > 70) { for (i = 0; i < 20; i++) count[i] = (int)((70L*count[i])/j); }
00039
00040 al_trace( "\n" );
00041 for (i = 0; i < 20; i++)
00042 {
00043 al_trace( "\n|" );
00044 for (j = 1; j < count[i]; j = j+1)
00045 al_trace( "*" );
00046 }
00047 /* al_trace( "\n%s\np. mean = %9f, p. var = %9f\ns. mean = %9f, s. var = %9f\n" ,
00048 rx->Name() , rx->Mean() , rx->Variance() , mean , sd * sd );*/
00049
00050 delete a;
00051 }
|
|
|
Definition at line 16 of file tryrand1.cpp. Referenced by test1().
00016 { return 0.5*phi(0.5*(x-10.0)); }
|
|
|
Definition at line 13 of file tryrand1.cpp. References Real. Referenced by NORMAL10().
00014 { return (fabs(x)>8.0) ? 0 : 0.398942280 * exp(-x*x / 2); }
|
|
|
Definition at line 24 of file tryrand1.cpp. References Histogram(), SymGen::Next(), NORMAL10(), Real, TRIANG(), and UNIF().
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 }
|
|
|
Definition at line 20 of file tryrand1.cpp. References Real. Referenced by test1().
00020 { return (x>1.0) ? 0.0 : 1.0-x; }
|
|
|
Definition at line 18 of file tryrand1.cpp. References Real. Referenced by test1().
00018 { return (x>=0.0 && x<=1.0) ? 1.0 : 0.0; }
|
1.3.3