/* file: pdf.H Copyright glh 4/30/97 */ #ifndef PDFH #define PDFH #include #include #include #include typedef enum {false, true} Boolean; class pdf { protected: const double MAX; // (2**31)-1, random() --> [0,MAX] const double TWOPI; // 2*PI public: pdf() : MAX(2147483647.0), TWOPI(6.2831852) {} void SetRand(int seed) {srandom(seed);} virtual double Draw()=0; virtual void Type()=0; }; class uniform_pdf : public pdf { //Returns a uniformly distributed random variable in the range [a,b]. protected: double a,b; public: uniform_pdf(double arg1=0, double arg2=1) {a=arg1; b=arg2;} inline double Draw(); void Type() {cout << "uniform, range [" << a << "," << b << "]";} }; inline double uniform_pdf::Draw() {return ((b-a)/MAX * random() + a);} class std_normal_pdf : public pdf { //Returns a standard normal random variable. Uses the Box-Muller method. protected: Boolean one_left; double left_over; public: std_normal_pdf() {one_left=false;} double Draw(); void Type() {cout << "standard normal";} }; class normal_pdf : public pdf { //Returns a normal random variable using a standard normal random variable. protected: double mu, sigma; public: normal_pdf(double mean, double std_dev) {mu=mean; sigma=std_dev;} double Draw(); void Type() {cout << "normal, mean=" << mu << ", standard deviation=" << sigma;} }; class exponential_pdf : public pdf { //Returns an exponentially distributed random variable. protected: double mu; public: exponential_pdf(double mean) {mu = mean;} double Draw(); void Type() {cout << "exponential, mean=" << mu;} }; class erlang_pdf : public pdf { //Returns an erlang distributed random variable. protected: double k, mu; public: erlang_pdf(double param, double mean) {k = param; mu = mean;} double Draw(); void Type() {cout << "erlang, mean=" << mu << " k=" << k;} }; class Poisson_pdf : public pdf { //Returns an Poisson distributed random variable. protected: double theta; public: Poisson_pdf(double mean) {theta = mean;} double Draw(); void Type() {cout << "Poisson, mean and variance=" << theta;} }; #endif