⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 randist.texi

📁 This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without ev
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@cindex random number distributions@cindex cumulative distribution functions (CDFs)@cindex CDFs, cumulative distribution functions@cindex inverse cumulative distribution functions@cindex quantile functionsThis 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 be obtainedanalytically from the uniform distribution of a random number generatorby applying an appropriate transformation.  This method uses one call tothe random number generator.  More complicated distributions are createdby 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 library also provides cumulative distribution functions and inversecumulative distribution functions, sometimes referred to as quantilefunctions.  The cumulative distribution functions and their inverses arecomputed separately for the upper and lower tails of the distribution,allowing full accuracy to be retained for small results.The functions for random variates and probability density functionsdescribed in this section are declared in @file{gsl_randist.h}.  Thecorresponding cumulative distribution functions are declared in@file{gsl_cdf.h}.Note that the discrete random variate functions alwaysreturn a value of type @code{unsigned int}, and on most platforms thishas a maximum value of @c{$2^{32}-1 \approx 4.29\times10^9$} @math{2^32-1 ~=~ 4.29e9}. They should only be called witha safe range of parameters (where there is a negligible probability ofa variate exceeding this limit) to prevent incorrect results due tooverflow.@menu* Random Number Distribution Introduction::  * 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::     * Spherical Vector Distributions::  * The Weibull Distribution::    * The Type-1 Gumbel Distribution::  * The Type-2 Gumbel Distribution::  * The Dirichlet Distribution::  * General Discrete Distributions::  * The Poisson Distribution::    * The Bernoulli Distribution::  * The Binomial Distribution::   * The Multinomial 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@node Random Number Distribution Introduction@section IntroductionContinuous random number distributions are defined by a probabilitydensity function, @math{p(x)}, such that the probability of @math{x}occurring in the infinitesimal range @math{x} to @math{x+dx} is @c{$p\,dx$}@math{p dx}.The cumulative distribution function for the lower tail @math{P(x)} isdefined by the integral,@tex\beforedisplay$$P(x) = \int_{-\infty}^{x} dx' p(x')$$\afterdisplay@end tex@ifinfo@exampleP(x) = \int_@{-\infty@}^@{x@} dx' p(x')@end example@end ifinfo@noindentand gives the probability of a variate taking a value less than @math{x}.The cumulative distribution function for the upper tail @math{Q(x)} isdefined by the integral,@tex\beforedisplay$$Q(x) = \int_{x}^{+\infty} dx' p(x')$$\afterdisplay@end tex@ifinfo@exampleQ(x) = \int_@{x@}^@{+\infty@} dx' p(x')@end example@end ifinfo@noindentand gives the probability of a variate taking a value greater than @math{x}.The upper and lower cumulative distribution functions are related by@math{P(x) + Q(x) = 1} and satisfy @c{$0 \le P(x) \le 1$}@math{0 <= P(x) <= 1}, @c{$0 \le Q(x) \le 1$}@math{0 <= Q(x) <= 1}.The inverse cumulative distributions, @c{$x=P^{-1}(P)$}@math{x=P^@{-1@}(P)} and @c{$x=Q^{-1}(Q)$}@math{x=Q^@{-1@}(Q)} give the values of @math{x}which correspond to a specific value of @math{P} or @math{Q}.  They can be used to find confidence limits from probability values.For discrete distributions the probability of sampling the integervalue @math{k} is given by @math{p(k)}, where @math{\sum_k p(k) = 1}.The cumulative distribution for the lower tail @math{P(k)} of adiscrete distribution is defined as,@tex\beforedisplay$$P(k) = \sum_{i \le k} p(i) $$\afterdisplay@end tex@ifinfo@exampleP(k) = \sum_@{i <= k@} p(i)@end example@end ifinfo@noindentwhere the sum is over the allowed range of the distribution less thanor equal to @math{k}.  The cumulative distribution for the upper tail of a discretedistribution @math{Q(k)} is defined as@tex\beforedisplay$$Q(k) = \sum_{i > k} p(i) $$\afterdisplay@end tex@ifinfo@exampleQ(k) = \sum_@{i > k@} p(i)@end example@end ifinfo@noindentgiving the sum of probabilities for all values greater than @math{k}.These two definitions satisfy the identity @math{P(k)+Q(k)=1}.If the range of the distribution is 1 to @math{n} inclusive then@math{P(n)=1}, @math{Q(n)=0} while @math{P(1) = p(1)},@math{Q(1)=1-p(1)}.@page@node The Gaussian Distribution@section The Gaussian Distribution@deftypefun double gsl_ran_gaussian (const gsl_rng * @var{r}, double @var{sigma})@cindex Gaussian distributionThis 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 to the random number generator @var{r}.@end deftypefun@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_ziggurat (const gsl_rng * @var{r}, double @var{sigma})@deftypefunx double gsl_ran_gaussian_ratio_method (const gsl_rng * @var{r}, double @var{sigma})This function computes a Gaussian random variate using the alternativeMarsaglia-Tsang ziggurat and Kinderman-Monahan-Leva ratio methods.  TheZiggurat algorithm is the fastest available algorithm in most cases.@end deftypefun@deftypefun double gsl_ran_ugaussian (const gsl_rng * @var{r})@deftypefunx double gsl_ran_ugaussian_pdf (double @var{x})@deftypefunx double gsl_ran_ugaussian_ratio_method (const gsl_rng * @var{r})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 deftypefun@deftypefun double gsl_cdf_gaussian_P (double @var{x}, double @var{sigma})@deftypefunx double gsl_cdf_gaussian_Q (double @var{x}, double @var{sigma})@deftypefunx double gsl_cdf_gaussian_Pinv (double @var{P}, double @var{sigma})@deftypefunx double gsl_cdf_gaussian_Qinv (double @var{Q}, double @var{sigma})These functions compute the cumulative distribution functions@math{P(x)}, @math{Q(x)} and their inverses for the Gaussiandistribution with standard deviation @var{sigma}.@end deftypefun@deftypefun double gsl_cdf_ugaussian_P (double @var{x})@deftypefunx double gsl_cdf_ugaussian_Q (double @var{x})@deftypefunx double gsl_cdf_ugaussian_Pinv (double @var{P})@deftypefunx double gsl_cdf_ugaussian_Qinv (double @var{Q})These functions compute the cumulative distribution functions@math{P(x)}, @math{Q(x)} and their inverses for the unit Gaussiandistribution.@end deftypefun@page@node The Gaussian Tail Distribution@section The Gaussian Tail Distribution@deftypefun double gsl_ran_gaussian_tail (const gsl_rng * @var{r}, double @var{a}, double @var{sigma})@cindex Gaussian Tail distributionThis 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 (Ann. Math. 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) \sqrt{2 \pi \sigma^2}} \exp (- x^2 / 2\sigma^2) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{1 \over N(a;\sigma) \sqrt@{2 \pi \sigma^2@}@} \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 deftypefun@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@deftypefun double gsl_ran_ugaussian_tail (const gsl_rng * @var{r}, double @var{a})@deftypefunx 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 deftypefun@page@node The Bivariate Gaussian Distribution@section The Bivariate Gaussian Distribution@deftypefun 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 Bivariate Gaussian distribution@cindex two dimensional Gaussian distribution@cindex Gaussian distribution, bivariateThis 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/\sigma_x^2 + y^2/\sigma_y^2 - 2 \rho x y/(\sigma_x\sigma_y)) \over 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/\sigma_x^2 + y^2/\sigma_y^2 - 2 \rho x y/(\sigma_x\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 deftypefun@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@deftypefun double gsl_ran_exponential (const gsl_rng * @var{r}, double @var{mu})@cindex Exponential distributionThis 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 deftypefun@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@deftypefun double gsl_cdf_exponential_P (double @var{x}, double @var{mu})@deftypefunx double gsl_cdf_exponential_Q (double @var{x}, double @var{mu})

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -