📄 randist.texi
字号:
@end tex
@ifinfo
@example
p(k) = @{\mu^k \over k!@} \exp(-\mu)
@end example
@end ifinfo
@noindent
for @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 formula
given 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 variates
This function returns either 0 or 1, the result of a Bernoulli trial
with probability @var{p}. The probability distribution for a Bernoulli
trial is,
@tex
\beforedisplay
$$
\eqalign{
p(0) & = 1 - p \cr
p(1) & = p
}
$$
\afterdisplay
@end tex
@ifinfo
@example
p(0) = 1 - p
p(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}
@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 variates
This 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
@example
p(k) = @{n! \over k! (n-k)! @} p^k (1-p)^@{n-k@}
@end example
@end ifinfo
@noindent
for @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}, using
the 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
@example
P(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
@noindent
where @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 be
treated as weights and normalized appropriately.
Random variates are generated using the conditional binomial method (see
C.S. David, @cite{The computer generation of multinomial random
variates}, 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 the
multinomial 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 variates
This function returns a random integer from the negative binomial
distribution, the number of failures occurring before @var{n} successes
in independent trials with probability @var{p} of success. The
probability 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
@example
p(k) = @{\Gamma(n + k) \over \Gamma(k+1) \Gamma(n) @} p^n (1-p)^k
@end example
@end ifinfo
@noindent
Note 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. The
Pascal distribution is simply a negative binomial distribution with an
integer value of @math{n}.
@tex
\beforedisplay
$$
p(k) = {(n + k - 1)! \over k! (n - 1)! } p^n (1-p)^k
$$
\afterdisplay
@end tex
@ifinfo
@example
p(k) = @{(n + k - 1)! \over k! (n - 1)! @} p^n (1-p)^k
@end example
@end ifinfo
@noindent
for @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 variates
This function returns a random integer from the geometric distribution,
the number of independent trials with probability @var{p} until the
first success. The probability distribution for geometric variates
is,
@tex
\beforedisplay
$$
p(k) = p (1-p)^{k-1}
$$
\afterdisplay
@end tex
@ifinfo
@example
p(k) = p (1-p)^(k-1)
@end example
@end ifinfo
@noindent
for @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}, using
the 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 variates
This function returns a random integer from the hypergeometric
distribution. The probability distribution for hypergeometric
random 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
@example
p(k) = C(n_1,k) C(n_2, t-k) / C(n_1 + n_2,k)
@end example
@end ifinfo
@noindent
where @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 variates
This function returns a random integer from the logarithmic
distribution. The probability distribution for logarithmic random variates
is,
@tex
\beforedisplay
$$
p(k) = {-1 \over \log(1-p)} {\left( p^k \over k \right)}
$$
\afterdisplay
@end tex
@ifinfo
@example
p(k) = @{-1 \over \log(1-p)@} @{(p^k \over k)@}
@end example
@end ifinfo
@noindent
for @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 Sampling
The following functions allow the shuffling and sampling of a set of
objects. The algorithms rely on a random number generator as source of
randomness and a poor quality generator can lead to correlations in the
output. In particular it is important to avoid generators with a short
period. 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 of
size @var{size}, stored in the array @var{base}[0..@var{n}-1]. The
output of the random number generator @var{r} is used to produce the
permutation. The algorithm generates all possible @math{n!}
permutations with equal probability, assuming a perfect source of random
numbers.
The following code shows how to shuffle the numbers from 0 to 51,
@example
int 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 taken
randomly from the @var{n} elements of the array
@var{src}[0..@var{n}-1]. The objects are each of size @var{size}. The
output of the random number generator @var{r} is used to make the
selection. The algorithm ensures all possible samples are equally
likely, assuming a perfect source of randomness.
The objects are sampled @emph{without} replacement, thus each object can
only appear once in @var{dest}[k]. It is required that @var{k} be less
than or equal to @code{n}. The objects in @var{dest} will be in the
same relative order as those in @
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -