4 void gsl_ran_dir_2d
(const gsl_rng
* r
, double
*OUTPUT, double
*OUTPUT);
5 void gsl_ran_dir_2d_trig_method
(const gsl_rng
* r
, double
*OUTPUT, double
*OUTPUT);
6 void gsl_ran_dir_3d
(const gsl_rng
* r
, double
*OUTPUT, double
*OUTPUT, double
*OUTPUT);
15 croak
("Argument $argnum is not a reference.");
16 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
17 croak
("Argument $argnum is not an array.");
19 tempav
= (AV
*)SvRV
($input
);
21 $
1 = (int
**) malloc
((len
+2)*sizeof
(int
*));
22 for
(i
= 0; i
<= len
; i
++) {
23 tv
= av_fetch
(tempav
, i
, 0);
25 memset
((int
*)($
1+i
), x
, 1);
26 //printf
("curr = %d\n", (int
)($
1+i
) );
29 %typemap
(freearg
) void
* {
34 #include
"/usr/local/include/gsl/gsl_randist.h"
36 %include
"/usr/local/include/gsl/gsl_randist.h"
40 our @EXPORT_OK
= qw
/gsl_ran_bernoulli gsl_ran_bernoulli_pdf gsl_ran_beta
41 gsl_ran_beta_pdf gsl_ran_binomial gsl_ran_binomial_knuth
42 gsl_ran_binomial_tpe gsl_ran_binomial_pdf gsl_ran_exponential
43 gsl_ran_exponential_pdf gsl_ran_exppow gsl_ran_exppow_pdf
44 gsl_ran_cauchy gsl_ran_cauchy_pdf gsl_ran_chisq
45 gsl_ran_chisq_pdf gsl_ran_dirichlet gsl_ran_dirichlet_pdf
46 gsl_ran_dirichlet_lnpdf gsl_ran_erlang gsl_ran_erlang_pdf
47 gsl_ran_fdist gsl_ran_fdist_pdf gsl_ran_flat
48 gsl_ran_flat_pdf gsl_ran_gamma gsl_ran_gamma_int
49 gsl_ran_gamma_pdf gsl_ran_gamma_mt gsl_ran_gamma_knuth
50 gsl_ran_gaussian gsl_ran_gaussian_ratio_method gsl_ran_gaussian_ziggurat
51 gsl_ran_gaussian_pdf gsl_ran_ugaussian gsl_ran_ugaussian_ratio_method
52 gsl_ran_ugaussian_pdf gsl_ran_gaussian_tail gsl_ran_gaussian_tail_pdf
53 gsl_ran_ugaussian_tail gsl_ran_ugaussian_tail_pdf gsl_ran_bivariate_gaussian
54 gsl_ran_bivariate_gaussian_pdf gsl_ran_landau gsl_ran_landau_pdf
55 gsl_ran_geometric gsl_ran_geometric_pdf gsl_ran_hypergeometric
56 gsl_ran_hypergeometric_pdf gsl_ran_gumbel1 gsl_ran_gumbel1_pdf
57 gsl_ran_gumbel2 gsl_ran_gumbel2_pdf gsl_ran_logistic
58 gsl_ran_logistic_pdf gsl_ran_lognormal gsl_ran_lognormal_pdf
59 gsl_ran_logarithmic gsl_ran_logarithmic_pdf gsl_ran_multinomial
60 gsl_ran_multinomial_pdf gsl_ran_multinomial_lnpdf
61 gsl_ran_negative_binomial gsl_ran_negative_binomial_pdf gsl_ran_pascal
62 gsl_ran_pascal_pdf gsl_ran_pareto gsl_ran_pareto_pdf
63 gsl_ran_poisson gsl_ran_poisson_array
64 gsl_ran_poisson_pdf gsl_ran_rayleigh gsl_ran_rayleigh_pdf
65 gsl_ran_rayleigh_tail gsl_ran_rayleigh_tail_pdf gsl_ran_tdist
66 gsl_ran_tdist_pdf gsl_ran_laplace gsl_ran_laplace_pdf
67 gsl_ran_levy gsl_ran_levy_skew gsl_ran_weibull
68 gsl_ran_weibull_pdf gsl_ran_dir_2d gsl_ran_dir_2d_trig_method
69 gsl_ran_dir_3d gsl_ran_dir_nd gsl_ran_shuffle
70 gsl_ran_choose gsl_ran_sample
71 gsl_ran_discrete_t gsl_ran_discrete_free gsl_ran_discrete_preproc
72 gsl_ran_discrete gsl_ran_discrete_pdf
76 all
=> [ @EXPORT_OK
],
77 logarithmic
=> [ gsl_ran_logarithmic
, gsl_ran_logarithmic_pdf
],
78 choose
=> [ gsl_ran_choose
],
79 exponential
=> [ gsl_ran_exponential
, gsl_ran_exponential_pdf
],
80 gumbel1
=> [ gsl_ran_gumbel1
, gsl_ran_gumbel1_pdf
],
81 exppow
=> [ gsl_ran_exppow
, gsl_ran_exppow_pdf
],
82 sample
=> [ gsl_ran_sample
],
83 logistic
=> [ gsl_ran_logistic
, gsl_ran_logistic_pdf
],
85 gsl_ran_gaussian
, gsl_ran_gaussian_ratio_method
, gsl_ran_gaussian_ziggurat
,
86 gsl_ran_gaussian_pdf
, gsl_ran_gaussian_tail
, gsl_ran_gaussian_tail_pdf
88 poisson
=> [ gsl_ran_poisson
, gsl_ran_poisson_array
, gsl_ran_poisson_pdf
],
89 binomial
=> [ gsl_ran_binomial
, gsl_ran_binomial_knuth
, gsl_ran_binomial_tpe
,
90 gsl_ran_binomial_pdf
],
91 fdist
=> [ gsl_ran_fdist
, gsl_ran_fdist_pdf
],
92 chisq
=> [ gsl_ran_chisq
, gsl_ran_chisq_pdf
],
93 gamma
=> [ gsl_ran_gamma
, gsl_ran_gamma_int
, gsl_ran_gamma_pdf
, gsl_ran_gamma_mt
, gsl_ran_gamma_knuth
],
94 hypergeometric
=> [ gsl_ran_hypergeometric
, gsl_ran_hypergeometric_pdf
],
95 dirichlet
=> [ gsl_ran_dirichlet
, gsl_ran_dirichlet_pdf
, gsl_ran_dirichlet_lnpdf
],
96 negative
=> [ gsl_ran_negative_binomial
, gsl_ran_negative_binomial_pdf
],
97 flat
=> [ gsl_ran_flat
, gsl_ran_flat_pdf
],
98 geometric
=> [ gsl_ran_geometric
, gsl_ran_geometric_pdf
],
99 discrete
=> [ gsl_ran_discrete
, gsl_ran_discrete_pdf
],
100 tdist
=> [ gsl_ran_tdist
, gsl_ran_tdist_pdf
],
101 ugaussian
=> [ gsl_ran_ugaussian
, gsl_ran_ugaussian_ratio_method
, gsl_ran_ugaussian_pdf
,
102 gsl_ran_ugaussian_tail
, gsl_ran_ugaussian_tail_pdf
],
103 rayleigh
=> [ gsl_ran_rayleigh
, gsl_ran_rayleigh_pdf
, gsl_ran_rayleigh_tail
,
104 gsl_ran_rayleigh_tail_pdf
],
105 dir
=> [ gsl_ran_dir_2d
, gsl_ran_dir_2d_trig_method
, gsl_ran_dir_3d
, gsl_ran_dir_nd
],
106 pascal
=> [ gsl_ran_pascal
, gsl_ran_pascal_pdf
],
107 gumbel2
=> [ gsl_ran_gumbel2
, gsl_ran_gumbel2_pdf
],
108 shuffle
=> [ gsl_ran_shuffle
],
109 landau
=> [ gsl_ran_landau
, gsl_ran_landau_pdf
],
110 bernoulli
=> [ gsl_ran_bernoulli
, gsl_ran_bernoulli_pdf
],
111 weibull
=> [ gsl_ran_weibull
, gsl_ran_weibull_pdf
],
112 multinomial
=> [ gsl_ran_multinomial
, gsl_ran_multinomial_pdf
, gsl_ran_multinomial_lnpdf
],
113 beta
=> [ gsl_ran_beta
, gsl_ran_beta_pdf
],
114 lognormal
=> [ gsl_ran_lognormal
, gsl_ran_lognormal_pdf
],
115 laplace
=> [ gsl_ran_laplace
, gsl_ran_laplace_pdf
],
116 erlang
=> [ gsl_ran_erlang
, gsl_ran_erlang_pdf
],
117 cauchy
=> [ gsl_ran_cauchy
, gsl_ran_cauchy_pdf
],
118 levy
=> [ gsl_ran_levy
, gsl_ran_levy_skew
],
119 bivariate
=> [ gsl_ran_bivariate_gaussian
, gsl_ran_bivariate_gaussian_pdf
],
120 pareto
=> [ gsl_ran_pareto
, gsl_ran_pareto_pdf
]
127 Math
::GSL
::Randist
- Probability Distributions
131 use Math
::GSL
::Randist qw
/:all
/;
135 Here is a list of all the functions included in this module
:
139 =item gsl_ran_bernoulli
($r
, $p
) - This function returns either
0 or
1, the result of a Bernoulli trial with probability $p. The probability distribution for a Bernoulli trial is
, p
(0) = 1 - $p and p
(1) = $p. $r is a gsl_rng structure.
141 =item gsl_ran_bernoulli_pdf
($k
, $p
) - This function computes the probability p
($k
) of obtaining $k from a Bernoulli distribution with probability parameter $p
, using the formula given above.
143 =item gsl_ran_beta
($r
, $a
, $b
) - This function 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
} dx for
0 <= $x
<= 1.$r is a gsl_rng structure.
145 =item gsl_ran_beta_pdf
($x
, $a
, $b
) - This function computes the probability density p
($x
) at $x for a beta distribution with parameters $a and $b
, using the formula given above.
147 =item gsl_ran_binomial
($k
, $p
, $n
) - This function 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 is p
($k
) = {$n
! \ $k
! ($n-$k
)! } $p
**$k
(1-$p
)^
{$n-$k
} for
0 <= $k
<= $n.
149 =item gsl_ran_binomial_knuth
151 =item gsl_ran_binomial_tpe
153 =item gsl_ran_binomial_pdf
($k
, $p
, $n
) - This function computes the probability p
($k
) of obtaining $k from a binomial distribution with parameters $p and $n
, using the formula given above.
155 =item gsl_ran_exponential
($r
, $mu
) - This function returns a random variate from the exponential distribution with mean $mu. The distribution is
, p
($x
) dx
= {1 \ $mu
} exp
(-$x
/$mu
) dx for $x
>= 0. $r is a gsl_rng structure.
157 =item gsl_ran_exponential_pdf
($x
, $mu
) - This function computes the probability density p
($x
) at $x for an exponential distribution with mean $mu
, using the formula given above.
159 =item gsl_ran_exppow
($r
, $a
, $b
) - This function returns a random variate from the exponential power distribution with scale parameter $a and exponent $b. The distribution is
, p
(x
) dx
= {1 / 2 $a Gamma
(1+1/$b
)} exp
(-|$x
/$a|
**$b
) dx for $x
>= 0. For $b
= 1 this reduces to the Laplace distribution. For $b
= 2 it has the same form as a gaussian distribution
, but with $a
= sqrt
(2) sigma. $r is a gsl_rng structure.
161 =item gsl_ran_exppow_pdf
($x
, $a
, $b
) - This function computes the probability density p
($x
) at $x for an exponential power distribution with scale parameter $a and exponent $b
, using the formula given above.
165 =item gsl_ran_cauchy_pdf
169 =item gsl_ran_chisq_pdf
171 =item gsl_ran_dirichlet
173 =item gsl_ran_dirichlet_pdf
175 =item gsl_ran_dirichlet_lnpdf
179 =item gsl_ran_erlang_pdf
183 =item gsl_ran_fdist_pdf
187 =item gsl_ran_flat_pdf
191 =item gsl_ran_gamma_int
193 =item gsl_ran_gamma_pdf
195 =item gsl_ran_gamma_mt
197 =item gsl_ran_gamma_knuth
199 =item gsl_ran_gaussian
201 =item gsl_ran_gaussian_ratio_method
203 =item gsl_ran_gaussian_ziggurat
205 =item gsl_ran_gaussian_pdf
207 =item gsl_ran_ugaussian
209 =item gsl_ran_ugaussian_ratio_method
211 =item gsl_ran_ugaussian_pdf
213 =item gsl_ran_gaussian_tail
215 =item gsl_ran_gaussian_tail_pdf
217 =item gsl_ran_ugaussian_tail
219 =item gsl_ran_ugaussian_tail_pdf
221 =item gsl_ran_bivariate_gaussian
223 =item gsl_ran_bivariate_gaussian_pdf
227 =item gsl_ran_landau_pdf
229 =item gsl_ran_geometric
231 =item gsl_ran_geometric_pdf
233 =item gsl_ran_hypergeometric
235 =item gsl_ran_hypergeometric_pdf
237 =item gsl_ran_gumbel1
239 =item gsl_ran_gumbel1_pdf
241 =item gsl_ran_gumbel2
243 =item gsl_ran_gumbel2_pdf
245 =item gsl_ran_logistic
247 =item gsl_ran_logistic_pdf
249 =item gsl_ran_lognormal
251 =item gsl_ran_lognormal_pdf
253 =item gsl_ran_logarithmic
255 =item gsl_ran_logarithmic_pdf
257 =item gsl_ran_multinomial
259 =item gsl_ran_multinomial_pdf
261 =item gsl_ran_multinomial_lnpdf
263 =item gsl_ran_negative_binomial
265 =item gsl_ran_negative_binomial_pdf
267 =item gsl_ran_pascal
($r
, $p
, $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 $n. p
($k
) = {($n
+ $k
- 1)! \ $k
! ($n
- 1)! } $p
**$n
(1-$p
)**$k for $k
>= 0. $r is gsl_rng structure
269 =item gsl_ran_pascal_pdf
($k
, $p
, $n
) - This function computes the probability p
($k
) of obtaining $k from a Pascal distribution with parameters $p and $n
, using the formula given above.
271 =item gsl_ran_pareto
($r
, $a
, $b
) - This function 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
273 =item gsl_ran_pareto_pdf
($x
, $a
, $b
) - This function computes the probability density p
(x
) at x for a Pareto distribution with exponent a and scale b
, using the formula given above.
275 =item gsl_ran_poisson
($r
, $mu
) -This function returns a random integer from the Poisson distribution with mean $mu. $r is a gsl_rng structure. The probability distribution for Poisson variates is
, p
(k
) = {$mu
**$k \ $k
!} exp
(-$mu
) for $k
>= 0.
277 =item gsl_ran_poisson_array
279 =item gsl_ran_poisson_pdf
($k
, $mu
)- This function computes the probability p
($k
) of obtaining $k from a Poisson distribution with mean $mu
, using the formula given above.
281 =item gsl_ran_rayleigh
283 =item gsl_ran_rayleigh_pdf
285 =item gsl_ran_rayleigh_tail
287 =item gsl_ran_rayleigh_tail_pdf
291 =item gsl_ran_tdist_pdf
293 =item gsl_ran_laplace
295 =item gsl_ran_laplace_pdf
299 =item gsl_ran_levy_skew
301 =item gsl_ran_weibull
303 =item gsl_ran_weibull_pdf
305 =item gsl_ran_dir_2d
($r
) - This function returns two values. The first is $x and the second is $y of a random direction vector v
= ($x
,$y
) in two dimensions. The vector is normalized such that |v|^
2 = $x^
2 + $y^
2 = 1.
307 =item gsl_ran_dir_2d_trig_method
($r
) - This function returns two values. The first is $x and the second is $y of a random direction vector v
= ($x
,$y
) in two dimensions. The vector is normalized such that |v|^
2 = $x^
2 + $y^
2 = 1.
313 =item gsl_ran_shuffle
319 =item gsl_ran_discrete_preproc
321 =item gsl_ran_discrete
($r
, $g
) - After gsl_ran_discrete_preproc has been called
, you use this function to get the discrete random numbers. $r is a gsl_rng structure and $g is a gsl_ran_discrete structure
322 =item gsl_ran_discrete_pdf
($k
, $g
) - Returns the probability P
[$k
] of observing the variable $k. Since P
[$k
] is not stored as part of the lookup table
, it must be recomputed
; this computation takes O
(K
), so if K is large and you care about the original array P
[$k
] used to create the lookup table
, then you should just keep this original array P
[$k
] around. $r is a gsl_rng structure and $g is a gsl_ran_discrete structure
324 =item gsl_ran_discrete_free
($g
) - De-allocates the gsl_ran_discrete pointed to by g.
328 You have to add the functions you want to use inside the qw
/put_funtion_here
/.
329 You can also write use Math
::GSL
::Randist qw
/:name_of_tag
/; to use all avaible functions of the module.
330 Other tags are also avaible
, here is a complete list of all tags for this module
:
412 For example the beta tag contains theses functions
: gsl_ran_beta
, gsl_ran_beta_pdf.
414 For more informations on the functions
, we refer you to the GSL offcial documentation
: http
://www.gnu.org
/software
/gsl
/manual
/html_node
/
415 Tip
: search on google
: site
:http
://www.gnu.org
/software
/gsl
/manual
/html_node
/ name_of_the_function_you_want
417 You might also want to write
418 use Math
::GSL
::RNG qw
/:all
/;
419 since a lot of the functions of Math
::GSL
::Randist take as argument a structure that is created by Math
::GSL
::RNG.
420 Refer to Math
::GSL
::RNG documentation to see how to create such a structure.
422 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.
427 use Math
::GSL
::Randist qw
/:all
/;
428 print gsl_ran_exponential_pdf
(5,2) .
"\n";
430 use Math
::GSL
::Randist qw
/:all
/;
431 $x
= Math
::GSL
::gsl_ran_discrete_t
::new
;
436 Jonathan Leto
<jonathan@leto.net
> and Thierry Moisan
<thierry.moisan@gmail.com
>
438 =head1 COPYRIGHT
AND LICENSE
440 Copyright
(C
) 2008 Jonathan Leto and Thierry Moisan
442 This program is free software
; you can redistribute it and
/or modify it
443 under the same terms as Perl itself.