Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

tryrand.cpp

Go to the documentation of this file.
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);          // draw histogram with n obsv
00020 void Hist(Random* rx, int n , const int cnt );          // draw histogram with n obsv
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";   // Forces cout to allocate memory at beginning
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       Uniform u;
00063       SumRandom sr1 = u*u;
00064       SumRandom sr2 = (u-0.5)*(u-0.5);
00065       Histogram(&sr1,n);
00066       cout << "Mean and variance should be 0.25 and 0.048611" << endl;
00067       Histogram(&sr2,n);
00068       cout << "Mean and variance should be 0.0 and 0.006944" << endl;
00069 */   
00070                 //      RING    
00071 #if 1
00072 /*
00073                 {
00074       static Real probs[]={.05 , 0.25, .025 , 0 , 0.025 ,.3 , .025 , 0 , 0.025 , .25 , .05};
00075       DiscreteGen discrete(11,probs); Normal nn;
00076       SumRandom sr = discrete + (nn * 0.25)(2) + 10.0;
00077       Histogram(&discrete,n);
00078       Histogram(&sr,n);
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;     //      Normal nn;
00099       {
00100                         SumRandom sr = discrete + (nn * 0.1)( 2 );
00101 //                      Hist(&sr,n,7);
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 //                      Hist(&sr,n,7);
00110                 }
00111       {
00112                         SumRandom sr = discrete + (nn * 0.75)( 2 );
00113 //                      Hist(&sr,n,7);
00114                 }
00115    }
00116 #endif
00117 
00118 //      test1(n);
00119                 test2(n);
00120 //      test3(n_large);
00121 //      test4(n);
00122 
00123       cout << "\nEnd of tests\n";
00124 
00125       delete [] A;
00126    }
00127 
00128  /*
00129  { s2 = new Real[8000]; delete [] s2; }
00130    cout << "\n(The following memory checks are probably not valid with all\n";
00131    cout << "compilers - see documentation)\n";
00132    cout << "\nChecking for lost memory: "
00133       << (unsigned long)s1 << " " << (unsigned long)s2 << " ";
00134    if (s1 != s2) cout << " - error\n"; else cout << " - ok\n\n";
00135    { s4 = new Real; delete s4;}
00136    cout << "\nChecking for lost memory: "
00137       << (unsigned long)s3 << " " << (unsigned long)s4 << " ";
00138    if (s3 != s4) cout << " - error\n"; else cout << " - ok\n\n";
00139 */
00140    return 0;
00141 }
00142 

Generated on Fri Dec 5 04:06:00 2003 for Borqueror by doxygen 1.3.3