• Main Page
  • Classes
  • Files
  • File List

src/rng.h

00001 /*
00002  *   See COPYING file distributed along with the psignifit package for
00003  *   the copyright and license terms
00004  */
00005 #ifndef RNG_H
00006 #define RNG_H
00007 
00008 #include <cstdlib>
00009 #include <cmath>
00010 #include "errors.h"
00011 
00012 
00013 class PsiRandom
00014 {
00015         public:
00016                 PsiRandom ( void ) {}
00017                 double rngcall ( void );
00018                 virtual double draw ( void ) { throw NotImplementedError(); }
00019                 virtual PsiRandom * clone ( void ) const {throw NotImplementedError(); }
00020 };
00021 
00022 class GaussRandom : public PsiRandom
00023 {
00024         private:
00025                 double mu;
00026                 double sigma;
00027                 bool good;
00028                 double x1;
00029                 double x2;
00030                 double w;
00031                 double y;
00032         public:
00033                 GaussRandom ( double mean=0, double standarddeviation=1 ) : mu ( mean ), sigma ( standarddeviation ), good ( false ) {}
00034                 double draw ( void );              
00035                 PsiRandom * clone ( void ) const { return new GaussRandom(*this); }
00036 };
00037 
00038 class UniformRandom : public PsiRandom
00039 {
00040         private:
00041                 double lower;
00042                 double upper;
00043         public:
00044                 UniformRandom ( double low=0, double up=1 ) : lower(low), upper(up) {}
00045                 double draw ( void ) { return  (upper-lower)*rngcall()+lower; }
00046                 PsiRandom * clone ( void ) const { return new UniformRandom(*this); }
00047 };
00048 
00049 class BinomialRandom : public PsiRandom
00050 {
00051         private:
00052                 int n;
00053                 double p;
00054         public:
00055                 BinomialRandom ( int number, double probability ) : n(number), p(probability) {}
00056                 double draw ( void );
00057                 void setprm ( int number, double probability ) { n = number; p = probability; }
00058                 PsiRandom * clone ( void ) const { return new BinomialRandom(*this); }
00059 };
00060 
00061 class GammaRandom : public PsiRandom
00062 {
00063         private:
00064                 double k;
00065                 double theta;
00066                 GaussRandom grng;
00067         public:
00068                 GammaRandom ( double shape, double scale ) : k (shape), theta(scale), grng() {}
00069                 double draw ( void );              
00070                 PsiRandom * clone ( void ) const { return new GammaRandom(*this); }
00071 };
00072 
00073 class BetaRandom : public PsiRandom
00074 {
00075         private:
00076                 double alpha;
00077                 double beta;
00078                 GammaRandom grnga;
00079                 GammaRandom grngb;
00080         public:
00081                 BetaRandom ( double alpha, double beta ) : alpha(alpha), beta(beta), grnga (alpha, 1), grngb (beta, 1) {}
00082                 double draw ( void );              
00083                 PsiRandom * clone ( void ) const { return new BetaRandom(*this); }
00084 };
00085 
00086 
00087 void setSeed(long int seedval);
00088 
00089 #endif

Generated on Mon Jul 4 2011 14:52:04 for Psi++ by  doxygen 1.7.1