00001 /******************************************************************* 00002 * File: Normal.h 00003 * Description: Generates random numbers with normal 00004 * distribution. 00005 * Author: Subhasis Ray 00006 * E-mail: ray.subhasis@gmail.com 00007 * Created: 2007-10-30 11:22:51 00008 ********************************************************************/ 00009 /********************************************************************** 00010 ** This program is part of 'MOOSE', the 00011 ** Messaging Object Oriented Simulation Environment, 00012 ** also known as GENESIS 3 base code. 00013 ** copyright (C) 2003-2005 Upinder S. Bhalla. and NCBS 00014 ** It is made available under the terms of the 00015 ** GNU General Public License version 2 00016 ** See the file COPYING.LIB for the full notice. 00017 **********************************************************************/ 00018 00019 #ifndef _NORMAL_H 00020 #define _NORMAL_H 00021 #include "Probability.h" 00022 enum NormalGenerator 00023 { 00024 ALIAS, 00025 BOX_MUELLER, 00026 ZIGGURAT 00027 }; 00028 00029 class Normal : public Probability 00030 { 00031 00032 public: 00033 Normal(double mean=0.0, double variance=1.0, NormalGenerator algorithm=ALIAS); 00034 double getMean() const; 00035 void setMean(double value); 00036 double getVariance() const; 00037 void setVariance( double value ); 00038 NormalGenerator getMethod(void); 00039 void setMethod(NormalGenerator method); 00040 double getNextSample() const; 00041 private: 00042 double mean_; 00043 double variance_; 00044 double (*generator_)(); 00045 bool isStandard_; 00046 NormalGenerator method_; 00047 static double BoxMueller(); 00048 static double aliasMethod(); 00049 static double gslZiggurat(); 00050 static bool testAcceptance(unsigned long t, unsigned long v); 00051 }; 00052 00053 00054 #endif