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

📄 randist.texi

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
@end tex@page@node The Binomial Distribution@section The Binomial Distribution@deftypefn Random {unsigned int} gsl_ran_binomial (const gsl_rng * @var{r}, double @var{p}, unsigned int @var{n})@cindex Binomial random variatesThis function returns a random integer from the binomial distribution,the number of successes in @var{n} independent trials with probability@var{p}.  The probability distribution for binomial variates is,@tex\beforedisplay$$p(k) = {n! \over k! (n-k)!} p^k (1-p)^{n-k}$$\afterdisplay@end tex@ifinfo@examplep(k) = @{n! \over k! (n-k)! @} p^k (1-p)^@{n-k@}@end example@end ifinfo@noindentfor @c{$0 \le k \le n$}@math{0 <= k <= n}.@end deftypefn@deftypefun double gsl_ran_binomial_pdf (unsigned int @var{k}, double @var{p}, unsigned int @var{n})This function computes the probability @math{p(k)} of obtaining @var{k}from a binomial distribution with parameters @var{p} and @var{n}, usingthe formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-binomial.tex}@end tex@page@node The Multinomial Distribution@section The Multinomial Distribution@deftypefn Random void gsl_ran_multinomial (const gsl_rng * @var{r}, size_t @var{K}, unsigned int @var{N}, const double @var{p}[], unsigned int @var{n}[])@cindex Multinomial distribution This function returns an array of @var{K} random variates from a multinomial distribution. The distribution function is,@tex\beforedisplay$$P(n_1, n_2,\cdots, n_K) = {{ N!}\over{n_1 ! n_2 ! \cdots n_K !}} \,  p_1^{n_1} p_2^{n_2} \cdots p_K^{n_K}$$\afterdisplay@end tex@ifinfo@exampleP(n_1, n_2, ..., n_K) =   (N!/(n_1! n_2! ... n_K!)) p_1^n_1 p_2^n_2 ... p_K^n_K@end example@end ifinfo@noindentwhere @c{($n_1$, $n_2$, $\ldots$, $n_K$)}@math{(n_1, n_2, ..., n_K)} are nonnegative integers with @c{$\sum_{k=1}^{K} n_k =N$} @math{sum_@{k=1@}^K n_k = N},and@c{$(p_1, p_2, \ldots, p_K)$} @math{(p_1, p_2, ..., p_K)}is a probability distribution with @math{\sum p_i = 1}.  If the array @var{p}[@var{K}] is not normalized then its entries will betreated as weights and normalized appropriately.Random variates are generated using the conditional binomial method (seeC.S. David, @cite{The computer generation of multinomial randomvariates}, Comp. Stat. Data Anal. 16 (1993) 205-217 for details).@end deftypefn@deftypefun double gsl_ran_multinomial_pdf (size_t @var{K}, const double @var{p}[], const unsigned int @var{n}[]) This function computes the probability @c{$P(n_1, n_2, \ldots, n_K)$}@math{P(n_1, n_2, ..., n_K)}of sampling @var{n}[@var{K}] from a multinomial distribution with parameters @var{p}[@var{K}], using the formula given above.@end deftypefun@deftypefun double gsl_ran_multinomial_lnpdf (size_t @var{K}, const double @var{p}[], const unsigned int @var{n}[]) This function returns the logarithm of the probability for themultinomial distribution @c{$P(n_1, n_2, \ldots, n_K)$}@math{P(n_1, n_2, ..., n_K)} with parameters @var{p}[@var{K}].@end deftypefun@page@node The Negative Binomial Distribution@section The Negative Binomial Distribution@deftypefn Random {unsigned int} gsl_ran_negative_binomial (const gsl_rng * @var{r}, double @var{p}, double @var{n})@cindex Negative Binomial distribution, random variatesThis function returns a random integer from the negative binomialdistribution, the number of failures occurring before @var{n} successesin independent trials with probability @var{p} of success.  Theprobability distribution for negative binomial variates is,@tex\beforedisplay$$p(k) = {\Gamma(n + k) \over \Gamma(k+1) \Gamma(n) } p^n (1-p)^k$$\afterdisplay@end tex@ifinfo@examplep(k) = @{\Gamma(n + k) \over \Gamma(k+1) \Gamma(n) @} p^n (1-p)^k@end example@end ifinfo@noindentNote that @math{n} is not required to be an integer.@end deftypefn@deftypefun double gsl_ran_negative_binomial_pdf (unsigned int @var{k}, double @var{p}, double  @var{n})This function computes the probability @math{p(k)} of obtaining @var{k}from a negative binomial distribution with parameters @var{p} and@var{n}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-nbinomial.tex}@end tex@page@node The Pascal Distribution@section The Pascal Distribution@deftypefn Random {unsigned int} gsl_ran_pascal (const gsl_rng * @var{r}, double @var{p}, unsigned int @var{n})This function returns a random integer from the Pascal distribution.  ThePascal distribution is simply a negative binomial distribution with aninteger value of @math{n}.@tex\beforedisplay$$p(k) = {(n + k - 1)! \over k! (n - 1)! } p^n (1-p)^k$$\afterdisplay@end tex@ifinfo@examplep(k) = @{(n + k - 1)! \over k! (n - 1)! @} p^n (1-p)^k@end example@end ifinfo@noindentfor @c{$k \ge 0$}@math{k >= 0}@end deftypefn@deftypefun double gsl_ran_pascal_pdf (unsigned int @var{k}, double @var{p}, unsigned int @var{n})This function computes the probability @math{p(k)} of obtaining @var{k}from a Pascal distribution with parameters @var{p} and@var{n}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-pascal.tex}@end tex@page@node The Geometric Distribution@section The Geometric Distribution@deftypefn Random {unsigned int} gsl_ran_geometric (const gsl_rng * @var{r}, double @var{p})@cindex Geometric random variatesThis function returns a random integer from the geometric distribution,the number of independent trials with probability @var{p} until thefirst success.  The probability distribution for geometric variatesis,@tex\beforedisplay$$p(k) =  p (1-p)^{k-1}$$\afterdisplay@end tex@ifinfo@examplep(k) =  p (1-p)^(k-1)@end example@end ifinfo@noindentfor @c{$k \ge 1$}@math{k >= 1}.@end deftypefn@deftypefun double gsl_ran_geometric_pdf (unsigned int @var{k}, double @var{p})This function computes the probability @math{p(k)} of obtaining @var{k}from a geometric distribution with probability parameter @var{p}, usingthe formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-geometric.tex}@end tex@page@node The Hypergeometric Distribution@section The Hypergeometric Distribution@deftypefn Random {unsigned int} gsl_ran_hypergeometric (const gsl_rng * @var{r}, unsigned int @var{n1}, unsigned int @var{n2}, unsigned int @var{t})@cindex Geometric random variatesThis function returns a random integer from the hypergeometricdistribution.  The probability distribution for hypergeometricrandom variates is,@tex\beforedisplay$$p(k) =  C(n_1,k) C(n_2, t-k) / C(n_1+n_2,k)$$\afterdisplay@end tex@ifinfo@examplep(k) =  C(n_1,k) C(n_2, t-k) / C(n_1 + n_2,k)@end example@end ifinfo@noindentwhere @math{C(a,b) = a!/(b!(a-b)!)}.  The domain of @math{k} is@c{$\hbox{max}(0\,t-n_2), \ldots, \hbox{max}(t,n_1)$}@math{max(0,t-n_2), ..., max(t,n_1)}.@end deftypefn@deftypefun double gsl_ran_hypergeometric_pdf (unsigned int @var{k}, unsigned int @var{n1}, unsigned int @var{n2}, unsigned int @var{t})This function computes the probability @math{p(k)} of obtaining @var{k}from a hypergeometric distribution with parameters @var{n1}, @var{n2},@var{n3}, using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-hypergeometric.tex}@end tex@page@node The Logarithmic Distribution@section The Logarithmic Distribution@deftypefn Random {unsigned int} gsl_ran_logarithmic (const gsl_rng * @var{r}, double @var{p})@cindex Logarithmic random variatesThis function returns a random integer from the logarithmicdistribution.  The probability distribution for logarithmic random variatesis,@tex\beforedisplay$$p(k) = {-1 \over \log(1-p)} {\left( p^k \over k \right)}$$\afterdisplay@end tex@ifinfo@examplep(k) = @{-1 \over \log(1-p)@} @{(p^k \over k)@}@end example@end ifinfo@noindentfor @c{$k \ge 1$}@math{k >= 1}.@end deftypefn@deftypefun double gsl_ran_logarithmic_pdf (unsigned int @var{k}, double @var{p})This function computes the probability @math{p(k)} of obtaining @var{k}from a logarithmic distribution with probability parameter @var{p},using the formula given above.@end deftypefun@sp 1@tex\centerline{\input rand-logarithmic.tex}@end tex@page@node Shuffling and Sampling@section Shuffling and SamplingThe following functions allow the shuffling and sampling of a set ofobjects.  The algorithms rely on a random number generator as source ofrandomness and a poor quality generator can lead to correlations in theoutput.  In particular it is important to avoid generators with a shortperiod.  For more information see Knuth, v2, 3rd ed, Section 3.4.2,``Random Sampling and Shuffling''.@deftypefn Random void gsl_ran_shuffle (const gsl_rng * @var{r}, void * @var{base}, size_t @var{n}, size_t @var{size})This function randomly shuffles the order of @var{n} objects, each ofsize @var{size}, stored in the array @var{base}[0..@var{n}-1].  Theoutput of the random number generator @var{r} is used to produce thepermutation.  The algorithm generates all possible @math{n!}permutations with equal probability, assuming a perfect source of randomnumbers.The following code shows how to shuffle the numbers from 0 to 51,@exampleint a[52];for (i = 0; i < 52; i++)  @{    a[i] = i;  @}gsl_ran_shuffle (r, a, 52, sizeof (int));@end example@end deftypefn@deftypefn Random int gsl_ran_choose (const gsl_rng * @var{r}, void * @var{dest}, size_t @var{k}, void * @var{src}, size_t @var{n}, size_t @var{size})This function fills the array @var{dest}[k] with @var{k} objects takenrandomly from the @var{n} elements of the array@var{src}[0..@var{n}-1].  The objects are each of size @var{size}.  Theoutput of the random number generator @var{r} is used to make theselection.  The algorithm ensures all possible samples are equallylikely, assuming a perfect source of randomness.The objects are sampled @emph{without} replacement, thus each object canonly appear once in @var{dest}[k].  It is required that @var{k} be lessthan or equal to @code{n}.  The objects in @var{dest} will be in thesame relative order as those in @var{src}.  You will need to call@code{gsl_ran_shuffle(r, dest, n, size)} if you want to randomize theorder.The following code shows how to select a random sample of three uniquenumbers from the set 0 to 99,@exampledouble a[3], b[100];for (i = 0; i < 100; i++)  @{    b[i] = (double) i;  @}gsl_ran_choose (r, a, 3, b, 100, sizeof (double));@end example@end deftypefn@deftypefn Random void gsl_ran_sample (const gsl_rng * @var{r}, void * @var{dest}, size_t @var{k}, void * @var{src}, size_t @var{n}, size_t @var{size})This function is like @code{gsl_ran_choose} but samples @var{k} itemsfrom the original array of @var{n} items @var{src} with replacement, sothe same object can appear more than once in the output sequence@var{dest}.  There is no requirement that @var{k} be less than @var{n}in this case.@end deftypefn@node Random Number Distribution Examples@section ExamplesThe following program demonstrates the use of a random number generatorto produce variates from a distribution.  It prints 10 samples from thePoisson distribution with a mean of 3.@example@verbatiminclude examples/randpoisson.c@end example@noindentIf the library and header files are installed under @file{/usr/local}(the default location) then the program can be compiled with theseoptions,@examplegcc demo.c -lgsl -lgslcblas -lm@end example@noindentHere is the output of the program,@example$ ./a.out @verbatiminclude examples/randpoisson.out@end example@noindentThe variates depend on the seed used by the generator.  The seed for thedefault generator type @code{gsl_rng_default} can be changed with the@code{GSL_RNG_SEED} environment variable to produce a different streamof variates,@example$ GSL_RNG_SEED=123 ./a.out @verbatiminclude examples/randpoisson.2.out@end example@noindentThe following program generates a random walk in two dimensions.@example@verbatiminclude examples/randwalk.c@end example@noinde

⌨️ 快捷键说明

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