00001 /*
00002 * This program is free software; you can redistribute it and/or modify
00003 * it under the terms of the GNU General Public License as published by
00004 * the Free Software Foundation; either version 2 of the License, or
00005 * (at your option) any later version.
00006 *
00007 * This program is distributed in the hope that it will be useful,
00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00010 * GNU General Public License for more details.
00011 *
00012 * You should have received a copy of the GNU General Public License
00013 * along with this program; if not, write to the Free Software
00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 *
00016 * This file is extracted from the random generator library provided by Agner Fog
00017 * (http://www.agner.org/random/) and has been modified for Seagull.
00018 * (c) 2002 Agner Fog. GNU General Public License www.gnu.org/copyleft/gpl.html
00019 *
00020 * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00021 *
00022 */
00023 #ifndef STOCC_H
00024 #define STOCC_H
00025
00026 #include "randomc.h"
00027
00028 #ifndef RANDOM_GENERATOR
00029 #define RANDOM_GENERATOR TRandomMersenne
00030 #endif
00031
00032 /***********************************************************************
00033 System-specific user interface functions
00034 ***********************************************************************/
00035 void FatalError(char * ErrorText); // system-specific error reporting
00036
00037 /***********************************************************************
00038 Constants and tables
00039 ***********************************************************************/
00040
00041 // constant for LnFac function:
00042 static const int FAK_LEN = 1024; // length of factorial table
00043
00044
00045 /***********************************************************************
00046 Class StochasticLib1
00047 ***********************************************************************/
00048
00049 class StochasticLib1 : public RANDOM_GENERATOR {
00050 // This class encapsulates the random variate generating functions.
00051 // May be derived from any of the random number generators.
00052 public:
00053 StochasticLib1 (int seed); // constructor
00054 int32 Poisson (double L); // poisson distribution
00055
00056 // functions used internally
00057 protected:
00058 static double fc_lnpk(int32 k, int32 N_Mn, int32 M, int32 n); // used by Hypergeometric
00059
00060 // subfunctions for each approximation method
00061 int32 PoissonInver(double L); // poisson by inversion
00062 int32 PoissonRatioUniforms(double L); // poisson by ratio of uniforms
00063 int32 PoissonLow(double L); // poisson for extremely low L
00064 int32 BinomialInver (int32 n, double p); // binomial by inversion
00065 int32 BinomialRatioOfUniforms (int32 n, double p); // binomial by ratio of uniforms
00066 int32 HypInversionMod (int32 n, int32 M, int32 N); // hypergeometric by inversion searching from mode
00067 int32 HypRatioOfUnifoms (int32 n, int32 M, int32 N);// hypergeometric by ratio of uniforms method
00068
00069 // variables used by Normal distribution
00070 double normal_x2; int normal_x2_valid;
00071
00072 // define constants
00073 enum constants {
00074 // maximum value of 'colors' in multivariate distributions:
00075 MAXCOLORS = 20}; // you may change this number
00076 };
00077
00078 #endif
1.2.14 written by Dimitri van Heesch,
© 1997-2002