Math::...andist(3pm)
π Math::...andist(3pm) β User Contributed Perl Documentation π
okay bestie, gather round. This page is filed as Math::...andist(3pm) under User Contributed Perl Documentation, and the module it's actually spilling tea about is Math::GSL::Randist. It's giving probability distributions, no cap, and honestly? iconic.
π NAME π
Math::GSL::Randistβ Probability Distributions.
β¨ SYNOPSIS β¨
Bestie, here's the vibe in code form, and yes, it is exact:
use Math::GSL::RNG;
use Math::GSL::Randist qw/:all/;
my $rng = Math::GSL::RNG->new();
my $coinflip = gsl_ran_bernoulli($rng->raw(), .5);
π DESCRIPTION π
Here is the whole list of functions chillin' in this module. For all the sampling methods, that first argument $r is a raw gsl_rnd structure you retrieve by calling raw() on an Math::GSL::RNG object. Periodt.
π Bernoulli π
gsl_ran_bernoulli($r, $p)β returns either0or1, aka the result of a Bernoulli trial with probability$p. The probability distribution for a Bernoulli trial isp(0) = 1 - $pandp(1) = $p.$ris agsl_rngstructure.gsl_ran_bernoulli_pdf($k, $p)β computes the probabilityp($k)of obtaining$kfrom a Bernoulli distribution with probability parameter$p, using the formula given above.
π Beta π
gsl_ran_beta($r, $a, $b)β returns a random variate from the beta distribution. The distribution function is,p($x) dx = {Gamma($a+$b) \ Gamma($a) Gamma($b)} $x**{$a-1} (1-$x)**{$b-1} dxfor0 <= $x <= 1.$ris agsl_rngstructure.gsl_ran_beta_pdf($x, $a, $b)β computes the probability densityp($x)at$xfor a beta distribution with parameters$aand$b, using the formula given above.
π¦ Binomial π¦
gsl_ran_binomial($k, $p, $n)β returns a random integer from the binomial distribution, the number of successes in n independent trials with probability$p. The probability distribution for binomial variates isp($k) = {$n! \ $k! ($n-$k)! } $p**$k (1-$p)^{$n-$k}for0 <= $k <= $n. Uses Binomial Triangle Parallelogram Exponential algorithm.gsl_ran_binomial_knuth($k, $p, $n)β alternative and original implementation forgsl_ran_binomialusing Knuth's algorithm.gsl_ran_binomial_tpe($k, $p, $n)β same asgsl_ran_binomial.gsl_ran_binomial_pdf($k, $p, $n)β computes the probabilityp($k)of obtaining$kfrom a binomial distribution with parameters$pand$n, using the formula given above.
πΈ Exponential πΈ
gsl_ran_exponential($r, $mu)β returns a random variate from the exponential distribution with mean$mu. The distribution is,p($x) dx = {1 \ $mu} exp(-$x/$mu) dxfor$x >= 0.$ris agsl_rngstructure.gsl_ran_exponential_pdf($x, $mu)β computes the probability densityp($x)at$xfor an exponential distribution with mean$mu, using the formula given above.
π Exponential Power π
gsl_ran_exppow($r, $a, $b)β returns a random variate from the exponential power distribution with scale parameter$aand exponent$b. The distribution is,p(x) dx = {1 / 2 $a Gamma(1+1/$b)} exp(-|$x/$a|**$b) dxfor$x >= 0. For$b = 1this reduces to the Laplace distribution. For$b = 2it has the same form as a gaussian distribution, but with$a = sqrt(2) sigma.$ris agsl_rngstructure.gsl_ran_exppow_pdf($x, $a, $b)β computes the probability densityp($x)at$xfor an exponential power distribution with scale parameter$aand exponent$b, using the formula given above.
π Cauchy π
gsl_ran_cauchy($r, $scale)β returns a random variate from the Cauchy distribution with$scale. The probability distribution for Cauchy random variates is,
p(x) dx = {1 / $scale pi (1 + (x/$$scale)**2) } dx
for x in the range -infinity to +infinity. The Cauchy distribution is also known as the Lorentz distribution. $r is a gsl_rng structure.
gsl_ran_cauchy_pdf($x, $scale)β computes the probability densityp($x)at$xfor a Cauchy distribution with$scale, using the formula given above.
π Chi-Squared π
gsl_ran_chisq($r, $nu)β returns a random variate from the chi-squared distribution with$nudegrees of freedom. The distribution function is,p(x) dx = {1 / 2 Gamma($nu/2) } (x/2)**{$nu/2 - 1} exp(-x/2) dxfor$x >= 0.$ris agsl_rngstructure.gsl_ran_chisq_pdf($x, $nu)β computes the probability densityp($x)at$xfor a chi-squared distribution with$nudegrees of freedom, using the formula given above.
π«Ά Dirichlet π«Ά
gsl_ran_dirichlet($r, $alpha)β returns an array of K (where K = length of$alphaarray) random variates from a Dirichlet distribution of order K-1. The distribution function is
p(\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
for theta_i >= 0 and alpha_i > 0. The delta function ensures that \sum \theta_i = 1. The normalization factor Z is
Z = {\prod_{i=1}^K \Gamma(\alpha_i)} / {\Gamma( \sum_{i=1}^K \alpha_i)}
The random variates are generated by sampling K values from gamma distributions with parameters a=alpha_i, b=1, and renormalizing. See A.M. Law, W.D. Kelton, Simulation Modeling and Analysis (1991).
gsl_ran_dirichlet_pdf($theta, $alpha)β computes the probability densityp(\theta_1, ... , \theta_K)at theta[K] for a Dirichlet distribution with parameters alpha[K], using the formula given above.$alphaand$thetashould be array references of the same size. Theta should be normalized to sum to 1.gsl_ran_dirichlet_lnpdf($theta, $alpha)β computes the logarithm of the probability densityp(\theta_1, ... , \theta_K)for a Dirichlet distribution with parameters alpha[K].$alphaand$thetashould be array references of the same size. Theta should be normalized to sum to 1.
π Erlang π
gsl_ran_erlang($r, $scale, $shape)β Equivalent togsl_ran_gamma($r, $shape, $scale)where$shapeis an integer.gsl_ran_erlang_pdfβ Equivalent togsl_ran_gamma_pdf($r, $shape, $scale)where$shapeis an integer.
π₯ F-distribution π₯
gsl_ran_fdist($r, $nu1, $nu2)β returns a random variate from the F-distribution with degrees of freedom nu1 and nu2. The distribution function is,p(x) dx = { Gamma(($nu_1 + $nu_2)/2) / Gamma($nu_1/2) Gamma($nu_2/2) } $nu_1**{$nu_1/2} $nu_2**{$nu_2/2} x**{$nu_1/2 - 1} ($nu_2 + $nu_1 x)**{-$nu_1/2 -$nu_2/2}for$x >= 0.$ris agsl_rngstructure.gsl_ran_fdist_pdf($x, $nu1, $nu2)β computes the probability density p(x) at x for an F-distribution with nu1 and nu2 degrees of freedom, using the formula given above.
β¨ Uniform/Flat distribution β¨
gsl_ran_flat($r, $a, $b)β returns a random variate from the flat (uniform) distribution from a to b. The distribution is,p(x) dx = {1 / ($b-$a)} dxif$a <= x < $band 0 otherwise.$ris agsl_rngstructure.gsl_ran_flat_pdf($x, $a, $b)β computes the probability densityp($x)at$xfor a uniform distribution from$ato$b, using the formula given above.
π Gamma π
gsl_ran_gamma($r, $shape, $scale)β returns a random variate from the gamma distribution. The distribution function is,p(x) dx = {1 \over \Gamma($shape) $scale^$shape} x^{$shape-1} e^{-x/$scale} dxfor x > 0. Uses Marsaglia-Tsang method. Can also be called asgsl_ran_gamma_mt.gsl_ran_gamma_pdf($x, $shape, $scale)β computes the probability densityp($x)at$xfor a gamma distribution with parameters$shapeand$scale, using the formula given above.gsl_ran_gamma($r, $shape, $scale)β same asgsl_ran_gamma.gsl_ran_gamma_knuth($r, $shape, $scale)β alternative implementation forgsl_ran_gamma, using algorithm in Knuth volume 2.
π§ Gaussian/Normal π§
gsl_ran_gaussian($r, $sigma)β returns a Gaussian random variate, with mean zero and standard deviation$sigma. The probability distribution for Gaussian random variates is,p(x) dx = {1 / sqrt{2 pi $sigma**2}} exp(-x**2 / 2 $sigma**2) dxfor x in the range -infinity to +infinity.$ris agsl_rngstructure. Uses Box-Mueller (polar) method.gsl_ran_gaussian_ratio_method($r, $sigma)β computes a Gaussian random variate using the alternative Kinderman-Monahan-Leva ratio method.gsl_ran_gaussian_ziggurat($r, $sigma)β computes a Gaussian random variate using the alternative Marsaglia-Tsang ziggurat ratio method. The Ziggurat algorithm is the fastest available algorithm in most cases.$ris agsl_rngstructure.gsl_ran_gaussian_pdf($x, $sigma)β computes the probability densityp($x)at$xfor a Gaussian distribution with standard deviation sigma, using the formula given above.gsl_ran_ugaussian($r)gsl_ran_ugaussian_ratio_method($r)gsl_ran_ugaussian_pdf($x)β This function computes results for the unit Gaussian distribution. It is equivalent to the gaussian functions above with a standard deviation of one,sigma = 1.gsl_ran_bivariate_gaussian($r, $sigma_x, $sigma_y, $rho)β generates a pair of correlated Gaussian variates, with mean zero, correlation coefficient rho and standard deviations$sigma_xand$sigma_yin the x and y directions. The first value returned is x and the second y. The probability distribution for bivariate Gaussian random variates is,p(x,y) dx dy = {1 / 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 dyfor x,y in the range -infinity to +infinity. The correlation coefficient$rhoshould lie between 1 and -1.$ris agsl_rngstructure.gsl_ran_bivariate_gaussian_pdf($x, $y, $sigma_x, $sigma_y, $rho)β computes the probability densityp($x,$y)at($x,$y)for a bivariate Gaussian distribution with standard deviations$sigma_x,$sigma_yand correlation coefficient$rho, using the formula given above.
πΈ Gaussian Tail πΈ
gsl_ran_gaussian_tail($r, $a, $sigma)β provides random variates from the upper tail of a Gaussian distribution with standard deviation sigma. The values returned are larger than the lower limit a, which must be positive. The probability distribution for Gaussian tail random variates is,p(x) dx = {1 / N($a; $sigma) sqrt{2 pi sigma**2}} exp(- x**2/(2 sigma**2)) dxfor x >$awhereN($a; $sigma)is the normalization constant,N($a; $sigma) = (1/2) erfc($a / sqrt(2 $sigma**2)).$ris agsl_rngstructure.gsl_ran_gaussian_tail_pdf($x, $a, $gaussian)β bestie this one hands u the probability densityp($x)at$xfor a Gaussian tail distribution with standard deviationsigmaand lower limit$a, straight up using the formula given above. no new math, just vibes π«gsl_ran_ugaussian_tail($r, $a)β same energy but for the tail of a unit Gaussian distribution π it's literally equivalent to the functions above with$sigma = 1. and yeah,$ris agsl_rngstructure, we been knew.gsl_ran_ugaussian_tail_pdf($x, $a)β the pdf twin of the above β¨ still the tail of a unit Gaussian, still$sigma = 1, no cap.
πΈ Landau
gsl_ran_landau($r)β returns a random variate from the Landau distribution, and the way this distribution is defined?? analytically, by a whole complex integral, it's giving main character:
p(x) = (1/(2 \pi i)) \int_{c-i\infty}^{c+i\infty} ds exp(s log(s) + x s)
but for numerical purposes it's way more convenient to use this equivalent form of the integral instead:
p(x) = (1/\pi) \int_0^\infty dt \exp(-t \log(t) - x t) \sin(\pi t)
$r is a gsl_rng structure π¦
gsl_ran_landau_pdf($x)β computes the probability densityp($x)at$xfor the Landau distribution, using an approximation to the formula given above. approximation!! she's doing her best π
π² Geometric
gsl_ran_geometric($r, $p)β returns a random integer from the geometric distribution: the number of independent trials with probability$puntil the first success. the probability distribution for geometric variates is:
p(k) = p (1-$p)^(k-1) for k >= 1
so like, heads up β this definition starts at k=1. there's another convention out there where the exponent k-1 gets replaced by k, so don't get it twisted π $r is a gsl_rng structure.
gsl_ran_geometric_pdf($k, $p)β computes the probabilityp($k)of obtaining$kfrom a geometric distribution with probability parameterp, using the formula given above πΈ
π§Ί Hypergeometric
gsl_ran_hypergeometric($r, $n1, $n2, $t)β returns a random integer from the hypergeometric distribution π«Ά and the probability distribution for hypergeometric random variates is:
p(k) = C(n_1, k) C(n_2, t - k) / C(n_1 + n_2, t)
where
C(a,b) = a!/(b!(a-b)!)
and t <= n_1 + n_2. the domain of k is max(0,t-n_2), ..., min(t,n_1). so picture it: a population with n_1 elements of "type 1" and n_2 elements of "type 2" β the hypergeometric distribution gives u the probability of obtaining k elements of "type 1" in t samples from the population without replacement. it's giving sampling drama π $r is a gsl_rng structure.
gsl_ran_hypergeometric_pdf($k, $n1, $n2, $t)β computes the probabilityp(k)of obtainingkfrom a hypergeometric distribution with parameters$n1,$n2,$t, using the formula given above β¨
π Gumbel
gsl_ran_gumbel1($r, $a, $b)β returns a random variate from the Type-1 Gumbel distribution. the Type-1 Gumbel distribution function is:
p(x) dx = a b \exp(-(b \exp(-ax) + ax)) dx
for -\infty < x < \infty. $r is a gsl_rng structure π
gsl_ran_gumbel1_pdf($x, $a, $b)β computes the probability densityp($x)at$xfor a Type-1 Gumbel distribution with parameters$aand$b, using the formula given above πgsl_ran_gumbel2($r, $a, $b)β returns a random variate from the Type-2 Gumbel distribution, yes there's a sequel π the Type-2 Gumbel distribution function is:
p(x) dx = a b x^{-a-1} \exp(-b x^{-a}) dx
for 0 < x < \infty. $r is a gsl_rng structure πΈ
gsl_ran_gumbel2_pdf($x, $a, $b)β computes the probability densityp($x)at$xfor a Type-2 Gumbel distribution with parameters$aand$b, using the formula given above β
π Logistic
gsl_ran_logistic($r, $a)β returns a random variate from the logistic distribution. the distribution function is:
p(x) dx = { \exp(-x/a) \over a (1 + \exp(-x/a))^2 } dx
for -\infty < x < +\infty. $r is a gsl_rng structure π¦
gsl_ran_logistic_pdf($x, $a)β computes the probability densityp($x)at$xfor a logistic distribution with scale parameter$a, using the formula given above π
π Lognormal
gsl_ran_lognormal($r, $zeta, $sigma)β returns a random variate from the lognormal distribution. distribution function, coming right up:
p(x) dx = {1 \over x \sqrt{2 \pi \sigma^2} } \exp(-(\ln(x) - \zeta)^2/2 \sigma^2) dx
for x > 0. $r is a gsl_rng structure β¨
gsl_ran_lognormal_pdf($x, $zeta, $sigma)β computes the probability densityp($x)at$xfor a lognormal distribution with parameters$zetaand$sigma, using the formula given above π
πͺ΅ Logarithmic
gsl_ran_logarithmic($r, $p)β returns a random integer from the logarithmic distribution. the probability distribution for logarithmic random variates is:
p(k) = {-1 \over \log(1-p)} {(p^k \over k)} for k >= 1
$r is a gsl_rng structure π
gsl_ran_logarithmic_pdf($k, $p)β computes the probabilityp($k)of obtaining$kfrom a logarithmic distribution with probability parameter$p, using the formula given above πΈ
π± Multinomial
gsl_ran_multinomial($r, $P, $N)β computes and returns a random samplen[]from the multinomial distribution formed byNtrials from an underlying distributionp[K]. the distribution function forn[]is:
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
where (n_1, n_2, ..., n_K) are nonnegative integers with sum_{k=1}^K n_k = N, and (p_1, p_2, ..., p_K) is a probability distribution with \sum p_i = 1. and listen π if the array p[K] is not normalized, its entries get treated as weights and normalized appropriately. she adapts, she's flexible.
random variates are generated using the conditional binomial method (see C.S. Davis, The computer generation of multinomial random variates, Comp. Stat. Data Anal. 16 (1993) 205-217 for details) β citations?? we love a receipts moment π
gsl_ran_multinomial_pdf($counts, $P)β returns the probability for the multinomial distributionP(counts[1], counts[2], ..., counts[K])with parametersp[K]π«Άgsl_ran_multinomial_lnpdf($counts, $P)β returns the logarithm of the probability for the multinomial distributionP(counts[1], counts[2], ..., counts[K])with parametersp[K]. it's the log edition, iykyk π₯
β Negative Binomial
gsl_ran_negative_binomial($r, $p, $n)β returns a random integer from the negative binomial distribution: the number of failures occurring beforensuccesses in independent trials with probabilitypof success. probability distribution for negative binomial variates:
p(k) = {\Gamma(n + k) \over \Gamma(k+1) \Gamma(n) } p^n (1-p)^k
and important!! note that n is not required to be an integer π«
gsl_ran_negative_binomial_pdf($k, $p, $n)β computes the probabilityp($k)of obtaining$kfrom a negative binomial distribution with parameters$pand$n, using the formula given above π
π° Pascal
gsl_ran_pascal($r, $p, $n)β returns a random integer from the Pascal distribution. plot twist: the Pascal distribution is simply a negative binomial distribution with an integer value of$nπ so:
p($k) = {($n + $k - 1)! \ $k! ($n - 1)! } $p**$n (1-$p)**$k for $k >= 0
$r is gsl_rng structure π
gsl_ran_pascal_pdf($k, $p, $n)β computes the probabilityp($k)of obtaining$kfrom a Pascal distribution with parameters$pand$n, using the formula given above π
π° Pareto
gsl_ran_pareto($r, $a, $b)β returns a random variate from the Pareto distribution of order$a. the distribution function is:
p($x) dx = ($a/$b) / ($x/$b)^{$a+1} dx for $x >= $b
$r is a gsl_rng structure β
gsl_ran_pareto_pdf($x, $a, $b)β computes the probability densityp(x)atxfor a Pareto distribution with exponentaand scaleb, using the formula given above β¨
πΈ Poisson
gsl_ran_poisson($r, $lambda)β returns a random integer from the Poisson distribution with mean$lambda.$ris agsl_rngstructure. the probability distribution for Poisson variates is:
p(k) = {$lambda**$k \ $k!} exp(-$lambda)
for $k >= 0. and yeah, $r is a gsl_rng structure β said it twice bc it's that important bestie π
gsl_ran_poisson_pdf($k, $lambda)β computes the probabilityp($k)of obtaining$kfrom a Poisson distribution with mean$lambda, using the formula given above π
βοΈ Rayleigh
gsl_ran_rayleigh($r, $sigma)β returns a random variate from the Rayleigh distribution with scale parametersigma. the distribution is:
p(x) dx = {x \over \sigma^2} \exp(- x^2/(2 \sigma^2)) dx for x > 0
$r is a gsl_rng structure π¦
gsl_ran_rayleigh_pdf($x, $sigma)β computes the probability densityp($x)at$xfor a Rayleigh distribution with scale parametersigma, using the formula given above πgsl_ran_rayleigh_tail($r, $a, $sigma)β returns a random variate from the tail of the Rayleigh distribution with scale parameter$sigmaand a lower limit of$a. the distribution is:
p(x) dx = {x \over \sigma^2} \exp ((a^2 - x^2) /(2 \sigma^2)) dx for x > a
$r is a gsl_rng structure πΈ
gsl_ran_rayleigh_tail_pdf($x, $a, $sigma)β computes the probability densityp($x)at$xfor a Rayleigh tail distribution with scale parameter$sigmaand lower limit$a, using the formula given above π«
π Student-t
gsl_ran_tdist($r, $nu)β returns a random variate from the t-distribution. the distribution function is:
p(x) dx = {\Gamma((\nu + 1)/2) \over \sqrt{\pi \nu} \Gamma(\nu/2)} (1 + x^2/\nu)^{-(\nu + 1)/2} dx
for -\infty < x < +\infty β¨
gsl_ran_tdist_pdf($x, $nu)β computes the probability densityp($x)at$xfor a t-distribution withnudegrees of freedom, using the formula given above π«Ά
π«§ Laplace
gsl_ran_laplace($r, $a)β returns a random variate from the Laplace distribution with width$a. the distribution is:
p(x) dx = {1 \over 2 a} \exp(-|x/a|) dx
for -\infty < x < \infty π
gsl_ran_laplace_pdf($x, $a)β computes the probability densityp($x)at$xfor a Laplace distribution with width$a, using the formula given above π
π Levy (the chaotic one, we stan)
gsl_ran_levy($r, $c, $alpha)β hands you a random variate from the Levy symmetric stable distribution, with scale$cand exponent$alpha. The symmetric stable probability distribution is defined by a fourier transform:
p(x) = {1 \over 2 \pi} \int_{-\infty}^{+\infty} dt \exp(-it x - |c t|^alpha)
There is no explicit solution for the form of p(x) and the library does not define a corresponding pdf function. Okay so, the glow-ups: for \alpha = 1 the distribution reduces to the Cauchy distribution. For \alpha = 2 it is a Gaussian distribution with \sigma = \sqrt{2} c. And for \alpha < 1 the tails of the distribution become extremely wide (like, alarmingly wide bestie). The algorithm only works for 0 < alpha <= 2. $r is a gsl_rng structure.
gsl_ran_levy_skew($r, $c, $alpha, $beta)β random variate from the Levy skew stable distribution with scale$c, exponent$alphaand skewness parameter$beta. The skewness parameter must lie in the range[-1,1]. The Levy skew stable probability distribution is defined by a fourier transform:
p(x) = {1 \over 2 \pi} \int_{-\infty}^{+\infty} dt \exp(-it x - |c t|^alpha (1-i beta sign(t) tan(pi alpha/2)))
When \alpha = 1 the term \tan(\pi \alpha/2) is replaced by -(2/\pi)\log|t|. There is no explicit solution for the form of p(x) and the library does not define a corresponding pdf function. When $alpha = 2 the distribution reduces to a Gaussian distribution with $sigma = sqrt(2) $c, and the skewness parameter has no effect. When $alpha < 1 the tails of the distribution become extremely wide. The symmetric distribution corresponds to $beta = 0. The algorithm only works for 0 < $alpha <= 2.
Also iconic: the Levy alpha-stable distributions have the property that if N alpha-stable variates are drawn from the distribution p(c, \alpha, \beta) then the sum Y = X_1 + X_2 + \dots + X_N will also be distributed as an alpha-stable variate, p(N^(1/\alpha) c, \alpha, \beta). $r is a gsl_rng structure.
πΎ Weibull
gsl_ran_weibull($r, $scale, $exponent)β random variate from the Weibull distribution with$scaleand$exponent(aka scale, yes it really does say that twice, that's the doc's business not mine π«Ά). The distribution function is:
p(x) dx = {$exponent \over $scale^$exponent} x^{$exponent-1}
\exp(-(x/$scale)^$exponent) dx
for x >= 0. $r is a gsl_rng structure.
gsl_ran_weibull_pdf($x, $scale, $exponent)β computes the probability densityp($x)at$xfor a Weibull distribution with$scaleand$exponent, using the formula given just above. Same math, now as a density. Slay.
π¦ Spherical Vector
gsl_ran_dir_2d($r)β returns two values. The first is$xand the second is$yof a random direction vectorv = ($x,$y)in two dimensions. The vector is normalized such that|v|^2 = $x^2 + $y^2 = 1.$ris a gsl_rng structure.gsl_ran_dir_2d_trig_method($r)β returns two values. The first is$xand the second is$yof a random direction vectorv = ($x,$y)in two dimensions. The vector is normalized such that|v|^2 = $x^2 + $y^2 = 1.$ris a gsl_rng structure. (Yes bestie, it's the same description β the trig method is just a different way of getting there. π)gsl_ran_dir_3d($r)β returns three values. The first is$x, the second$yand the third$zof a random direction vectorv = ($x,$y,$z)in three dimensions. The vector is normalized such that|v|^2 = x^2 + y^2 + z^2 = 1. The method employed is due to Robert E. Knop (CACM 13, 326 (1970)), and explained in Knuth, v2, 3rd ed, p136. It uses the surprising fact that the distribution projected along any axis is actually uniform β and that's only true for 3 dimensions. Main character dimension fr. πgsl_ran_dir_nd(Not yet implemented) β this function returns a random direction vectorv = (x_1,x_2,...,x_n)in n dimensions. The vector is normalized such that
|v|^2 = x_1^2 + x_2^2 + ... + x_n^2 = 1.
The method uses the fact that a multivariate Gaussian distribution is spherically symmetric. Each component is generated to have a Gaussian distribution, and then the components are normalized. The method is described by Knuth, v2, 3rd ed, p135-136, and attributed to G. W. Brown, Modern Mathematics for the Engineer (1956).
Heads up: it's literally marked not yet implemented, so don't come for me when it doesn't go. π
π Shuffling and Sampling
gsl_ran_shuffleβ please use theshufflemethod in the GSL::RNG module OO interface. That's the vibe now, bestie.gsl_ran_chooseβ please use thechoosemethod in the GSL::RNG module OO interface.gsl_ran_sampleβ please use thesamplemethod in the GSL::RNG module OO interface.gsl_ran_discrete_preproc/gsl_ran_discrete($r, $g)β aftergsl_ran_discrete_preprochas been called, you use this function to get the discrete random numbers.$ris a gsl_rng structure and$gis a gsl_ran_discrete structure.gsl_ran_discrete_pdf($k, $g)β returns the probabilityP[$k]of observing the variable$k. SinceP[$k]is not stored as part of the lookup table, it must be recomputed; this computation takesO(K), so ifKis large and you care about the original arrayP[$k]used to create the lookup table, then you should just keep this original arrayP[$k]around.$ris a gsl_rng structure and$gis a gsl_ran_discrete structure.gsl_ran_discrete_free($g)β de-allocates the gsl_ran_discrete pointed to byg.
You have to add the functions you want to use inside the qw /put_function_here /.
You can also write use Math::GSL::Randist qw/:all/; to use all available functions of the module.
Other tags are also available, here is a complete list of all tags for this module:
logarithmicchooseexponentialgumbel1exppowsamplelogisticgaussianpoissonbinomialfdistchisqgammahypergeometricdirichletnegativeflatgeometricdiscretetdistugaussianrayleighdirpascalgumbel2shufflelandaubernoulliweibullmultinomialbetalognormallaplaceerlangcauchylevybivariatepareto
For example the beta tag contains theses functions : gsl_ran_beta, gsl_ran_beta_pdf.
For more information on the functions, we refer you to the GSL official documentation: <http://www.gnu.org/software/gsl/manual/html_node/>
You might also want to write
use Math::GSL::RNG qw/:all/;
since a lot of the functions of Math::GSL::Randist take as argument a structure that is created by Math::GSL::RNG. Refer to Math::GSL::RNG documentation to see how to create such a structure.
Math::GSL::CDF also contains a structure named gsl_ran_discrete_t. An example is given in the EXAMPLES part on how to use the function related to this structure.
π EXAMPLES π
use Math::GSL::Randist qw/:all/;
print gsl_ran_exponential_pdf(5,2) . "\n";
use Math::GSL::Randist qw/:all/;
my $x = Math::GSL::gsl_ran_discrete_t::new;
π AUTHORS π
Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
And that's a wrap on part 3, bestie!! π This whole thing isperl v5.42.3, dated2026-08-20, and it's theMath::...andist(3pm)page from the User Contributed Perl Documentation crew. Go forth and generate them random variates. Periodt. π β¨
π¦ where this page comes from
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms