📄 stocc.h
字号:
/***************************** STOCC.H ************************ 2004-01-08 AF *
*
* This file contains function prototypes and class declarations for the C++
* library of non-uniform random number generators. Most functions are fast and
* accurate, even for extreme values of the parameters.
*
*
* functions without classes:
* ==========================
*
* void EndOfProgram(void);
* System-specific exit code. You may modify this to make it fit your
* user interface.
*
* void FatalError(char * ErrorText);
* Used for outputting error messages from the other functions and classes.
* You may have to modify this function to make it fit your user interface.
*
* double LnFac(long int n);
* Returns the natural logarithm of the factorial of n
*
*
* class StochasticLib:
* ====================
* This class can be derived from any of the uniform random number generators
* defined in randomc.h. StochasticLib provides the following non-uniform random
* variate generators:
*
* int Bernoulli(double p);
* Bernoulli distribution. Gives 0 or 1 with probability 1-p and p.
*
* double Normal(double m, double s);
* Normal distribution with mean m and standard deviation s.
*
* long int Poisson (double L);
* Poisson distribution with mean L.
*
* long int Binomial (long int n, double p);
* Binomial distribution. n trials with probability p.
*
* long int Hypergeometric (long int n, long int m, long int N);
* Hypergeometric distribution. Taking n items out N, m of which are colored.
*
* void Multinomial (long int * destination, double * source, long int n, int colors);
* void Multinomial (long int * destination, long int * source, long int n, int colors);
* Multivariate binomial distribution.
*
* void MultiHypergeometric (long int * destination, long int * source, long int n, int colors);
* Multivariate hypergeometric distribution.
*
* void Shuffle(int * list, int min, int n);
* Shuffle a list of integers.
*
*
* class StochasticLib2:
* =====================
* This class is derived from class StochasticLib. It redefines the functions
* Poisson, Binomial and HyperGeometric.
* In StochasticLib, these functions are optimized for being called with
* parameters that vary. In StochasticLib2, the same functions are optimized
* for being called repeatedly with the same parameters. If your parameters
* seldom vary, then StochasticLib2 is faster. The two classes use different
* calculation methods, both of which are accurate.
*
*
* class StochasticLib3:
* =====================
* This class can be derived from either StochasticLib or StochasticLib2,
* whichever is preferred. It contains functions for generating variates with
* the univariate and multivariate Wallenius' and Fisher's noncentral
* hypergeometric distributions.
*
* long int WalleniusNCHyp (long int n, long int m, long int N, double odds);
* Sampling from Wallenius' noncentral hypergeometric distribution.
* Taking n items out N, m of which are colored, with bias.
*
* long int FishersNCHyp (long int n, long int m, long int N, double odds);
* Sampling from Fisher's noncentral hypergeometric distribution.
*
* void MultiWalleniusNCHyp (long int * destination, long int * source, double * weights, long int n, int colors);
* Sampling from multivariate Wallenius' noncentral hypergeometric distribution.
*
* void MultiFishersNCHyp (long int * destination, long int * source, double * weights, long int n, int colors);
* Sampling from multivariate Fisher's noncentral hypergeometric distribution.
*
*
* class CWalleniusNCHypergeometric
* ================================
* This class implements various methods for calculating the probability
* function and the mean and variance of the univariate Wallenius' noncentral
* hypergeometric distribution. It is used by StochasticLib3 and can also be
* used independently.
*
*
* class CMultiWalleniusNCHypergeometric
* =====================================
* This class implements various methods for calculating the probability func-
* tion and the mean of the multivariate Wallenius' noncentral hypergeometric
* distribution. It is used by StochasticLib3 and can also be used independently.
*
*
* class CMultiWalleniusNCHypergeometricMoments
* ============================================
* This class calculates the exact mean and variance of the multivariate
* Wallenius' noncentral hypergeometric probability distribution.
*
*
* class CFishersNCHypergeometric
* ==============================
* This class calculates the probability function and the mean and variance
* of Fisher's noncentral hypergeometric distribution.
*
*
* class CMultiFishersNCHypergeometric
* ===================================
* This class calculates the probability function and the mean and variance
* of the multivariate Fisher's noncentral hypergeometric distribution.
*
* Uniform random number generators (integer and float) are also available, as
* these are inherited from the random number generator class that is the base
* class of StochasticLib.
*
*
* source code:
* ============
* The code for EndOfProgram and FatalError is found in the file userintf.cpp.
* The code for the functions in StochasticLib is found in the file stoc1.cpp.
* The code for the functions in StochasticLib2 is found in the file stoc2.cpp.
* The code for the functions in StochasticLib3 is found in the file stoc3.cpp.
* The code for the functions in CWalleniusNCHypergeometric,
* CMultiWalleniusNCHypergeometric and CMultiWalleniusNCHypergeometricMoments
* is found in the file wnchyppr.cpp.
* The code for the functions in CFishersNCHypergeometric and
* CMultiFishersNCHypergeometric is found in the file fnchyppr.cpp
*
*
* Examples:
* =========
* The file ex-stoc.cpp contains an example of how to use this class library.
*
* The file ex-cards.cpp contains an example of how to shuffle a list of items.
*
* The file ex-lotto.cpp contains an example of how to generate a sequence of
* random integers where no number can occur more than once.
*
* The file testbino.cpp contains an example of sampling from the binomial distribution.
*
* The file testhype.cpp contains an example of sampling from the hypergeometric distribution.
*
* The file testpois.cpp contains an example of sampling from the poisson distribution.
*
* The file testwnch.cpp contains an example of sampling from Wallenius noncentral hypergeometric distribution.
*
* The file testfnch.cpp contains an example of sampling from Fisher's noncentral hypergeometric distribution.
*
* The file testmwnc.cpp contains an example of sampling from the multivariate Wallenius noncentral hypergeometric distribution.
*
* The file testmfnc.cpp contains an example of sampling from the multivariate Fisher's noncentral hypergeometric distribution.
*
* The file evolc.zip contains examples of how to simulate biological evolution using this class library.
*
*
* Documentation:
* ==============
* The file stocc.htm contains further instructions.
*
* The file distrib.pdf contains definitions of the standard statistic distributions:
* Bernoulli, Normal, Poisson, Binomial, Hypergeometric, Multinomial, MultiHypergeometric.
*
* The file sampmet.pdf contains theoretical descriptions of the methods used
* for sampling from these distributions.
*
* The file nchyp.pdf, available from www.agner.org/random/, contains
* definitions of the univariate and multivariate Wallenius and Fisher's
* noncentral hypergeometric distributions and theoretical explanations of
* the methods for calculating and sampling from these.
*
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -