📄 randist.texi
字号:
@cindex random number distributionsThis chapter describes functions for generating random variates andcomputing their probability distributions. Samples from thedistributions described in this chapter can be obtained using any of therandom number generators in the library as an underlying source ofrandomness. In the simplest cases a non-uniform distribution can beobtained analytically from the uniform distribution of a random numbergenerator by applying an appropriate transformation. This method usesone call to the random number generator.More complicated distributions are created by the@dfn{acceptance-rejection} method, which compares the desireddistribution against a distribution which is similar and knownanalytically. This usually requires several samples from the generator.The functions described in this section are declared in@file{gsl_randist.h}.@menu* The Gaussian Distribution:: * The Gaussian Tail Distribution:: * The Bivariate Gaussian Distribution:: * The Exponential Distribution:: * The Laplace Distribution:: * The Exponential Power Distribution:: * The Cauchy Distribution:: * The Rayleigh Distribution:: * The Rayleigh Tail Distribution:: * The Landau Distribution:: * The Levy alpha-Stable Distributions:: * The Levy skew alpha-Stable Distribution:: * The Gamma Distribution:: * The Flat (Uniform) Distribution:: * The Lognormal Distribution:: * The Chi-squared Distribution:: * The F-distribution:: * The t-distribution:: * The Beta Distribution:: * The Logistic Distribution:: * The Pareto Distribution:: * The Spherical Distribution (2D & 3D):: * The Weibull Distribution:: * The Type-1 Gumbel Distribution:: * The Type-2 Gumbel Distribution:: * General Discrete Distributions:: * The Poisson Distribution:: * The Bernoulli Distribution:: * The Binomial Distribution:: * The Negative Binomial Distribution:: * The Pascal Distribution:: * The Geometric Distribution:: * The Hypergeometric Distribution:: * The Logarithmic Distribution:: * Shuffling and Sampling:: * Random Number Distribution Examples:: * Random Number Distribution References and Further Reading:: @end menu@page@node The Gaussian Distribution@section The Gaussian Distribution@deftypefn Random double gsl_ran_gaussian (const gsl_rng * @var{r}, double @var{sigma})@cindex Gaussian random variatesThis function returns a Gaussian random variate, with mean zero andstandard deviation @var{sigma}. The probability distribution forGaussian random variates is,@tex\beforedisplay$$p(x) dx = {1 \over \sqrt{2 \pi \sigma^2}} \exp (-x^2 / 2\sigma^2) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over \sqrt@{2 \pi \sigma^2@}@} \exp (-x^2 / 2\sigma^2) dx@end example@end ifinfo@noindentfor @math{x} in the range @math{-\infty} to @math{+\infty}. Use thetransformation @math{z = \mu + x} on the numbers returned by@code{gsl_ran_gaussian} to obtain a Gaussian distribution with mean@math{\mu}. This function uses the Box-Mueller algorithm which requires twocalls the random number generator @var{r}.@end deftypefn@deftypefun double gsl_ran_gaussian_pdf (double @var{x}, double @var{sigma})This function computes the probability density @math{p(x)} at @var{x}for a Gaussian distribution with standard deviation @var{sigma}, usingthe formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-gaussian.tex}@end tex@deftypefun double gsl_ran_gaussian_ratio_method (const gsl_rng * @var{r}, const double @var{sigma})This function computes a gaussian random variate using theKinderman-Monahan ratio method.@end deftypefun@deftypefn Random double gsl_ran_ugaussian (const gsl_rng * @var{r})@deftypefnx Random double gsl_ran_ugaussian_pdf (double @var{x})@deftypefnx Random double gsl_ran_ugaussian_ratio_method (const gsl_rng * @var{r}, const double @var{sigma})These functions compute results for the unit Gaussian distribution. Theyare equivalent to the functions above with a standard deviation of one,@var{sigma} = 1.@end deftypefn@page@node The Gaussian Tail Distribution@section The Gaussian Tail Distribution@deftypefn Random double gsl_ran_gaussian_tail (const gsl_rng * @var{r}, double @var{a}, double @var{sigma})@cindex Gaussian Tail random variatesThis function provides random variates from the upper tail of a Gaussiandistribution with standard deviation @var{sigma}. The values returnedare larger than the lower limit @var{a}, which must be positive. Themethod is based on Marsaglia's famous rectangle-wedge-tail algorithm (AnnMath Stat 32, 894-899 (1961)), with this aspect explained in Knuth, v2,3rd ed, p139,586 (exercise 11).The probability distribution for Gaussian tail random variates is,@tex\beforedisplay$$p(x) dx = {1 \over N(a;\sigma)} \exp (- x^2 / 2\sigma^2) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over N(a;\sigma)@} \exp (- x^2/(2 \sigma^2)) dx@end example@end ifinfo@noindentfor @math{x > a} where @math{N(a;\sigma)} is the normalization constant,@tex\beforedisplay$$N(a;\sigma) = {1 \over 2} \hbox{erfc}\left({a \over \sqrt{2 \sigma^2}}\right).$$\afterdisplay@end tex@ifinfo@exampleN(a;\sigma) = (1/2) erfc(a / sqrt(2 sigma^2)).@end example@end ifinfo@end deftypefn@deftypefun double gsl_ran_gaussian_tail_pdf (double @var{x}, double @var{a}, double @var{sigma})This function computes the probability density @math{p(x)} at @var{x}for a Gaussian tail distribution with standard deviation @var{sigma} andlower limit @var{a}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-gaussian-tail.tex}@end tex@deftypefn Random double gsl_ran_ugaussian_tail (const gsl_rng * @var{r}, double @var{a})@deftypefnx Random double gsl_ran_ugaussian_tail_pdf (double @var{x}, double @var{a})These functions compute results for the tail of a unit Gaussiandistribution. They are equivalent to the functions above with a standarddeviation of one, @var{sigma} = 1.@end deftypefn@page@node The Bivariate Gaussian Distribution@section The Bivariate Gaussian Distribution@deftypefn Random void gsl_ran_bivariate_gaussian (const gsl_rng * @var{r}, double @var{sigma_x}, double @var{sigma_y}, double @var{rho}, double * @var{x}, double * @var{y})@cindex Gaussian random variatesThis function generates a pair of correlated gaussian variates, withmean zero, correlation coefficient @var{rho} and standard deviations@var{sigma_x} and @var{sigma_y} in the @math{x} and @math{y} directions.The probability distribution for bivariate gaussian random variates is,@tex\beforedisplay$$p(x,y) dx dy = {1 \over 2 \pi \sigma_x \sigma_y \sqrt{1-\rho^2}} \exp \left(-(x^2 + y^2 - 2 \rho x y) \over 2\sigma_x^2\sigma_y^2 (1-\rho^2)\right) dx dy$$\afterdisplay@end tex@ifinfo@examplep(x,y) dx dy = @{1 \over 2 \pi \sigma_x \sigma_y \sqrt@{1-\rho^2@}@} \exp (-(x^2 + y^2 - 2 \rho x y)/2\sigma_x^2\sigma_y^2 (1-\rho^2)) dx dy@end example@end ifinfo@noindentfor @math{x,y} in the range @math{-\infty} to @math{+\infty}. Thecorrelation coefficient @var{rho} should lie between @math{1} and@math{-1}.@end deftypefn@deftypefun double gsl_ran_bivariate_gaussian_pdf (double @var{x}, double @var{y}, double @var{sigma_x}, double @var{sigma_y}, double @var{rho})This function computes the probability density @math{p(x,y)} at(@var{x},@var{y}) for a bivariate gaussian distribution with standarddeviations @var{sigma_x}, @var{sigma_y} and correlation coefficient@var{rho}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-bivariate-gaussian.tex}@end tex@page@node The Exponential Distribution@section The Exponential Distribution@deftypefn Random double gsl_ran_exponential (const gsl_rng * @var{r}, double @var{mu})@cindex Exponential random variatesThis function returns a random variate from the exponential distributionwith mean @var{mu}. The distribution is,@tex\beforedisplay$$p(x) dx = {1 \over \mu} \exp(-x/\mu) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over \mu@} \exp(-x/\mu) dx@end example@end ifinfo@noindentfor @c{$x \ge 0$}@math{x >= 0}. @end deftypefn@deftypefun double gsl_ran_exponential_pdf (double @var{x}, double @var{mu})This function computes the probability density @math{p(x)} at @var{x}for an exponential distribution with mean @var{mu}, using the formulagiven above.@end deftypefun@sp 1@tex\centerline{\input rand-exponential.tex}@end tex@page@node The Laplace Distribution@section The Laplace Distribution@deftypefn Random double gsl_ran_laplace (const gsl_rng * @var{r}, double @var{a})@cindex two-sided exponential random variates@cindex Laplace distribution random variatesThis function returns a random variate from the the Laplace distributionwith width @var{a}. The distribution is,@tex\beforedisplay$$p(x) dx = {1 \over 2 a} \exp(-|x/a|) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over 2 a@} \exp(-|x/a|) dx@end example@end ifinfo@noindentfor @math{-\infty < x < \infty}.@end deftypefn@deftypefun double gsl_ran_laplace_pdf (double @var{x}, double @var{a})This function computes the probability density @math{p(x)} at @var{x}for a Laplace distribution with mean @var{a}, using the formulagiven above.@end deftypefun@sp 1@tex\centerline{\input rand-laplace.tex}@end tex@page@node The Exponential Power Distribution@section The Exponential Power Distribution@deftypefn Random double gsl_ran_exppow (const gsl_rng * @var{r}, double @var{a}, double @var{b})@cindex Exponential power distribution, random variatesThis function returns a random variate from the exponential power distributionwith scale parameter @var{a} and exponent @var{b}. The distribution is,@tex\beforedisplay$$p(x) dx = {1 \over 2 a \Gamma(1+1/b)} \exp(-|x/a|^b) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over 2 a \Gamma(1+1/b)@} \exp(-|x/a|^b) dx@end example@end ifinfo@noindentfor @c{$x \ge 0$}@math{x >= 0}. For @math{b = 1} this reduces to the Laplacedistribution. For @math{b = 2} it has the same form as a gaussiandistribution, but with @c{$a = \sqrt{2} \sigma$}@math{a = \sqrt@{2@} \sigma}.@end deftypefn@deftypefun double gsl_ran_exppow_pdf (double @var{x}, double @var{a}, double @var{b})This function computes the probability density @math{p(x)} at @var{x}for an exponential power distribution with scale parameter @var{a}and exponent @var{b}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-exppow.tex}@end tex@page@node The Cauchy Distribution@section The Cauchy Distribution@deftypefn Random double gsl_ran_cauchy (const gsl_rng * @var{r}, double @var{a})@cindex Cauchy random variatesThis function returns a random variate from the Cauchy distribution withscale parameter @var{a}. The probability distribution for Cauchyrandom variates is,@tex\beforedisplay$$p(x) dx = {1 \over a\pi (1 + (x/a)^2) } dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over a\pi (1 + (x/a)^2) @} dx@end example@end ifinfo@noindentfor @math{x} in the range @math{-\infty} to @math{+\infty}. The Cauchydistribution is also known as the Lorentz distribution.@end deftypefn@deftypefun double gsl_ran_cauchy_pdf (double @var{x}, double @var{a})This function computes the probability density @math{p(x)} at @var{x}for a Cauchy distribution with scale parameter @var{a}, using the formulagiven above.@end deftypefun@sp 1@tex\centerline{\input rand-cauchy.tex}@end tex@page@node The Rayleigh Distribution@section The Rayleigh Distribution@deftypefn Random double gsl_ran_rayleigh (const gsl_rng * @var{r}, double @var{sigma})@cindex Rayleigh random variatesThis function returns a random variate from the Rayleigh distribution withscale parameter @var{sigma}. The distribution is,@tex\beforedisplay$$p(x) dx = {x \over \sigma^2} \exp(- x^2/(2 \sigma^2)) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{x \over \sigma^2@} \exp(- x^2/(2 \sigma^2)) dx@end example@end ifinfo@noindentfor @math{x > 0}.@end deftypefn@deftypefun double gsl_ran_rayleigh_pdf (double @var{x}, double @var{sigma})This function computes the probability density @math{p(x)} at @var{x}for a Rayleigh distribution with scale parameter @var{sigma}, using theformula given above.@end deftypefun@sp 1@tex\centerline{\input rand-rayleigh.tex}@end tex@page@node The Rayleigh Tail Distribution@section The Rayleigh Tail Distribution@deftypefn Random double gsl_ran_rayleigh_tail (const gsl_rng * @var{r}, double @var{a} double @var{sigma})@cindex Rayleigh Tail random variatesThis function returns a random variate from the tail of the Rayleighdistribution with scale parameter @var{sigma} and a lower limit of@var{a}. The distribution is,@tex\beforedisplay$$p(x) dx = {x \over \sigma^2} \exp ((a^2 - x^2) /(2 \sigma^2)) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{x \over \sigma^2@} \exp ((a^2 - x^2) /(2 \sigma^2)) dx@end example@end ifinfo@noindentfor @math{x > a}.@end deftypefn@deftypefun double gsl_ran_rayleigh_tail_pdf (double @var{x}, double @var{a}, double @var{sigma})This function computes the probability density @math{p(x)} at @var{x}for a Rayleigh tail distribution with scale parameter @var{sigma} andlower limit @var{a}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-rayleigh-tail.tex}@end tex@page@node The Landau Distribution@section The Landau Distribution@deftypefn Random double gsl_ran_landau (const gsl_rng * @var{r})@cindex Landau random variates
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -