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

📄 randist.texi

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@cindex direction vector, random 3D@cindex spherical random variates, 3DThis function returns a random direction vector @math{v} =(@var{x},@var{y},@var{z}) in three dimensions.  The vector is normalizedsuch that @math{|v|^2 = x^2 + y^2 + z^2 = 1}.  The method employed isdue to Robert E. Knop (CACM 13, 326 (1970)), and explained in Knuth, v2,3rd ed, p136.  It uses the surprising fact that the distributionprojected along any axis is actually uniform (this is only true for 3d).@end deftypefn@deftypefn Random void gsl_ran_dir_nd (const gsl_rng * @var{r}, size_t @var{n}, double *@var{x})@cindex N-dimensional random direction vector@cindex direction vector, random N-dimensional@cindex spherical random variates, N-dimensionalThis function returns a random direction vector@c{$v = (x_1,x_2,\ldots,x_n)$}@math{v = (x_1,x_2,...,x_n)} in @var{n} dimensions.  The vector is normalizedsuch that @c{$|v|^2 = x_1^2 + x_2^2 + \cdots + x_n^2 = 1$}@math{|v|^2 = x_1^2 + x_2^2 + ... + x_n^2 = 1}.  The methoduses the fact that a multivariate gaussian distribution is sphericallysymmetric.  Each component is generated to have a gaussian distribution,and then the components are normalized.  The method is described byKnuth, v2, 3rd ed, p135-136, and attributed to G. W. Brown, ModernMathematics for the Engineer (1956).@end deftypefn@page@node The Weibull Distribution@section The Weibull Distribution@deftypefn Random double gsl_ran_weibull (const gsl_rng * @var{r}, double @var{a}, double @var{b})@cindex Weibull distributionThis function returns a random variate from the Weibull distribution.  Thedistribution function is,@tex\beforedisplay$$p(x) dx = {b \over a^b} x^{b-1}  \exp(-(x/a)^b) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = @{b \over a^b@} x^@{b-1@}  \exp(-(x/a)^b) dx@end example@end ifinfo@noindentfor @c{$x \ge 0$}@math{x >= 0}.@end deftypefn@deftypefun double gsl_ran_weibull_pdf (double @var{x}, double @var{a}, double @var{b})This function computes the probability density @math{p(x)} at @var{x}for a Weibull distribution with scale @var{a} and exponent @var{b},using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-weibull.tex}@end tex@deftypefun double gsl_cdf_weibull_P (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_weibull_Q (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_weibull_Pinv (double @var{P}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_weibull_Qinv (double @var{Q}, double @var{a}, double @var{b})These functions compute the cumulative distribution functions@math{P(x)}, @math{Q(x)} and their inverses for the Weibulldistribution with scale @var{a} and exponent @var{b}.@end deftypefun@page@node The Type-1 Gumbel Distribution@section  The Type-1 Gumbel Distribution@deftypefn Random double gsl_ran_gumbel1 (const gsl_rng * @var{r}, double @var{a}, double @var{b})@cindex Gumbel distribution (Type 1)@cindex Type 1 Gumbel distribution, random variatesThis function returns  a random variate from the Type-1 Gumbeldistribution.  The Type-1 Gumbel distribution function is,@tex\beforedisplay$$p(x) dx = a b \exp(-(b \exp(-ax) + ax)) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = a b \exp(-(b \exp(-ax) + ax)) dx@end example@end ifinfo@noindentfor @math{-\infty < x < \infty}. @end deftypefn@deftypefun double gsl_ran_gumbel1_pdf (double @var{x}, double @var{a}, double @var{b})This function computes the probability density @math{p(x)} at @var{x}for a Type-1 Gumbel distribution with parameters @var{a} and @var{b},using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-gumbel1.tex}@end tex@deftypefun double gsl_cdf_gumbel1_P (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel1_Q (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel1_Pinv (double @var{P}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel1_Qinv (double @var{Q}, double @var{a}, double @var{b})These functions compute the cumulative distribution functions@math{P(x)}, @math{Q(x)} and their inverses for the Type-1 Gumbeldistribution with parameters @var{a} and @var{b}.@end deftypefun@page@node The Type-2 Gumbel Distribution@section  The Type-2 Gumbel Distribution@deftypefn Random double gsl_ran_gumbel2 (const gsl_rng * @var{r}, double @var{a}, double @var{b})@cindex Gumbel distribution (Type 2)@cindex Type 2 Gumbel distributionThis function returns a random variate from the Type-2 Gumbeldistribution.  The Type-2 Gumbel distribution function is,@tex\beforedisplay$$p(x) dx = a b x^{-a-1} \exp(-b x^{-a}) dx$$\afterdisplay@end tex@ifinfo@examplep(x) dx = a b x^@{-a-1@} \exp(-b x^@{-a@}) dx@end example@end ifinfo@noindentfor @math{0 < x < \infty}.@end deftypefn@deftypefun double gsl_ran_gumbel2_pdf (double @var{x}, double @var{a}, double @var{b})This function computes the probability density @math{p(x)} at @var{x}for a Type-2 Gumbel distribution with parameters @var{a} and @var{b},using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-gumbel2.tex}@end tex@deftypefun double gsl_cdf_gumbel2_P (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel2_Q (double @var{x}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel2_Pinv (double @var{P}, double @var{a}, double @var{b})@deftypefunx double gsl_cdf_gumbel2_Qinv (double @var{Q}, double @var{a}, double @var{b})These functions compute the cumulative distribution functions@math{P(x)}, @math{Q(x)} and their inverses for the Type-2 Gumbeldistribution with parameters @var{a} and @var{b}.@end deftypefun@page@node The Dirichlet Distribution@section The Dirichlet Distribution@deftypefn Random void gsl_ran_dirichlet (const gsl_rng * @var{r}, size_t @var{K}, const double @var{alpha}[], double @var{theta}[])@cindex Dirichlet distribution This function returns an array of @var{K} random variates from a Dirichletdistribution of order @var{K}-1. The distribution function is@tex\beforedisplay$$p(\theta_1,\ldots,\theta_K) \, d\theta_1 \cdots d\theta_K =         {1 \over Z} \prod_{i=1}^{K} \theta_i^{\alpha_i - 1}           \; \delta(1 -\sum_{i=1}^K \theta_i) d\theta_1 \cdots d\theta_K$$\afterdisplay@end tex@ifinfo@examplep(\theta_1, ..., \theta_K) d\theta_1 ... d\theta_K =   (1/Z) \prod_@{i=1@}^K \theta_i^@{\alpha_i - 1@} \delta(1 -\sum_@{i=1@}^K \theta_i) d\theta_1 ... d\theta_K@end example@end ifinfo@noindentfor @c{$\theta_i \ge 0$} @math{theta_i >= 0}and @c{$\alpha_i \ge 0$} @math{alpha_i >= 0}.  The delta function ensures that @math{\sum \theta_i = 1}.The normalization factor @math{Z} is@tex\beforedisplay$$Z = {\prod_{i=1}^K \Gamma(\alpha_i) \over \Gamma( \sum_{i=1}^K \alpha_i)}$$\afterdisplay@end tex@ifinfo@exampleZ = @{\prod_@{i=1@}^K \Gamma(\alpha_i)@} / @{\Gamma( \sum_@{i=1@}^K \alpha_i)@}@end example@end ifinfoThe random variates are generated by sampling @var{K} values from gamma distributions with parameters @c{$a=\alpha_i$, $b=1$} @math{a=alpha_i, b=1}, and renormalizing. See A.M. Law, W.D. Kelton, @cite{Simulation Modeling and Analysis} (1991).@end deftypefn@deftypefun double gsl_ran_dirichlet_pdf (size_t @var{K}, const double @var{alpha}[], const double @var{theta}[]) This function computes the probability density @c{$p(\theta_1, \ldots , \theta_K)$}@math{p(\theta_1, ... , \theta_K)}at @var{theta}[@var{K}] for a Dirichlet distribution with parameters @var{alpha}[@var{K}], using the formula given above.@end deftypefun@deftypefun double gsl_ran_dirichlet_lnpdf (size_t @var{K}, const double @var{alpha}[], const double @var{theta}[]) This function computes the logarithm of the probability density @c{$p(\theta_1, \ldots , \theta_K)$}@math{p(\theta_1, ... , \theta_K)}for a Dirichlet distribution with parameters @var{alpha}[@var{K}].@end deftypefun@page@node General Discrete Distributions@section General Discrete DistributionsGiven @math{K} discrete events with different probabilities @math{P[k]},produce a random value @math{k} consistent with its probability.The obvious way to do this is to preprocess the probability list bygenerating a cumulative probability array with @math{K+1} elements:@tex\beforedisplay$$\eqalign{C[0] & = 0 \crC[k+1] &= C[k]+P[k].}$$\afterdisplay@end tex@ifinfo@example  C[0] = 0 C[k+1] = C[k]+P[k].@end example@end ifinfo@noindentNote that this construction produces @math{C[K]=1}.  Now choose auniform deviate @math{u} between 0 and 1, and find the value of @math{k}such that @c{$C[k] \le u < C[k+1]$}@math{C[k] <= u < C[k+1]}.  Although this in principle requires of order @math{\log K} steps perrandom number generation, they are fast steps, and if you use somethinglike @math{\lfloor uK \rfloor} as a starting point, you can often dopretty well.But faster methods have been devised.  Again, the idea is to preprocessthe probability list, and save the result in some form of lookup table;then the individual calls for a random discrete event can go rapidly.An approach invented by G. Marsaglia (Generating discrete random numbersin a computer, Comm ACM 6, 37-38 (1963)) is very clever, and readersinterested in examples of good algorithm design are directed to thisshort and well-written paper.  Unfortunately, for large @math{K},Marsaglia's lookup table can be quite large.  A much better approach is due to Alastair J. Walker (An efficient methodfor generating discrete random variables with general distributions, ACMTrans on Mathematical Software 3, 253-256 (1977); see also Knuth, v2,3rd ed, p120-121,139).  This requires two lookup tables, one floatingpoint and one integer, but both only of size @math{K}.  Afterpreprocessing, the random numbers are generated in O(1) time, even forlarge @math{K}.  The preprocessing suggested by Walker requires@math{O(K^2)} effort, but that is not actually necessary, and theimplementation provided here only takes @math{O(K)} effort.  In general,more preprocessing leads to faster generation of the individual randomnumbers, but a diminishing return is reached pretty early.  Knuth pointsout that the optimal preprocessing is combinatorially difficult forlarge @math{K}.This method can be used to speed up some of the discrete random numbergenerators below, such as the binomial distribution.  To use if forsomething like the Poisson Distribution, a modification would have tobe made, since it only takes a finite set of @math{K} outcomes.@deftypefun {gsl_ran_discrete_t *} gsl_ran_discrete_preproc (size_t @var{K}, const double * @var{P})@cindex Discrete random numbers@cindex Discrete random numbers, preprocessingThis function returns a pointer to a structure that contains the lookuptable for the discrete random number generator.  The array @var{P}[] containsthe probabilities of the discrete events; these array elements must all be positive, but they needn't add up to one (so you can think of them moregenerally as "weights") -- the preprocessor will normalize appropriately.This return value is usedas an argument for the @code{gsl_ran_discrete} function below.@end deftypefun@deftypefn Random {size_t} gsl_ran_discrete (const gsl_rng * @var{r}, const gsl_ran_discrete_t * @var{g})@cindex Discrete random numbersAfter the preprocessor, above, has been called, you use this function toget the discrete random numbers.@end deftypefn@deftypefun {double} gsl_ran_discrete_pdf (size_t @var{k}, const gsl_ran_discrete_t * @var{g})@cindex Discrete random numbersReturns the probability @math{P[k]} of observing the variable @var{k}.Since @math{P[k]} is not stored as part of the lookup table, it must berecomputed; this computation takes @math{O(K)}, so if @var{K} is largeand you care about the original array @math{P[k]} used to create thelookup table, then you should just keep this original array @math{P[k]}around.@end deftypefun@deftypefun {void} gsl_ran_discrete_free (gsl_ran_discrete_t * @var{g})@cindex Discrete random numbersDe-allocates the lookup table pointed to by @var{g}.@end deftypefun@page@node The Poisson Distribution@section The Poisson Distribution@deftypefn Random {unsigned int} gsl_ran_poisson (const gsl_rng * @var{r}, double @var{mu})@cindex Poisson random numbersThis function returns a random integer from the Poisson distributionwith mean @var{mu}.  The probability distribution for Poisson variates is,@tex\beforedisplay$$p(k) = {\mu^k \over k!} \exp(-\mu)$$\afterdisplay@end tex@ifinfo@examplep(k) = @{\mu^k \over k!@} \exp(-\mu)@end example@end ifinfo@noindentfor @c{$k \ge 0$}@math{k >= 0}.@end deftypefn@deftypefun double gsl_ran_poisson_pdf (unsigned int @var{k}, double @var{mu})This function computes the probability @math{p(k)} of obtaining  @var{k}from a Poisson distribution with mean @var{mu}, using the formulagiven above.@end deftypefun@sp 1@tex\centerline{\input rand-poisson.tex}@end tex@page@node The Bernoulli Distribution@section The Bernoulli Distribution@deftypefn Random {unsigned int} gsl_ran_bernoulli (const gsl_rng * @var{r}, double @var{p})@cindex Bernoulli trial, random variatesThis function returns either 0 or 1, the result of a Bernoulli trialwith probability @var{p}.  The probability distribution for a Bernoullitrial is,@tex\beforedisplay$$\eqalign{p(0) & = 1 - p \crp(1) & = p}$$\afterdisplay@end tex@ifinfo@examplep(0) = 1 - pp(1) = p@end example@end ifinfo@end deftypefn@deftypefun double gsl_ran_bernoulli_pdf (unsigned int @var{k}, double @var{p})This function computes the probability @math{p(k)} of obtaining@var{k} from a Bernoulli distribution with probability parameter@var{p}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-bernoulli.tex}

⌨️ 快捷键说明

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