00001 #define WANT_STREAM
00002 #include "StdAfx.h"
00003
00004 #include <iostream>
00005 #include <fstream>
00006 using namespace std;
00007
00008 #include "include.h"
00009 #include "newran.h"
00010
00011 #ifdef use_namespace
00012 using namespace NEWRAN;
00013 #endif
00014
00015 void test1(int);
00016 void test2(int);
00017 void test3(int);
00018 void test4(int);
00019 void Histogram(Random*, int);
00020 void Hist(Random* rx, int n , const int cnt );
00021
00022 int main( int argc , char **argv )
00023 {
00024
00025 Random::Set(0.46875);
00026 long n = 1000;
00027 Uniform u , u1 , u2 , u3 , u4 , u5;
00028
00029 SumRandom *sr;
00030
00031 sr = new SumRandom( 2 * u * 2 * u );
00032 Hist( sr , 1000 , 42 );
00033 delete sr;
00034
00035 {
00036
00037 SumRandom sr1 = (u * u) + (1 - (u * u));
00038 Histogram(&sr1,n);
00039 cout << "Mean and variance should be 0.25 and 0.048611\n";
00040
00041 SumRandom sr2 = u + 2 * u * u;
00042 Histogram(&sr2,n);
00043 cout << "Mean and variance should be 0.25 and 0.048611\n";
00044
00045 SumRandom sr3 = (u-0.5) * (u-0.5) + u;
00046 Histogram(&sr3,n);
00047 cout << "Mean and variance should be 0.0 and 0.006944\n";
00048
00049 }
00050
00051 Real* s1; Real* s2; Real* s3; Real* s4;
00052 cout << "\nBegin test\n";
00053 { s1 = new Real[8000]; delete [] s1; }
00054 { s3 = new Real; delete s3;}
00055 {
00056
00057 Real* A = new Real[3750];
00058
00059 long n_large = 1000000;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #if 1
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 {
00082 static Real probs[]={.05 , 0.25, .02 , 0.01 , 0.02 ,.3 , .02 , 0.01 , 0.02 , .25 , .05};
00083 DiscreteGen discrete(11,probs); Normal nn;
00084 SumRandom sr = discrete + (nn * 0.25)(2) + 10.0;
00085 Hist(&discrete,n,50);
00086 Hist(&sr,n,50);
00087 }
00088
00089 {
00090
00091 static Real probs[]={ 0.4 , 0.000 ,0.000 ,0.12
00092 ,0.000 ,0.000 ,0.000
00093 ,0.12
00094 ,0.000 ,0.000 ,0.000,0.000 ,0.000 ,0.000,0.000 ,0.000
00095 ,0.12 , 0.12 , 0.12 };
00096 DiscreteGen discrete(19,probs);
00097 Hist(&discrete,n,19);
00098 Uniform nn;
00099 {
00100 SumRandom sr = discrete + (nn * 0.1)( 2 );
00101
00102 }
00103 {
00104 SumRandom sr = discrete + (nn * 0.25)( 2 );
00105 Hist(&sr,n,19);
00106 }
00107 {
00108 SumRandom sr = discrete + (nn * 0.5)( 2 );
00109
00110 }
00111 {
00112 SumRandom sr = discrete + (nn * 0.75)( 2 );
00113
00114 }
00115 }
00116 #endif
00117
00118
00119 test2(n);
00120
00121
00122
00123 cout << "\nEnd of tests\n";
00124
00125 delete [] A;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 return 0;
00141 }
00142