~ubuntu-branches/ubuntu/trusty/gsl-ref-html/trusty

« back to all changes in this revision

Viewing changes to gsl-ref_19.html

  • Committer: Bazaar Package Importer
  • Author(s): Dirk Eddelbuettel
  • Date: 2006-04-12 19:46:32 UTC
  • mfrom: (1.3.1 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060412194632-c9lodpl075pv9si3
Tags: 1.8-1
* New upstream release 1.8
* As with previous releases, the sources were obtained from the FSF web 
  pages by means of a wget call (c.f. the debian/rules target 'upstream')

* debian/control: Standards-Version increased to 3.6.2
* debian/copyright: Updated FSF address
* debian/rules: Set DH_COMPAT=4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<HTML>
2
 
<HEAD>
3
 
<!-- This HTML file has been created by texi2html 1.54+ (gsl)
4
 
     from ../gsl-ref.texi -->
5
 
 
6
 
<TITLE>GNU Scientific Library -- Reference Manual - Random Number Distributions</TITLE>
7
 
<!-- <LINK rel="stylesheet" title="Default Style Sheet" href="/css/texinfo.css" type="text/css"> -->
8
 
<link href="gsl-ref_20.html" rel=Next>
9
 
<link href="gsl-ref_18.html" rel=Previous>
10
 
<link href="gsl-ref_toc.html" rel=ToC>
11
 
 
12
 
</HEAD>
13
 
<BODY>
14
 
<p>Go to the <A HREF="gsl-ref_1.html">first</A>, <A HREF="gsl-ref_18.html">previous</A>, <A HREF="gsl-ref_20.html">next</A>, <A HREF="gsl-ref_50.html">last</A> section, <A HREF="gsl-ref_toc.html">table of contents</A>.
15
 
<P><HR><P>
16
 
 
17
 
 
18
 
<H1><A NAME="SEC286" HREF="gsl-ref_toc.html#TOC286">Random Number Distributions</A></H1>
19
 
<P>
20
 
<A NAME="IDX1459"></A>
21
 
<A NAME="IDX1460"></A>
22
 
<A NAME="IDX1461"></A>
23
 
<A NAME="IDX1462"></A>
24
 
<A NAME="IDX1463"></A>
25
 
This chapter describes functions for generating random variates and
26
 
computing their probability distributions.  Samples from the
27
 
distributions described in this chapter can be obtained using any of the
28
 
random number generators in the library as an underlying source of
29
 
randomness.  In the simplest cases a non-uniform distribution can be
30
 
obtained analytically from the uniform distribution of a random number
31
 
generator by applying an appropriate transformation.  This method uses
32
 
one call to the random number generator.
33
 
 
34
 
</P>
35
 
<P>
36
 
More complicated distributions are created by the
37
 
<I>acceptance-rejection</I> method, which compares the desired
38
 
distribution against a distribution which is similar and known
39
 
analytically.  This usually requires several samples from the generator.
40
 
 
41
 
</P>
42
 
<P>
43
 
The library also provides cumulative distribution functions and inverse
44
 
cumulative distribution functions, sometimes referred to as quantile
45
 
functions.  The cumulative distribution functions and their inverses are
46
 
computed separately for the upper and lower tails of the distribution,
47
 
allowing full accuracy to be retained for small results.
48
 
 
49
 
</P>
50
 
<P>
51
 
The functions for random variates and probability density functions
52
 
described in this section are declared in <TT>'gsl_randist.h'</TT>.  The
53
 
corresponding cumulative distribution functions are declared in
54
 
<TT>'gsl_cdf.h'</TT>.
55
 
 
56
 
</P>
57
 
 
58
 
 
59
 
 
60
 
<H2><A NAME="SEC287" HREF="gsl-ref_toc.html#TOC287">Introduction</A></H2>
61
 
 
62
 
<P>
63
 
Continuous random number distributions are defined by a probability
64
 
density function, p(x), such that the probability of x
65
 
occurring in the infinitesimal range x to x+dx is 
66
 
p dx.
67
 
 
68
 
</P>
69
 
<P>
70
 
The cumulative distribution function for the lower tail is defined by,
71
 
 
72
 
<PRE class="example">
73
 
P(x) = \int_{-\infty}^{x} dx' p(x')
74
 
</PRE>
75
 
 
76
 
<P>
77
 
and gives the probability of a variate taking a value less than x.
78
 
 
79
 
</P>
80
 
<P>
81
 
The cumulative distribution function for the upper tail is defined by,
82
 
 
83
 
<PRE class="example">
84
 
Q(x) = \int_{x}^{+\infty} dx' p(x')
85
 
</PRE>
86
 
 
87
 
<P>
88
 
and gives the probability of a variate taking a value greater than x.
89
 
The upper and lower cumulative distribution functions are related by
90
 
P(x) + Q(x) = 1 and satisfy 
91
 
0 &#60;= P(x) &#60;= 1, 
92
 
0 &#60;= Q(x) &#60;= 1.
93
 
 
94
 
</P>
95
 
<P>
96
 
The inverse cumulative distributions, 
97
 
x=P^{-1}(P) and 
98
 
x=Q^{-1}(Q) give the values of x
99
 
which correspond to a specific value of P or {Q}.  
100
 
They can be used to find confidence limits from probability values.
101
 
 
102
 
</P>
103
 
 
104
 
 
105
 
<H2><A NAME="SEC288" HREF="gsl-ref_toc.html#TOC288">The Gaussian Distribution</A></H2>
106
 
<P>
107
 
<DL>
108
 
<DT><U>Random:</U> double <B>gsl_ran_gaussian</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>sigma</VAR>)</I>
109
 
<DD><A NAME="IDX1464"></A>
110
 
<A NAME="IDX1465"></A>
111
 
This function returns a Gaussian random variate, with mean zero and
112
 
standard deviation <VAR>sigma</VAR>.  The probability distribution for
113
 
Gaussian random variates is,
114
 
 
115
 
</P>
116
 
 
117
 
<PRE class="example">
118
 
p(x) dx = {1 \over \sqrt{2 \pi \sigma^2}} \exp (-x^2 / 2\sigma^2) dx
119
 
</PRE>
120
 
 
121
 
<P>
122
 
for x in the range -\infty to +\infty.  Use the
123
 
transformation z = \mu + x on the numbers returned by
124
 
<CODE>gsl_ran_gaussian</CODE> to obtain a Gaussian distribution with mean
125
 
\mu.  This function uses the Box-Mueller algorithm which requires two
126
 
calls to the random number generator <VAR>r</VAR>.
127
 
</DL>
128
 
 
129
 
</P>
130
 
<P>
131
 
<DL>
132
 
<DT><U>Function:</U> double <B>gsl_ran_gaussian_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
133
 
<DD><A NAME="IDX1466"></A>
134
 
This function computes the probability density p(x) at <VAR>x</VAR>
135
 
for a Gaussian distribution with standard deviation <VAR>sigma</VAR>, using
136
 
the formula given above.
137
 
</DL>
138
 
 
139
 
</P>
140
 
<P>
141
 
 
142
 
<P>
143
 
<DL>
144
 
<DT><U>Function:</U> double <B>gsl_ran_gaussian_ratio_method</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>sigma</VAR>)</I>
145
 
<DD><A NAME="IDX1467"></A>
146
 
This function computes a Gaussian random variate using the
147
 
Kinderman-Monahan ratio method.
148
 
</DL>
149
 
 
150
 
</P>
151
 
<P>
152
 
<DL>
153
 
<DT><U>Random:</U> double <B>gsl_ran_ugaussian</B> <I>(const gsl_rng * <VAR>r</VAR>)</I>
154
 
<DD><A NAME="IDX1468"></A>
155
 
<DT><U>Function:</U> double <B>gsl_ran_ugaussian_pdf</B> <I>(double <VAR>x</VAR>)</I>
156
 
<DD><A NAME="IDX1469"></A>
157
 
<DT><U>Random:</U> double <B>gsl_ran_ugaussian_ratio_method</B> <I>(const gsl_rng * <VAR>r</VAR>)</I>
158
 
<DD><A NAME="IDX1470"></A>
159
 
These functions compute results for the unit Gaussian distribution.  They
160
 
are equivalent to the functions above with a standard deviation of one,
161
 
<VAR>sigma</VAR> = 1.
162
 
</DL>
163
 
 
164
 
</P>
165
 
<P>
166
 
<DL>
167
 
<DT><U>Function:</U> double <B>gsl_cdf_gaussian_P</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
168
 
<DD><A NAME="IDX1471"></A>
169
 
<DT><U>Function:</U> double <B>gsl_cdf_gaussian_Q</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
170
 
<DD><A NAME="IDX1472"></A>
171
 
<DT><U>Function:</U> double <B>gsl_cdf_gaussian_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>sigma</VAR>)</I>
172
 
<DD><A NAME="IDX1473"></A>
173
 
<DT><U>Function:</U> double <B>gsl_cdf_gaussian_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>sigma</VAR>)</I>
174
 
<DD><A NAME="IDX1474"></A>
175
 
These functions compute the cumulative distribution functions
176
 
P(x), Q(x) and their inverses for the Gaussian
177
 
distribution with standard deviation <VAR>sigma</VAR>.
178
 
</DL>
179
 
 
180
 
</P>
181
 
<P>
182
 
<DL>
183
 
<DT><U>Function:</U> double <B>gsl_cdf_ugaussian_P</B> <I>(double <VAR>x</VAR>)</I>
184
 
<DD><A NAME="IDX1475"></A>
185
 
<DT><U>Function:</U> double <B>gsl_cdf_ugaussian_Q</B> <I>(double <VAR>x</VAR>)</I>
186
 
<DD><A NAME="IDX1476"></A>
187
 
<DT><U>Function:</U> double <B>gsl_cdf_ugaussian_Pinv</B> <I>(double <VAR>P</VAR>)</I>
188
 
<DD><A NAME="IDX1477"></A>
189
 
<DT><U>Function:</U> double <B>gsl_cdf_ugaussian_Qinv</B> <I>(double <VAR>Q</VAR>)</I>
190
 
<DD><A NAME="IDX1478"></A>
191
 
These functions compute the cumulative distribution functions
192
 
P(x), Q(x) and their inverses for the unit Gaussian
193
 
distribution.
194
 
</DL>
195
 
 
196
 
</P>
197
 
 
198
 
 
199
 
<H2><A NAME="SEC289" HREF="gsl-ref_toc.html#TOC289">The Gaussian Tail Distribution</A></H2>
200
 
<P>
201
 
<DL>
202
 
<DT><U>Random:</U> double <B>gsl_ran_gaussian_tail</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>sigma</VAR>)</I>
203
 
<DD><A NAME="IDX1479"></A>
204
 
<A NAME="IDX1480"></A>
205
 
This function provides random variates from the upper tail of a Gaussian
206
 
distribution with standard deviation <VAR>sigma</VAR>.  The values returned
207
 
are larger than the lower limit <VAR>a</VAR>, which must be positive.  The
208
 
method is based on Marsaglia's famous rectangle-wedge-tail algorithm (Ann
209
 
Math Stat 32, 894-899 (1961)), with this aspect explained in Knuth, v2,
210
 
3rd ed, p139,586 (exercise 11).
211
 
 
212
 
</P>
213
 
<P>
214
 
The probability distribution for Gaussian tail random variates is,
215
 
 
216
 
</P>
217
 
 
218
 
<PRE class="example">
219
 
p(x) dx = {1 \over N(a;\sigma)} \exp (- x^2/(2 \sigma^2)) dx
220
 
</PRE>
221
 
 
222
 
<P>
223
 
for x &#62; a where N(a;\sigma) is the normalization constant,
224
 
 
225
 
</P>
226
 
 
227
 
<PRE class="example">
228
 
N(a;\sigma) = (1/2) erfc(a / sqrt(2 sigma^2)).
229
 
</PRE>
230
 
 
231
 
</DL>
232
 
 
233
 
<P>
234
 
<DL>
235
 
<DT><U>Function:</U> double <B>gsl_ran_gaussian_tail_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>sigma</VAR>)</I>
236
 
<DD><A NAME="IDX1481"></A>
237
 
This function computes the probability density p(x) at <VAR>x</VAR>
238
 
for a Gaussian tail distribution with standard deviation <VAR>sigma</VAR> and
239
 
lower limit <VAR>a</VAR>, using the formula given above.
240
 
</DL>
241
 
 
242
 
</P>
243
 
<P>
244
 
 
245
 
<P>
246
 
<DL>
247
 
<DT><U>Random:</U> double <B>gsl_ran_ugaussian_tail</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>)</I>
248
 
<DD><A NAME="IDX1482"></A>
249
 
<DT><U>Function:</U> double <B>gsl_ran_ugaussian_tail_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
250
 
<DD><A NAME="IDX1483"></A>
251
 
These functions compute results for the tail of a unit Gaussian
252
 
distribution.  They are equivalent to the functions above with a standard
253
 
deviation of one, <VAR>sigma</VAR> = 1.
254
 
</DL>
255
 
 
256
 
</P>
257
 
 
258
 
 
259
 
 
260
 
<H2><A NAME="SEC290" HREF="gsl-ref_toc.html#TOC290">The Bivariate Gaussian Distribution</A></H2>
261
 
 
262
 
<P>
263
 
<DL>
264
 
<DT><U>Random:</U> void <B>gsl_ran_bivariate_gaussian</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>sigma_x</VAR>, double <VAR>sigma_y</VAR>, double <VAR>rho</VAR>, double * <VAR>x</VAR>, double * <VAR>y</VAR>)</I>
265
 
<DD><A NAME="IDX1484"></A>
266
 
<A NAME="IDX1485"></A>
267
 
<A NAME="IDX1486"></A>
268
 
<A NAME="IDX1487"></A>
269
 
This function generates a pair of correlated gaussian variates, with
270
 
mean zero, correlation coefficient <VAR>rho</VAR> and standard deviations
271
 
<VAR>sigma_x</VAR> and <VAR>sigma_y</VAR> in the x and y directions.
272
 
The probability distribution for bivariate gaussian random variates is,
273
 
 
274
 
</P>
275
 
 
276
 
<PRE class="example">
277
 
p(x,y) dx dy = {1 \over 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 dy
278
 
</PRE>
279
 
 
280
 
<P>
281
 
for x,y in the range -\infty to +\infty.  The
282
 
correlation coefficient <VAR>rho</VAR> should lie between 1 and
283
 
-1.
284
 
</DL>
285
 
 
286
 
</P>
287
 
<P>
288
 
<DL>
289
 
<DT><U>Function:</U> double <B>gsl_ran_bivariate_gaussian_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>y</VAR>, double <VAR>sigma_x</VAR>, double <VAR>sigma_y</VAR>, double <VAR>rho</VAR>)</I>
290
 
<DD><A NAME="IDX1488"></A>
291
 
This function computes the probability density p(x,y) at
292
 
(<VAR>x</VAR>,<VAR>y</VAR>) for a bivariate gaussian distribution with standard
293
 
deviations <VAR>sigma_x</VAR>, <VAR>sigma_y</VAR> and correlation coefficient
294
 
<VAR>rho</VAR>, using the formula given above.
295
 
</DL>
296
 
 
297
 
</P>
298
 
<P>
299
 
 
300
 
 
301
 
 
302
 
<H2><A NAME="SEC291" HREF="gsl-ref_toc.html#TOC291">The Exponential Distribution</A></H2>
303
 
<P>
304
 
<DL>
305
 
<DT><U>Random:</U> double <B>gsl_ran_exponential</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>mu</VAR>)</I>
306
 
<DD><A NAME="IDX1489"></A>
307
 
<A NAME="IDX1490"></A>
308
 
This function returns a random variate from the exponential distribution
309
 
with mean <VAR>mu</VAR>. The distribution is,
310
 
 
311
 
</P>
312
 
 
313
 
<PRE class="example">
314
 
p(x) dx = {1 \over \mu} \exp(-x/\mu) dx
315
 
</PRE>
316
 
 
317
 
<P>
318
 
for 
319
 
x &#62;= 0. 
320
 
</DL>
321
 
 
322
 
</P>
323
 
<P>
324
 
<DL>
325
 
<DT><U>Function:</U> double <B>gsl_ran_exponential_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>mu</VAR>)</I>
326
 
<DD><A NAME="IDX1491"></A>
327
 
This function computes the probability density p(x) at <VAR>x</VAR>
328
 
for an exponential distribution with mean <VAR>mu</VAR>, using the formula
329
 
given above.
330
 
</DL>
331
 
 
332
 
</P>
333
 
<P>
334
 
 
335
 
<P>
336
 
<DL>
337
 
<DT><U>Function:</U> double <B>gsl_cdf_exponential_P</B> <I>(double <VAR>x</VAR>, double <VAR>mu</VAR>)</I>
338
 
<DD><A NAME="IDX1492"></A>
339
 
<DT><U>Function:</U> double <B>gsl_cdf_exponential_Q</B> <I>(double <VAR>x</VAR>, double <VAR>mu</VAR>)</I>
340
 
<DD><A NAME="IDX1493"></A>
341
 
<DT><U>Function:</U> double <B>gsl_cdf_exponential_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>mu</VAR>)</I>
342
 
<DD><A NAME="IDX1494"></A>
343
 
<DT><U>Function:</U> double <B>gsl_cdf_exponential_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>mu</VAR>)</I>
344
 
<DD><A NAME="IDX1495"></A>
345
 
These functions compute the cumulative distribution functions
346
 
P(x), Q(x) and their inverses for the exponential
347
 
distribution with mean <VAR>mu</VAR>.
348
 
</DL>
349
 
 
350
 
</P>
351
 
 
352
 
 
353
 
<H2><A NAME="SEC292" HREF="gsl-ref_toc.html#TOC292">The Laplace Distribution</A></H2>
354
 
<P>
355
 
<DL>
356
 
<DT><U>Random:</U> double <B>gsl_ran_laplace</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>)</I>
357
 
<DD><A NAME="IDX1496"></A>
358
 
<A NAME="IDX1497"></A>
359
 
<A NAME="IDX1498"></A>
360
 
This function returns a random variate from the Laplace distribution
361
 
with width <VAR>a</VAR>.  The distribution is,
362
 
 
363
 
</P>
364
 
 
365
 
<PRE class="example">
366
 
p(x) dx = {1 \over 2 a}  \exp(-|x/a|) dx
367
 
</PRE>
368
 
 
369
 
<P>
370
 
for -\infty &#60; x &#60; \infty.
371
 
</DL>
372
 
 
373
 
</P>
374
 
<P>
375
 
<DL>
376
 
<DT><U>Function:</U> double <B>gsl_ran_laplace_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
377
 
<DD><A NAME="IDX1499"></A>
378
 
This function computes the probability density p(x) at <VAR>x</VAR>
379
 
for a Laplace distribution with width <VAR>a</VAR>, using the formula
380
 
given above.
381
 
</DL>
382
 
 
383
 
</P>
384
 
<P>
385
 
 
386
 
<P>
387
 
<DL>
388
 
<DT><U>Function:</U> double <B>gsl_cdf_laplace_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
389
 
<DD><A NAME="IDX1500"></A>
390
 
<DT><U>Function:</U> double <B>gsl_cdf_laplace_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
391
 
<DD><A NAME="IDX1501"></A>
392
 
<DT><U>Function:</U> double <B>gsl_cdf_laplace_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>)</I>
393
 
<DD><A NAME="IDX1502"></A>
394
 
<DT><U>Function:</U> double <B>gsl_cdf_laplace_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>)</I>
395
 
<DD><A NAME="IDX1503"></A>
396
 
These functions compute the cumulative distribution functions
397
 
P(x), Q(x) and their inverses for the Laplace
398
 
distribution with width <VAR>a</VAR>.
399
 
</DL>
400
 
 
401
 
</P>
402
 
 
403
 
 
404
 
 
405
 
<H2><A NAME="SEC293" HREF="gsl-ref_toc.html#TOC293">The Exponential Power Distribution</A></H2>
406
 
<P>
407
 
<DL>
408
 
<DT><U>Random:</U> double <B>gsl_ran_exppow</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
409
 
<DD><A NAME="IDX1504"></A>
410
 
<A NAME="IDX1505"></A>
411
 
This function returns a random variate from the exponential power distribution
412
 
with scale parameter <VAR>a</VAR> and exponent <VAR>b</VAR>.  The distribution is,
413
 
 
414
 
</P>
415
 
 
416
 
<PRE class="example">
417
 
p(x) dx = {1 \over 2 a \Gamma(1+1/b)} \exp(-|x/a|^b) dx
418
 
</PRE>
419
 
 
420
 
<P>
421
 
for 
422
 
x &#62;= 0.  For b = 1 this reduces to the Laplace
423
 
distribution.  For b = 2 it has the same form as a gaussian
424
 
distribution, but with 
425
 
a = \sqrt{2} \sigma.
426
 
</DL>
427
 
 
428
 
</P>
429
 
<P>
430
 
<DL>
431
 
<DT><U>Function:</U> double <B>gsl_ran_exppow_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
432
 
<DD><A NAME="IDX1506"></A>
433
 
This function computes the probability density p(x) at <VAR>x</VAR>
434
 
for an exponential power distribution with scale parameter <VAR>a</VAR>
435
 
and exponent <VAR>b</VAR>, using the formula given above.
436
 
</DL>
437
 
 
438
 
</P>
439
 
<P>
440
 
 
441
 
 
442
 
 
443
 
<H2><A NAME="SEC294" HREF="gsl-ref_toc.html#TOC294">The Cauchy Distribution</A></H2>
444
 
<P>
445
 
<DL>
446
 
<DT><U>Random:</U> double <B>gsl_ran_cauchy</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>)</I>
447
 
<DD><A NAME="IDX1507"></A>
448
 
<A NAME="IDX1508"></A>
449
 
This function returns a random variate from the Cauchy distribution with
450
 
scale parameter <VAR>a</VAR>.  The probability distribution for Cauchy
451
 
random variates is,
452
 
 
453
 
</P>
454
 
 
455
 
<PRE class="example">
456
 
p(x) dx = {1 \over a\pi (1 + (x/a)^2) } dx
457
 
</PRE>
458
 
 
459
 
<P>
460
 
for x in the range -\infty to +\infty.  The Cauchy
461
 
distribution is also known as the Lorentz distribution.
462
 
</DL>
463
 
 
464
 
</P>
465
 
<P>
466
 
<DL>
467
 
<DT><U>Function:</U> double <B>gsl_ran_cauchy_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
468
 
<DD><A NAME="IDX1509"></A>
469
 
This function computes the probability density p(x) at <VAR>x</VAR>
470
 
for a Cauchy distribution with scale parameter <VAR>a</VAR>, using the formula
471
 
given above.
472
 
</DL>
473
 
 
474
 
</P>
475
 
<P>
476
 
 
477
 
<P>
478
 
<DL>
479
 
<DT><U>Function:</U> double <B>gsl_cdf_cauchy_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
480
 
<DD><A NAME="IDX1510"></A>
481
 
<DT><U>Function:</U> double <B>gsl_cdf_cauchy_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
482
 
<DD><A NAME="IDX1511"></A>
483
 
<DT><U>Function:</U> double <B>gsl_cdf_cauchy_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>)</I>
484
 
<DD><A NAME="IDX1512"></A>
485
 
<DT><U>Function:</U> double <B>gsl_cdf_cauchy_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>)</I>
486
 
<DD><A NAME="IDX1513"></A>
487
 
These functions compute the cumulative distribution functions
488
 
P(x), Q(x) and their inverses for the Cauchy
489
 
distribution with scale parameter <VAR>a</VAR>.
490
 
</DL>
491
 
 
492
 
</P>
493
 
 
494
 
 
495
 
 
496
 
<H2><A NAME="SEC295" HREF="gsl-ref_toc.html#TOC295">The Rayleigh Distribution</A></H2>
497
 
<P>
498
 
<DL>
499
 
<DT><U>Random:</U> double <B>gsl_ran_rayleigh</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>sigma</VAR>)</I>
500
 
<DD><A NAME="IDX1514"></A>
501
 
<A NAME="IDX1515"></A>
502
 
This function returns a random variate from the Rayleigh distribution with
503
 
scale parameter <VAR>sigma</VAR>.  The distribution is,
504
 
 
505
 
</P>
506
 
 
507
 
<PRE class="example">
508
 
p(x) dx = {x \over \sigma^2} \exp(- x^2/(2 \sigma^2)) dx
509
 
</PRE>
510
 
 
511
 
<P>
512
 
for x &#62; 0.
513
 
</DL>
514
 
 
515
 
</P>
516
 
<P>
517
 
<DL>
518
 
<DT><U>Function:</U> double <B>gsl_ran_rayleigh_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
519
 
<DD><A NAME="IDX1516"></A>
520
 
This function computes the probability density p(x) at <VAR>x</VAR>
521
 
for a Rayleigh distribution with scale parameter <VAR>sigma</VAR>, using the
522
 
formula given above.
523
 
</DL>
524
 
 
525
 
</P>
526
 
<P>
527
 
 
528
 
<P>
529
 
<DL>
530
 
<DT><U>Function:</U> double <B>gsl_cdf_rayleigh_P</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
531
 
<DD><A NAME="IDX1517"></A>
532
 
<DT><U>Function:</U> double <B>gsl_cdf_rayleigh_Q</B> <I>(double <VAR>x</VAR>, double <VAR>sigma</VAR>)</I>
533
 
<DD><A NAME="IDX1518"></A>
534
 
<DT><U>Function:</U> double <B>gsl_cdf_rayleigh_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>sigma</VAR>)</I>
535
 
<DD><A NAME="IDX1519"></A>
536
 
<DT><U>Function:</U> double <B>gsl_cdf_rayleigh_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>sigma</VAR>)</I>
537
 
<DD><A NAME="IDX1520"></A>
538
 
These functions compute the cumulative distribution functions
539
 
P(x), Q(x) and their inverses for the Rayleigh
540
 
distribution with scale parameter <VAR>sigma</VAR>.
541
 
</DL>
542
 
 
543
 
</P>
544
 
 
545
 
 
546
 
 
547
 
<H2><A NAME="SEC296" HREF="gsl-ref_toc.html#TOC296">The Rayleigh Tail Distribution</A></H2>
548
 
<P>
549
 
<DL>
550
 
<DT><U>Random:</U> double <B>gsl_ran_rayleigh_tail</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>sigma</VAR>)</I>
551
 
<DD><A NAME="IDX1521"></A>
552
 
<A NAME="IDX1522"></A>
553
 
This function returns a random variate from the tail of the Rayleigh
554
 
distribution with scale parameter <VAR>sigma</VAR> and a lower limit of
555
 
<VAR>a</VAR>.  The distribution is,
556
 
 
557
 
</P>
558
 
 
559
 
<PRE class="example">
560
 
p(x) dx = {x \over \sigma^2} \exp ((a^2 - x^2) /(2 \sigma^2)) dx
561
 
</PRE>
562
 
 
563
 
<P>
564
 
for x &#62; a.
565
 
</DL>
566
 
 
567
 
</P>
568
 
<P>
569
 
<DL>
570
 
<DT><U>Function:</U> double <B>gsl_ran_rayleigh_tail_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>sigma</VAR>)</I>
571
 
<DD><A NAME="IDX1523"></A>
572
 
This function computes the probability density p(x) at <VAR>x</VAR>
573
 
for a Rayleigh tail distribution with scale parameter <VAR>sigma</VAR> and
574
 
lower limit <VAR>a</VAR>, using the formula given above.
575
 
</DL>
576
 
 
577
 
</P>
578
 
<P>
579
 
 
580
 
 
581
 
 
582
 
<H2><A NAME="SEC297" HREF="gsl-ref_toc.html#TOC297">The Landau Distribution</A></H2>
583
 
<P>
584
 
<DL>
585
 
<DT><U>Random:</U> double <B>gsl_ran_landau</B> <I>(const gsl_rng * <VAR>r</VAR>)</I>
586
 
<DD><A NAME="IDX1524"></A>
587
 
<A NAME="IDX1525"></A>
588
 
This function returns a random variate from the Landau distribution.  The
589
 
probability distribution for Landau random variates is defined
590
 
analytically by the complex integral,
591
 
 
592
 
</P>
593
 
 
594
 
<PRE class="example">
595
 
p(x) = (1/(2 \pi i)) \int_{c-i\infty}^{c+i\infty} ds exp(s log(s) + x s) 
596
 
</PRE>
597
 
 
598
 
<P>
599
 
For numerical purposes it is more convenient to use the following
600
 
equivalent form of the integral,
601
 
 
602
 
<PRE class="example">
603
 
p(x) = (1/\pi) \int_0^\infty dt \exp(-t \log(t) - x t) \sin(\pi t).
604
 
</PRE>
605
 
 
606
 
</DL>
607
 
 
608
 
<P>
609
 
<DL>
610
 
<DT><U>Function:</U> double <B>gsl_ran_landau_pdf</B> <I>(double <VAR>x</VAR>)</I>
611
 
<DD><A NAME="IDX1526"></A>
612
 
This function computes the probability density p(x) at <VAR>x</VAR>
613
 
for the Landau distribution using an approximation to the formula given
614
 
above.
615
 
</DL>
616
 
 
617
 
</P>
618
 
<P>
619
 
 
620
 
 
621
 
 
622
 
<H2><A NAME="SEC298" HREF="gsl-ref_toc.html#TOC298">The Levy alpha-Stable Distributions</A></H2>
623
 
<P>
624
 
<DL>
625
 
<DT><U>Random:</U> double <B>gsl_ran_levy</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>c</VAR>, double <VAR>alpha</VAR>)</I>
626
 
<DD><A NAME="IDX1527"></A>
627
 
<A NAME="IDX1528"></A>
628
 
This function returns a random variate from the Levy symmetric stable
629
 
distribution with scale <VAR>c</VAR> and exponent <VAR>alpha</VAR>.  The symmetric
630
 
stable probability distribution is defined by a fourier transform,
631
 
 
632
 
</P>
633
 
 
634
 
<PRE class="example">
635
 
p(x) = {1 \over 2 \pi} \int_{-\infty}^{+\infty} dt \exp(-it x - |c t|^alpha)
636
 
</PRE>
637
 
 
638
 
<P>
639
 
There is no explicit solution for the form of p(x) and the
640
 
library does not define a corresponding <CODE>pdf</CODE> function.  For
641
 
\alpha = 1 the distribution reduces to the Cauchy distribution.  For
642
 
\alpha = 2 it is a Gaussian distribution with 
643
 
\sigma = \sqrt{2} c.  For \alpha &#60; 1 the tails of the
644
 
distribution become extremely wide.
645
 
 
646
 
</P>
647
 
<P>
648
 
The algorithm only works for 
649
 
0 &#60; alpha &#60;= 2.
650
 
</DL>
651
 
 
652
 
</P>
653
 
<P>
654
 
 
655
 
 
656
 
 
657
 
<H2><A NAME="SEC299" HREF="gsl-ref_toc.html#TOC299">The Levy skew alpha-Stable Distribution</A></H2>
658
 
 
659
 
<P>
660
 
<DL>
661
 
<DT><U>Random:</U> double <B>gsl_ran_levy_skew</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>c</VAR>, double <VAR>alpha</VAR>, double <VAR>beta</VAR>)</I>
662
 
<DD><A NAME="IDX1529"></A>
663
 
<A NAME="IDX1530"></A>
664
 
<A NAME="IDX1531"></A>
665
 
This function returns a random variate from the Levy skew stable
666
 
distribution with scale <VAR>c</VAR>, exponent <VAR>alpha</VAR> and skewness
667
 
parameter <VAR>beta</VAR>.  The skewness parameter must lie in the range
668
 
[-1,1].  The Levy skew stable probability distribution is defined
669
 
by a fourier transform,
670
 
 
671
 
</P>
672
 
 
673
 
<PRE class="example">
674
 
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)))
675
 
</PRE>
676
 
 
677
 
<P>
678
 
When \alpha = 1 the term \tan(\pi \alpha/2) is replaced by
679
 
-(2/\pi)\log|t|.  There is no explicit solution for the form of
680
 
p(x) and the library does not define a corresponding <CODE>pdf</CODE>
681
 
function.  For \alpha = 2 the distribution reduces to a Gaussian
682
 
distribution with 
683
 
\sigma = \sqrt{2} c and the skewness parameter has no effect.  
684
 
For \alpha &#60; 1 the tails of the distribution become extremely
685
 
wide.  The symmetric distribution corresponds to \beta =
686
 
0.
687
 
 
688
 
</P>
689
 
<P>
690
 
The algorithm only works for 
691
 
0 &#60; alpha &#60;= 2.
692
 
</DL>
693
 
 
694
 
</P>
695
 
<P>
696
 
The Levy alpha-stable distributions have the property that if N
697
 
alpha-stable variates are drawn from the distribution p(c, \alpha,
698
 
\beta) then the sum Y = X_1 + X_2 + \dots + X_N will also be
699
 
distributed as an alpha-stable variate,
700
 
p(N^(1/\alpha) c, \alpha, \beta).
701
 
 
702
 
</P>
703
 
 
704
 
<P>
705
 
 
706
 
 
707
 
 
708
 
<H2><A NAME="SEC300" HREF="gsl-ref_toc.html#TOC300">The Gamma Distribution</A></H2>
709
 
<P>
710
 
<DL>
711
 
<DT><U>Random:</U> double <B>gsl_ran_gamma</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
712
 
<DD><A NAME="IDX1532"></A>
713
 
<A NAME="IDX1533"></A>
714
 
This function returns a random variate from the gamma
715
 
distribution.  The distribution function is,
716
 
 
717
 
</P>
718
 
 
719
 
<PRE class="example">
720
 
p(x) dx = {1 \over \Gamma(a) b^a} x^{a-1} e^{-x/b} dx
721
 
</PRE>
722
 
 
723
 
<P>
724
 
for x &#62; 0.
725
 
</DL>
726
 
 
727
 
</P>
728
 
<P>
729
 
<DL>
730
 
<DT><U>Function:</U> double <B>gsl_ran_gamma_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
731
 
<DD><A NAME="IDX1534"></A>
732
 
This function computes the probability density p(x) at <VAR>x</VAR>
733
 
for a gamma distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>, using the
734
 
formula given above.
735
 
</DL>
736
 
 
737
 
</P>
738
 
<P>
739
 
 
740
 
<P>
741
 
<DL>
742
 
<DT><U>Function:</U> double <B>gsl_cdf_gamma_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
743
 
<DD><A NAME="IDX1535"></A>
744
 
<DT><U>Function:</U> double <B>gsl_cdf_gamma_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
745
 
<DD><A NAME="IDX1536"></A>
746
 
<DT><U>Function:</U> double <B>gsl_cdf_gamma_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
747
 
<DD><A NAME="IDX1537"></A>
748
 
<DT><U>Function:</U> double <B>gsl_cdf_gamma_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
749
 
<DD><A NAME="IDX1538"></A>
750
 
These functions compute the cumulative distribution functions
751
 
P(x), Q(x) and their inverses for the gamma
752
 
distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>.
753
 
</DL>
754
 
 
755
 
</P>
756
 
 
757
 
 
758
 
<H2><A NAME="SEC301" HREF="gsl-ref_toc.html#TOC301">The Flat (Uniform) Distribution</A></H2>
759
 
<P>
760
 
<DL>
761
 
<DT><U>Random:</U> double <B>gsl_ran_flat</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
762
 
<DD><A NAME="IDX1539"></A>
763
 
<A NAME="IDX1540"></A>
764
 
<A NAME="IDX1541"></A>
765
 
This function returns a random variate from the flat (uniform)
766
 
distribution from <VAR>a</VAR> to <VAR>b</VAR>. The distribution is,
767
 
 
768
 
</P>
769
 
 
770
 
<PRE class="example">
771
 
p(x) dx = {1 \over (b-a)} dx
772
 
</PRE>
773
 
 
774
 
<P>
775
 
if 
776
 
a &#60;= x &#60; b and 0 otherwise.
777
 
</DL>
778
 
 
779
 
</P>
780
 
<P>
781
 
<DL>
782
 
<DT><U>Function:</U> double <B>gsl_ran_flat_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
783
 
<DD><A NAME="IDX1542"></A>
784
 
This function computes the probability density p(x) at <VAR>x</VAR>
785
 
for a uniform distribution from <VAR>a</VAR> to <VAR>b</VAR>, using the formula
786
 
given above.
787
 
</DL>
788
 
 
789
 
</P>
790
 
<P>
791
 
 
792
 
<P>
793
 
<DL>
794
 
<DT><U>Function:</U> double <B>gsl_cdf_flat_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
795
 
<DD><A NAME="IDX1543"></A>
796
 
<DT><U>Function:</U> double <B>gsl_cdf_flat_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
797
 
<DD><A NAME="IDX1544"></A>
798
 
<DT><U>Function:</U> double <B>gsl_cdf_flat_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
799
 
<DD><A NAME="IDX1545"></A>
800
 
<DT><U>Function:</U> double <B>gsl_cdf_flat_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
801
 
<DD><A NAME="IDX1546"></A>
802
 
These functions compute the cumulative distribution functions
803
 
P(x), Q(x) and their inverses for a uniform distribution
804
 
from <VAR>a</VAR> to <VAR>b</VAR>.
805
 
</DL>
806
 
 
807
 
</P>
808
 
 
809
 
 
810
 
 
811
 
<H2><A NAME="SEC302" HREF="gsl-ref_toc.html#TOC302">The Lognormal Distribution</A></H2>
812
 
<P>
813
 
<DL>
814
 
<DT><U>Random:</U> double <B>gsl_ran_lognormal</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
815
 
<DD><A NAME="IDX1547"></A>
816
 
<A NAME="IDX1548"></A>
817
 
This function returns a random variate from the lognormal
818
 
distribution.  The distribution function is,
819
 
 
820
 
</P>
821
 
 
822
 
<PRE class="example">
823
 
p(x) dx = {1 \over x \sqrt{2 \pi \sigma^2} } \exp(-(\ln(x) - \zeta)^2/2 \sigma^2) dx
824
 
</PRE>
825
 
 
826
 
<P>
827
 
for x &#62; 0.
828
 
</DL>
829
 
 
830
 
</P>
831
 
<P>
832
 
<DL>
833
 
<DT><U>Function:</U> double <B>gsl_ran_lognormal_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
834
 
<DD><A NAME="IDX1549"></A>
835
 
This function computes the probability density p(x) at <VAR>x</VAR>
836
 
for a lognormal distribution with parameters <VAR>zeta</VAR> and <VAR>sigma</VAR>,
837
 
using the formula given above.
838
 
</DL>
839
 
 
840
 
</P>
841
 
<P>
842
 
 
843
 
<P>
844
 
<DL>
845
 
<DT><U>Function:</U> double <B>gsl_cdf_lognormal_P</B> <I>(double <VAR>x</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
846
 
<DD><A NAME="IDX1550"></A>
847
 
<DT><U>Function:</U> double <B>gsl_cdf_lognormal_Q</B> <I>(double <VAR>x</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
848
 
<DD><A NAME="IDX1551"></A>
849
 
<DT><U>Function:</U> double <B>gsl_cdf_lognormal_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
850
 
<DD><A NAME="IDX1552"></A>
851
 
<DT><U>Function:</U> double <B>gsl_cdf_lognormal_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>zeta</VAR>, double <VAR>sigma</VAR>)</I>
852
 
<DD><A NAME="IDX1553"></A>
853
 
These functions compute the cumulative distribution functions
854
 
P(x), Q(x) and their inverses for the lognormal
855
 
distribution with parameters <VAR>zeta</VAR> and <VAR>sigma</VAR>.
856
 
</DL>
857
 
 
858
 
</P>
859
 
 
860
 
 
861
 
 
862
 
<H2><A NAME="SEC303" HREF="gsl-ref_toc.html#TOC303">The Chi-squared Distribution</A></H2>
863
 
<P>
864
 
The chi-squared distribution arises in statistics.  If Y_i are
865
 
n independent gaussian random variates with unit variance then the
866
 
sum-of-squares,
867
 
 
868
 
</P>
869
 
 
870
 
<PRE class="example">
871
 
X_i = \sum_i Y_i^2
872
 
</PRE>
873
 
 
874
 
<P>
875
 
has a chi-squared distribution with n degrees of freedom.
876
 
 
877
 
</P>
878
 
<P>
879
 
<DL>
880
 
<DT><U>Random:</U> double <B>gsl_ran_chisq</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>nu</VAR>)</I>
881
 
<DD><A NAME="IDX1554"></A>
882
 
<A NAME="IDX1555"></A>
883
 
This function returns a random variate from the chi-squared distribution
884
 
with <VAR>nu</VAR> degrees of freedom. The distribution function is,
885
 
 
886
 
</P>
887
 
 
888
 
<PRE class="example">
889
 
p(x) dx = {1 \over 2 \Gamma(\nu/2) } (x/2)^{\nu/2 - 1} \exp(-x/2) dx
890
 
</PRE>
891
 
 
892
 
<P>
893
 
for 
894
 
x &#62;= 0. 
895
 
</DL>
896
 
 
897
 
</P>
898
 
<P>
899
 
<DL>
900
 
<DT><U>Function:</U> double <B>gsl_ran_chisq_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
901
 
<DD><A NAME="IDX1556"></A>
902
 
This function computes the probability density p(x) at <VAR>x</VAR>
903
 
for a chi-squared distribution with <VAR>nu</VAR> degrees of freedom, using
904
 
the formula given above.
905
 
</DL>
906
 
 
907
 
</P>
908
 
<P>
909
 
 
910
 
<P>
911
 
<DL>
912
 
<DT><U>Function:</U> double <B>gsl_cdf_chisq_P</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
913
 
<DD><A NAME="IDX1557"></A>
914
 
<DT><U>Function:</U> double <B>gsl_cdf_chisq_Q</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
915
 
<DD><A NAME="IDX1558"></A>
916
 
<DT><U>Function:</U> double <B>gsl_cdf_chisq_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>nu</VAR>)</I>
917
 
<DD><A NAME="IDX1559"></A>
918
 
<DT><U>Function:</U> double <B>gsl_cdf_chisq_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>nu</VAR>)</I>
919
 
<DD><A NAME="IDX1560"></A>
920
 
These functions compute the cumulative distribution functions
921
 
P(x), Q(x) and their inverses for the chi-squared
922
 
distribution with <VAR>nu</VAR> degrees of freedom.
923
 
</DL>
924
 
 
925
 
</P>
926
 
 
927
 
 
928
 
 
929
 
<H2><A NAME="SEC304" HREF="gsl-ref_toc.html#TOC304">The F-distribution</A></H2>
930
 
<P>
931
 
The F-distribution arises in statistics.  If Y_1 and Y_2
932
 
are chi-squared deviates with \nu_1 and \nu_2 degrees of
933
 
freedom then the ratio,
934
 
 
935
 
</P>
936
 
 
937
 
<PRE class="example">
938
 
X = { (Y_1 / \nu_1) \over (Y_2 / \nu_2) }
939
 
</PRE>
940
 
 
941
 
<P>
942
 
has an F-distribution F(x;\nu_1,\nu_2).
943
 
 
944
 
</P>
945
 
<P>
946
 
<DL>
947
 
<DT><U>Random:</U> double <B>gsl_ran_fdist</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>nu1</VAR>, double <VAR>nu2</VAR>)</I>
948
 
<DD><A NAME="IDX1561"></A>
949
 
<A NAME="IDX1562"></A>
950
 
This function returns a random variate from the F-distribution with degrees of freedom <VAR>nu1</VAR> and <VAR>nu2</VAR>. The distribution function is,
951
 
 
952
 
</P>
953
 
 
954
 
<PRE class="example">
955
 
p(x) dx = 
956
 
   { \Gamma((\nu_1 + \nu_2)/2)
957
 
        \over \Gamma(\nu_1/2) \Gamma(\nu_2/2) } 
958
 
   \nu_1^{\nu_1/2} \nu_2^{\nu_2/2} 
959
 
   x^{\nu_1/2 - 1} (\nu_2 + \nu_1 x)^{-\nu_1/2 -\nu_2/2}
960
 
</PRE>
961
 
 
962
 
<P>
963
 
for 
964
 
x &#62;= 0. 
965
 
</DL>
966
 
 
967
 
</P>
968
 
<P>
969
 
<DL>
970
 
<DT><U>Function:</U> double <B>gsl_ran_fdist_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>nu1</VAR>, double <VAR>nu2</VAR>)</I>
971
 
<DD><A NAME="IDX1563"></A>
972
 
This function computes the probability density p(x) at <VAR>x</VAR>
973
 
for an F-distribution with <VAR>nu1</VAR> and <VAR>nu2</VAR> degrees of freedom,
974
 
using the formula given above.
975
 
</DL>
976
 
 
977
 
</P>
978
 
<P>
979
 
 
980
 
<P>
981
 
<DL>
982
 
<DT><U>Function:</U> double <B>gsl_cdf_fdist_P</B> <I>(double <VAR>x</VAR>, double <VAR>nu1</VAR>, double <VAR>nu2</VAR>)</I>
983
 
<DD><A NAME="IDX1564"></A>
984
 
<DT><U>Function:</U> double <B>gsl_cdf_fdist_Q</B> <I>(double <VAR>x</VAR>, double <VAR>nu1</VAR>, double <VAR>nu2</VAR>)</I>
985
 
<DD><A NAME="IDX1565"></A>
986
 
These functions compute the cumulative distribution functions
987
 
P(x) and Q(x) for the F-distribution with <VAR>nu1</VAR> and
988
 
<VAR>nu2</VAR> degrees of freedom.
989
 
</DL>
990
 
 
991
 
</P>
992
 
 
993
 
 
994
 
<H2><A NAME="SEC305" HREF="gsl-ref_toc.html#TOC305">The t-distribution</A></H2>
995
 
<P>
996
 
The t-distribution arises in statistics.  If Y_1 has a normal
997
 
distribution and Y_2 has a chi-squared distribution with
998
 
\nu degrees of freedom then the ratio,
999
 
 
1000
 
</P>
1001
 
 
1002
 
<PRE class="example">
1003
 
X = { Y_1 \over \sqrt{Y_2 / \nu} }
1004
 
</PRE>
1005
 
 
1006
 
<P>
1007
 
has a t-distribution t(x;\nu) with \nu degrees of freedom.
1008
 
 
1009
 
</P>
1010
 
<P>
1011
 
<DL>
1012
 
<DT><U>Random:</U> double <B>gsl_ran_tdist</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>nu</VAR>)</I>
1013
 
<DD><A NAME="IDX1566"></A>
1014
 
<A NAME="IDX1567"></A>
1015
 
<A NAME="IDX1568"></A>
1016
 
This function returns a random variate from the t-distribution.  The
1017
 
distribution function is,
1018
 
 
1019
 
</P>
1020
 
 
1021
 
<PRE class="example">
1022
 
p(x) dx = {\Gamma((\nu + 1)/2) \over \sqrt{\pi \nu} \Gamma(\nu/2)}
1023
 
   (1 + x^2/\nu)^{-(\nu + 1)/2} dx
1024
 
</PRE>
1025
 
 
1026
 
<P>
1027
 
for -\infty &#60; x &#60; +\infty.
1028
 
</DL>
1029
 
 
1030
 
</P>
1031
 
<P>
1032
 
<DL>
1033
 
<DT><U>Function:</U> double <B>gsl_ran_tdist_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
1034
 
<DD><A NAME="IDX1569"></A>
1035
 
This function computes the probability density p(x) at <VAR>x</VAR>
1036
 
for a t-distribution with <VAR>nu</VAR> degrees of freedom, using the formula
1037
 
given above.
1038
 
</DL>
1039
 
 
1040
 
</P>
1041
 
<P>
1042
 
 
1043
 
<P>
1044
 
<DL>
1045
 
<DT><U>Function:</U> double <B>gsl_cdf_tdist_P</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
1046
 
<DD><A NAME="IDX1570"></A>
1047
 
<DT><U>Function:</U> double <B>gsl_cdf_tdist_Q</B> <I>(double <VAR>x</VAR>, double <VAR>nu</VAR>)</I>
1048
 
<DD><A NAME="IDX1571"></A>
1049
 
<DT><U>Function:</U> double <B>gsl_cdf_tdist_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>nu</VAR>)</I>
1050
 
<DD><A NAME="IDX1572"></A>
1051
 
<DT><U>Function:</U> double <B>gsl_cdf_tdist_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>nu</VAR>)</I>
1052
 
<DD><A NAME="IDX1573"></A>
1053
 
These functions compute the cumulative distribution functions
1054
 
P(x), Q(x) and their inverses for the t-distribution
1055
 
with <VAR>nu</VAR> degrees of freedom.
1056
 
</DL>
1057
 
 
1058
 
</P>
1059
 
 
1060
 
 
1061
 
<H2><A NAME="SEC306" HREF="gsl-ref_toc.html#TOC306">The Beta Distribution</A></H2>
1062
 
<P>
1063
 
<DL>
1064
 
<DT><U>Random:</U> double <B>gsl_ran_beta</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1065
 
<DD><A NAME="IDX1574"></A>
1066
 
<A NAME="IDX1575"></A>
1067
 
This function returns a random variate from the beta
1068
 
distribution.  The distribution function is,
1069
 
 
1070
 
</P>
1071
 
 
1072
 
<PRE class="example">
1073
 
p(x) dx = {\Gamma(a+b) \over \Gamma(a) \Gamma(b)} x^{a-1} (1-x)^{b-1} dx
1074
 
</PRE>
1075
 
 
1076
 
<P>
1077
 
for 
1078
 
0 &#60;= x &#60;= 1.
1079
 
</DL>
1080
 
 
1081
 
</P>
1082
 
<P>
1083
 
<DL>
1084
 
<DT><U>Function:</U> double <B>gsl_ran_beta_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1085
 
<DD><A NAME="IDX1576"></A>
1086
 
This function computes the probability density p(x) at <VAR>x</VAR>
1087
 
for a beta distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>, using the
1088
 
formula given above.
1089
 
</DL>
1090
 
 
1091
 
</P>
1092
 
<P>
1093
 
 
1094
 
<P>
1095
 
<DL>
1096
 
<DT><U>Function:</U> double <B>gsl_cdf_beta_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1097
 
<DD><A NAME="IDX1577"></A>
1098
 
<DT><U>Function:</U> double <B>gsl_cdf_beta_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1099
 
<DD><A NAME="IDX1578"></A>
1100
 
These functions compute the cumulative distribution functions
1101
 
P(x) and Q(x) for the beta distribution with
1102
 
parameters <VAR>a</VAR> and <VAR>b</VAR>.
1103
 
</DL>
1104
 
 
1105
 
</P>
1106
 
 
1107
 
 
1108
 
<H2><A NAME="SEC307" HREF="gsl-ref_toc.html#TOC307">The Logistic Distribution</A></H2>
1109
 
 
1110
 
<P>
1111
 
<DL>
1112
 
<DT><U>Random:</U> double <B>gsl_ran_logistic</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>)</I>
1113
 
<DD><A NAME="IDX1579"></A>
1114
 
<A NAME="IDX1580"></A>
1115
 
This function returns a random variate from the logistic
1116
 
distribution.  The distribution function is,
1117
 
 
1118
 
</P>
1119
 
 
1120
 
<PRE class="example">
1121
 
p(x) dx = { \exp(-x/a) \over a (1 + \exp(-x/a))^2 } dx
1122
 
</PRE>
1123
 
 
1124
 
<P>
1125
 
for -\infty &#60; x &#60; +\infty.
1126
 
</DL>
1127
 
 
1128
 
</P>
1129
 
<P>
1130
 
<DL>
1131
 
<DT><U>Function:</U> double <B>gsl_ran_logistic_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
1132
 
<DD><A NAME="IDX1581"></A>
1133
 
This function computes the probability density p(x) at <VAR>x</VAR>
1134
 
for a logistic distribution with scale parameter <VAR>a</VAR>, using the
1135
 
formula given above.
1136
 
</DL>
1137
 
 
1138
 
</P>
1139
 
<P>
1140
 
 
1141
 
<P>
1142
 
<DL>
1143
 
<DT><U>Function:</U> double <B>gsl_cdf_logistic_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
1144
 
<DD><A NAME="IDX1582"></A>
1145
 
<DT><U>Function:</U> double <B>gsl_cdf_logistic_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>)</I>
1146
 
<DD><A NAME="IDX1583"></A>
1147
 
<DT><U>Function:</U> double <B>gsl_cdf_logistic_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>)</I>
1148
 
<DD><A NAME="IDX1584"></A>
1149
 
<DT><U>Function:</U> double <B>gsl_cdf_logistic_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>)</I>
1150
 
<DD><A NAME="IDX1585"></A>
1151
 
These functions compute the cumulative distribution functions
1152
 
P(x), Q(x) and their inverses for the logistic
1153
 
distribution with scale parameter <VAR>a</VAR>.
1154
 
</DL>
1155
 
 
1156
 
</P>
1157
 
 
1158
 
 
1159
 
<H2><A NAME="SEC308" HREF="gsl-ref_toc.html#TOC308">The Pareto Distribution</A></H2>
1160
 
<P>
1161
 
<DL>
1162
 
<DT><U>Random:</U> double <B>gsl_ran_pareto</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1163
 
<DD><A NAME="IDX1586"></A>
1164
 
<A NAME="IDX1587"></A>
1165
 
This function returns a random variate from the Pareto distribution of
1166
 
order <VAR>a</VAR>.  The distribution function is,
1167
 
 
1168
 
</P>
1169
 
 
1170
 
<PRE class="example">
1171
 
p(x) dx = (a/b) / (x/b)^{a+1} dx
1172
 
</PRE>
1173
 
 
1174
 
<P>
1175
 
for 
1176
 
x &#62;= b.
1177
 
</DL>
1178
 
 
1179
 
</P>
1180
 
<P>
1181
 
<DL>
1182
 
<DT><U>Function:</U> double <B>gsl_ran_pareto_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1183
 
<DD><A NAME="IDX1588"></A>
1184
 
This function computes the probability density p(x) at <VAR>x</VAR>
1185
 
for a Pareto distribution with exponent <VAR>a</VAR> and scale <VAR>b</VAR>, using
1186
 
the formula given above.
1187
 
</DL>
1188
 
 
1189
 
</P>
1190
 
<P>
1191
 
 
1192
 
<P>
1193
 
<DL>
1194
 
<DT><U>Function:</U> double <B>gsl_cdf_pareto_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1195
 
<DD><A NAME="IDX1589"></A>
1196
 
<DT><U>Function:</U> double <B>gsl_cdf_pareto_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1197
 
<DD><A NAME="IDX1590"></A>
1198
 
<DT><U>Function:</U> double <B>gsl_cdf_pareto_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1199
 
<DD><A NAME="IDX1591"></A>
1200
 
<DT><U>Function:</U> double <B>gsl_cdf_pareto_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1201
 
<DD><A NAME="IDX1592"></A>
1202
 
These functions compute the cumulative distribution functions
1203
 
P(x), Q(x) and their inverses for the Pareto
1204
 
distribution with exponent <VAR>a</VAR> and scale <VAR>b</VAR>.
1205
 
</DL>
1206
 
 
1207
 
</P>
1208
 
 
1209
 
 
1210
 
<H2><A NAME="SEC309" HREF="gsl-ref_toc.html#TOC309">Spherical Vector Distributions</A></H2>
1211
 
 
1212
 
<P>
1213
 
The spherical distributions generate random vectors, located on a
1214
 
spherical surface.  They can be used as random directions, for example in
1215
 
the steps of a random walk.
1216
 
 
1217
 
</P>
1218
 
<P>
1219
 
<DL>
1220
 
<DT><U>Random:</U> void <B>gsl_ran_dir_2d</B> <I>(const gsl_rng * <VAR>r</VAR>, double *<VAR>x</VAR>, double *<VAR>y</VAR>)</I>
1221
 
<DD><A NAME="IDX1593"></A>
1222
 
<DT><U>Random:</U> void <B>gsl_ran_dir_2d_trig_method</B> <I>(const gsl_rng * <VAR>r</VAR>, double *<VAR>x</VAR>, double *<VAR>y</VAR>)</I>
1223
 
<DD><A NAME="IDX1594"></A>
1224
 
<A NAME="IDX1595"></A>
1225
 
<A NAME="IDX1596"></A>
1226
 
<A NAME="IDX1597"></A>
1227
 
This function returns a random direction vector v =
1228
 
(<VAR>x</VAR>,<VAR>y</VAR>) in two dimensions.  The vector is normalized such that
1229
 
|v|^2 = x^2 + y^2 = 1.  The obvious way to do this is to take a
1230
 
uniform random number between 0 and 2\pi and let <VAR>x</VAR> and
1231
 
<VAR>y</VAR> be the sine and cosine respectively.  Two trig functions would
1232
 
have been expensive in the old days, but with modern hardware
1233
 
implementations, this is sometimes the fastest way to go.  This is the
1234
 
case for the Pentium (but not the case for the Sun Sparcstation).
1235
 
One can avoid the trig evaluations by choosing <VAR>x</VAR> and
1236
 
<VAR>y</VAR> in the interior of a unit circle (choose them at random from the
1237
 
interior of the enclosing square, and then reject those that are outside
1238
 
the unit circle), and then dividing by 
1239
 
\sqrt{x^2 + y^2}.
1240
 
A much cleverer approach, attributed to von Neumann (See Knuth, v2, 3rd
1241
 
ed, p140, exercise 23), requires neither trig nor a square root.  In
1242
 
this approach, <VAR>u</VAR> and <VAR>v</VAR> are chosen at random from the
1243
 
interior of a unit circle, and then x=(u^2-v^2)/(u^2+v^2) and
1244
 
y=2uv/(u^2+v^2).
1245
 
</DL>
1246
 
 
1247
 
</P>
1248
 
<P>
1249
 
<DL>
1250
 
<DT><U>Random:</U> void <B>gsl_ran_dir_3d</B> <I>(const gsl_rng * <VAR>r</VAR>, double *<VAR>x</VAR>, double *<VAR>y</VAR>, double * <VAR>z</VAR>)</I>
1251
 
<DD><A NAME="IDX1598"></A>
1252
 
<A NAME="IDX1599"></A>
1253
 
<A NAME="IDX1600"></A>
1254
 
<A NAME="IDX1601"></A>
1255
 
This function returns a random direction vector v =
1256
 
(<VAR>x</VAR>,<VAR>y</VAR>,<VAR>z</VAR>) in three dimensions.  The vector is normalized
1257
 
such that |v|^2 = x^2 + y^2 + z^2 = 1.  The method employed is
1258
 
due to Robert E. Knop (CACM 13, 326 (1970)), and explained in Knuth, v2,
1259
 
3rd ed, p136.  It uses the surprising fact that the distribution
1260
 
projected along any axis is actually uniform (this is only true for 3
1261
 
dimensions).
1262
 
</DL>
1263
 
 
1264
 
</P>
1265
 
<P>
1266
 
<DL>
1267
 
<DT><U>Random:</U> void <B>gsl_ran_dir_nd</B> <I>(const gsl_rng * <VAR>r</VAR>, size_t <VAR>n</VAR>, double *<VAR>x</VAR>)</I>
1268
 
<DD><A NAME="IDX1602"></A>
1269
 
<A NAME="IDX1603"></A>
1270
 
<A NAME="IDX1604"></A>
1271
 
<A NAME="IDX1605"></A>
1272
 
 
1273
 
</P>
1274
 
<P>
1275
 
This function returns a random direction vector
1276
 
v = (x_1,x_2,...,x_n) in <VAR>n</VAR> dimensions.  The vector is normalized
1277
 
such that 
1278
 
|v|^2 = x_1^2 + x_2^2 + ... + x_n^2 = 1.  The method
1279
 
uses the fact that a multivariate gaussian distribution is spherically
1280
 
symmetric.  Each component is generated to have a gaussian distribution,
1281
 
and then the components are normalized.  The method is described by
1282
 
Knuth, v2, 3rd ed, p135-136, and attributed to G. W. Brown, Modern
1283
 
Mathematics for the Engineer (1956).
1284
 
</DL>
1285
 
 
1286
 
</P>
1287
 
 
1288
 
 
1289
 
<H2><A NAME="SEC310" HREF="gsl-ref_toc.html#TOC310">The Weibull Distribution</A></H2>
1290
 
<P>
1291
 
<DL>
1292
 
<DT><U>Random:</U> double <B>gsl_ran_weibull</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1293
 
<DD><A NAME="IDX1606"></A>
1294
 
<A NAME="IDX1607"></A>
1295
 
This function returns a random variate from the Weibull distribution.  The
1296
 
distribution function is,
1297
 
 
1298
 
</P>
1299
 
 
1300
 
<PRE class="example">
1301
 
p(x) dx = {b \over a^b} x^{b-1}  \exp(-(x/a)^b) dx
1302
 
</PRE>
1303
 
 
1304
 
<P>
1305
 
for 
1306
 
x &#62;= 0.
1307
 
</DL>
1308
 
 
1309
 
</P>
1310
 
<P>
1311
 
<DL>
1312
 
<DT><U>Function:</U> double <B>gsl_ran_weibull_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1313
 
<DD><A NAME="IDX1608"></A>
1314
 
This function computes the probability density p(x) at <VAR>x</VAR>
1315
 
for a Weibull distribution with scale <VAR>a</VAR> and exponent <VAR>b</VAR>,
1316
 
using the formula given above.
1317
 
</DL>
1318
 
 
1319
 
</P>
1320
 
<P>
1321
 
 
1322
 
<P>
1323
 
<DL>
1324
 
<DT><U>Function:</U> double <B>gsl_cdf_weibull_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1325
 
<DD><A NAME="IDX1609"></A>
1326
 
<DT><U>Function:</U> double <B>gsl_cdf_weibull_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1327
 
<DD><A NAME="IDX1610"></A>
1328
 
<DT><U>Function:</U> double <B>gsl_cdf_weibull_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1329
 
<DD><A NAME="IDX1611"></A>
1330
 
<DT><U>Function:</U> double <B>gsl_cdf_weibull_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1331
 
<DD><A NAME="IDX1612"></A>
1332
 
These functions compute the cumulative distribution functions
1333
 
P(x), Q(x) and their inverses for the Weibull
1334
 
distribution with scale <VAR>a</VAR> and exponent <VAR>b</VAR>.
1335
 
</DL>
1336
 
 
1337
 
</P>
1338
 
 
1339
 
 
1340
 
 
1341
 
<H2><A NAME="SEC311" HREF="gsl-ref_toc.html#TOC311">The Type-1 Gumbel Distribution</A></H2>
1342
 
<P>
1343
 
<DL>
1344
 
<DT><U>Random:</U> double <B>gsl_ran_gumbel1</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1345
 
<DD><A NAME="IDX1613"></A>
1346
 
<A NAME="IDX1614"></A>
1347
 
<A NAME="IDX1615"></A>
1348
 
This function returns  a random variate from the Type-1 Gumbel
1349
 
distribution.  The Type-1 Gumbel distribution function is,
1350
 
 
1351
 
</P>
1352
 
 
1353
 
<PRE class="example">
1354
 
p(x) dx = a b \exp(-(b \exp(-ax) + ax)) dx
1355
 
</PRE>
1356
 
 
1357
 
<P>
1358
 
for -\infty &#60; x &#60; \infty. 
1359
 
</DL>
1360
 
 
1361
 
</P>
1362
 
<P>
1363
 
<DL>
1364
 
<DT><U>Function:</U> double <B>gsl_ran_gumbel1_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1365
 
<DD><A NAME="IDX1616"></A>
1366
 
This function computes the probability density p(x) at <VAR>x</VAR>
1367
 
for a Type-1 Gumbel distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>,
1368
 
using the formula given above.
1369
 
</DL>
1370
 
 
1371
 
</P>
1372
 
<P>
1373
 
 
1374
 
<P>
1375
 
<DL>
1376
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel1_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1377
 
<DD><A NAME="IDX1617"></A>
1378
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel1_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1379
 
<DD><A NAME="IDX1618"></A>
1380
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel1_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1381
 
<DD><A NAME="IDX1619"></A>
1382
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel1_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1383
 
<DD><A NAME="IDX1620"></A>
1384
 
These functions compute the cumulative distribution functions
1385
 
P(x), Q(x) and their inverses for the Type-1 Gumbel
1386
 
distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>.
1387
 
</DL>
1388
 
 
1389
 
</P>
1390
 
 
1391
 
 
1392
 
 
1393
 
<H2><A NAME="SEC312" HREF="gsl-ref_toc.html#TOC312">The Type-2 Gumbel Distribution</A></H2>
1394
 
<P>
1395
 
<DL>
1396
 
<DT><U>Random:</U> double <B>gsl_ran_gumbel2</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1397
 
<DD><A NAME="IDX1621"></A>
1398
 
<A NAME="IDX1622"></A>
1399
 
<A NAME="IDX1623"></A>
1400
 
This function returns a random variate from the Type-2 Gumbel
1401
 
distribution.  The Type-2 Gumbel distribution function is,
1402
 
 
1403
 
</P>
1404
 
 
1405
 
<PRE class="example">
1406
 
p(x) dx = a b x^{-a-1} \exp(-b x^{-a}) dx
1407
 
</PRE>
1408
 
 
1409
 
<P>
1410
 
for 0 &#60; x &#60; \infty.
1411
 
</DL>
1412
 
 
1413
 
</P>
1414
 
<P>
1415
 
<DL>
1416
 
<DT><U>Function:</U> double <B>gsl_ran_gumbel2_pdf</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1417
 
<DD><A NAME="IDX1624"></A>
1418
 
This function computes the probability density p(x) at <VAR>x</VAR>
1419
 
for a Type-2 Gumbel distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>,
1420
 
using the formula given above.
1421
 
</DL>
1422
 
 
1423
 
</P>
1424
 
<P>
1425
 
 
1426
 
<P>
1427
 
<DL>
1428
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel2_P</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1429
 
<DD><A NAME="IDX1625"></A>
1430
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel2_Q</B> <I>(double <VAR>x</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1431
 
<DD><A NAME="IDX1626"></A>
1432
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel2_Pinv</B> <I>(double <VAR>P</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1433
 
<DD><A NAME="IDX1627"></A>
1434
 
<DT><U>Function:</U> double <B>gsl_cdf_gumbel2_Qinv</B> <I>(double <VAR>Q</VAR>, double <VAR>a</VAR>, double <VAR>b</VAR>)</I>
1435
 
<DD><A NAME="IDX1628"></A>
1436
 
These functions compute the cumulative distribution functions
1437
 
P(x), Q(x) and their inverses for the Type-2 Gumbel
1438
 
distribution with parameters <VAR>a</VAR> and <VAR>b</VAR>.
1439
 
</DL>
1440
 
 
1441
 
</P>
1442
 
 
1443
 
 
1444
 
 
1445
 
<H2><A NAME="SEC313" HREF="gsl-ref_toc.html#TOC313">The Dirichlet Distribution</A></H2>
1446
 
<P>
1447
 
<DL>
1448
 
<DT><U>Random:</U> void <B>gsl_ran_dirichlet</B> <I>(const gsl_rng * <VAR>r</VAR>, size_t <VAR>K</VAR>, const double <VAR>alpha</VAR>[], double <VAR>theta</VAR>[])</I>
1449
 
<DD><A NAME="IDX1629"></A>
1450
 
<A NAME="IDX1630"></A>
1451
 
This function returns an array of <VAR>K</VAR> random variates from a Dirichlet
1452
 
distribution of order <VAR>K</VAR>-1. The distribution function is
1453
 
 
1454
 
</P>
1455
 
 
1456
 
<PRE class="example">
1457
 
p(\theta_1, ..., \theta_K) d\theta_1 ... d\theta_K = 
1458
 
  (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
1459
 
</PRE>
1460
 
 
1461
 
<P>
1462
 
for 
1463
 
theta_i &#62;= 0
1464
 
and 
1465
 
alpha_i &#62;= 0.  The delta function ensures that \sum \theta_i = 1.
1466
 
The normalization factor Z is
1467
 
 
1468
 
</P>
1469
 
 
1470
 
<PRE class="example">
1471
 
Z = {\prod_{i=1}^K \Gamma(\alpha_i)} / {\Gamma( \sum_{i=1}^K \alpha_i)}
1472
 
</PRE>
1473
 
 
1474
 
<P>
1475
 
The random variates are generated by sampling <VAR>K</VAR> values 
1476
 
from gamma distributions with parameters 
1477
 
a=alpha_i, b=1, 
1478
 
and renormalizing. 
1479
 
See A.M. Law, W.D. Kelton, <CITE>Simulation Modeling and Analysis</CITE> (1991).
1480
 
</DL>
1481
 
 
1482
 
</P>
1483
 
<P>
1484
 
<DL>
1485
 
<DT><U>Function:</U> double <B>gsl_ran_dirichlet_pdf</B> <I>(size_t <VAR>K</VAR>, const double <VAR>alpha</VAR>[], const double <VAR>theta</VAR>[])</I>
1486
 
<DD><A NAME="IDX1631"></A>
1487
 
This function computes the probability density 
1488
 
p(\theta_1, ... , \theta_K)
1489
 
at <VAR>theta</VAR>[<VAR>K</VAR>] for a Dirichlet distribution with parameters 
1490
 
<VAR>alpha</VAR>[<VAR>K</VAR>], using the formula given above.
1491
 
</DL>
1492
 
 
1493
 
</P>
1494
 
<P>
1495
 
<DL>
1496
 
<DT><U>Function:</U> double <B>gsl_ran_dirichlet_lnpdf</B> <I>(size_t <VAR>K</VAR>, const double <VAR>alpha</VAR>[], const double <VAR>theta</VAR>[])</I>
1497
 
<DD><A NAME="IDX1632"></A>
1498
 
This function computes the logarithm of the probability density 
1499
 
p(\theta_1, ... , \theta_K)
1500
 
for a Dirichlet distribution with parameters 
1501
 
<VAR>alpha</VAR>[<VAR>K</VAR>].
1502
 
</DL>
1503
 
 
1504
 
</P>
1505
 
 
1506
 
 
1507
 
<H2><A NAME="SEC314" HREF="gsl-ref_toc.html#TOC314">General Discrete Distributions</A></H2>
1508
 
 
1509
 
<P>
1510
 
Given K discrete events with different probabilities P[k],
1511
 
produce a random value k consistent with its probability.
1512
 
 
1513
 
</P>
1514
 
<P>
1515
 
The obvious way to do this is to preprocess the probability list by
1516
 
generating a cumulative probability array with K+1 elements:
1517
 
 
1518
 
</P>
1519
 
 
1520
 
<PRE class="example">
1521
 
  C[0] = 0 
1522
 
C[k+1] = C[k]+P[k].
1523
 
</PRE>
1524
 
 
1525
 
<P>
1526
 
Note that this construction produces C[K]=1.  Now choose a
1527
 
uniform deviate u between 0 and 1, and find the value of k
1528
 
such that 
1529
 
C[k] &#60;= u &#60; C[k+1].  
1530
 
Although this in principle requires of order \log K steps per
1531
 
random number generation, they are fast steps, and if you use something
1532
 
like \lfloor uK \rfloor as a starting point, you can often do
1533
 
pretty well.
1534
 
 
1535
 
</P>
1536
 
<P>
1537
 
But faster methods have been devised.  Again, the idea is to preprocess
1538
 
the probability list, and save the result in some form of lookup table;
1539
 
then the individual calls for a random discrete event can go rapidly.
1540
 
An approach invented by G. Marsaglia (Generating discrete random numbers
1541
 
in a computer, Comm ACM 6, 37-38 (1963)) is very clever, and readers
1542
 
interested in examples of good algorithm design are directed to this
1543
 
short and well-written paper.  Unfortunately, for large K,
1544
 
Marsaglia's lookup table can be quite large.  
1545
 
 
1546
 
</P>
1547
 
<P>
1548
 
A much better approach is due to Alastair J. Walker (An efficient method
1549
 
for generating discrete random variables with general distributions, ACM
1550
 
Trans on Mathematical Software 3, 253-256 (1977); see also Knuth, v2,
1551
 
3rd ed, p120-121,139).  This requires two lookup tables, one floating
1552
 
point and one integer, but both only of size K.  After
1553
 
preprocessing, the random numbers are generated in O(1) time, even for
1554
 
large K.  The preprocessing suggested by Walker requires
1555
 
O(K^2) effort, but that is not actually necessary, and the
1556
 
implementation provided here only takes O(K) effort.  In general,
1557
 
more preprocessing leads to faster generation of the individual random
1558
 
numbers, but a diminishing return is reached pretty early.  Knuth points
1559
 
out that the optimal preprocessing is combinatorially difficult for
1560
 
large K.
1561
 
 
1562
 
</P>
1563
 
<P>
1564
 
This method can be used to speed up some of the discrete random number
1565
 
generators below, such as the binomial distribution.  To use it for
1566
 
something like the Poisson Distribution, a modification would have to
1567
 
be made, since it only takes a finite set of K outcomes.
1568
 
 
1569
 
</P>
1570
 
<P>
1571
 
<DL>
1572
 
<DT><U>Function:</U> gsl_ran_discrete_t * <B>gsl_ran_discrete_preproc</B> <I>(size_t <VAR>K</VAR>, const double * <VAR>P</VAR>)</I>
1573
 
<DD><A NAME="IDX1633"></A>
1574
 
<A NAME="IDX1634"></A>
1575
 
<A NAME="IDX1635"></A>
1576
 
This function returns a pointer to a structure that contains the lookup
1577
 
table for the discrete random number generator.  The array <VAR>P</VAR>[] contains
1578
 
the probabilities of the discrete events; these array elements must all be 
1579
 
positive, but they needn't add up to one (so you can think of them more
1580
 
generally as "weights")---the preprocessor will normalize appropriately.
1581
 
This return value is used
1582
 
as an argument for the <CODE>gsl_ran_discrete</CODE> function below.
1583
 
</DL>
1584
 
 
1585
 
</P>
1586
 
<P>
1587
 
<DL>
1588
 
<DT><U>Random:</U> size_t <B>gsl_ran_discrete</B> <I>(const gsl_rng * <VAR>r</VAR>, const gsl_ran_discrete_t * <VAR>g</VAR>)</I>
1589
 
<DD><A NAME="IDX1636"></A>
1590
 
<A NAME="IDX1637"></A>
1591
 
After the preprocessor, above, has been called, you use this function to
1592
 
get the discrete random numbers.
1593
 
</DL>
1594
 
 
1595
 
</P>
1596
 
<P>
1597
 
<DL>
1598
 
<DT><U>Function:</U> double <B>gsl_ran_discrete_pdf</B> <I>(size_t <VAR>k</VAR>, const gsl_ran_discrete_t * <VAR>g</VAR>)</I>
1599
 
<DD><A NAME="IDX1638"></A>
1600
 
<A NAME="IDX1639"></A>
1601
 
Returns the probability P[k] of observing the variable <VAR>k</VAR>.
1602
 
Since P[k] is not stored as part of the lookup table, it must be
1603
 
recomputed; this computation takes O(K), so if <VAR>K</VAR> is large
1604
 
and you care about the original array P[k] used to create the
1605
 
lookup table, then you should just keep this original array P[k]
1606
 
around.
1607
 
</DL>
1608
 
 
1609
 
</P>
1610
 
<P>
1611
 
<DL>
1612
 
<DT><U>Function:</U> void <B>gsl_ran_discrete_free</B> <I>(gsl_ran_discrete_t * <VAR>g</VAR>)</I>
1613
 
<DD><A NAME="IDX1640"></A>
1614
 
<A NAME="IDX1641"></A>
1615
 
De-allocates the lookup table pointed to by <VAR>g</VAR>.
1616
 
</DL>
1617
 
 
1618
 
</P>
1619
 
 
1620
 
 
1621
 
<H2><A NAME="SEC315" HREF="gsl-ref_toc.html#TOC315">The Poisson Distribution</A></H2>
1622
 
<P>
1623
 
<DL>
1624
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_poisson</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>mu</VAR>)</I>
1625
 
<DD><A NAME="IDX1642"></A>
1626
 
<A NAME="IDX1643"></A>
1627
 
This function returns a random integer from the Poisson distribution
1628
 
with mean <VAR>mu</VAR>.  The probability distribution for Poisson variates is,
1629
 
 
1630
 
</P>
1631
 
 
1632
 
<PRE class="example">
1633
 
p(k) = {\mu^k \over k!} \exp(-\mu)
1634
 
</PRE>
1635
 
 
1636
 
<P>
1637
 
for 
1638
 
k &#62;= 0.
1639
 
</DL>
1640
 
 
1641
 
</P>
1642
 
<P>
1643
 
<DL>
1644
 
<DT><U>Function:</U> double <B>gsl_ran_poisson_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>mu</VAR>)</I>
1645
 
<DD><A NAME="IDX1644"></A>
1646
 
This function computes the probability p(k) of obtaining  <VAR>k</VAR>
1647
 
from a Poisson distribution with mean <VAR>mu</VAR>, using the formula
1648
 
given above.
1649
 
</DL>
1650
 
 
1651
 
</P>
1652
 
<P>
1653
 
 
1654
 
 
1655
 
 
1656
 
<H2><A NAME="SEC316" HREF="gsl-ref_toc.html#TOC316">The Bernoulli Distribution</A></H2>
1657
 
<P>
1658
 
<DL>
1659
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_bernoulli</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>)</I>
1660
 
<DD><A NAME="IDX1645"></A>
1661
 
<A NAME="IDX1646"></A>
1662
 
This function returns either 0 or 1, the result of a Bernoulli trial
1663
 
with probability <VAR>p</VAR>.  The probability distribution for a Bernoulli
1664
 
trial is,
1665
 
 
1666
 
</P>
1667
 
 
1668
 
<PRE class="example">
1669
 
p(0) = 1 - p
1670
 
p(1) = p
1671
 
</PRE>
1672
 
 
1673
 
</DL>
1674
 
 
1675
 
<P>
1676
 
<DL>
1677
 
<DT><U>Function:</U> double <B>gsl_ran_bernoulli_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>)</I>
1678
 
<DD><A NAME="IDX1647"></A>
1679
 
This function computes the probability p(k) of obtaining
1680
 
<VAR>k</VAR> from a Bernoulli distribution with probability parameter
1681
 
<VAR>p</VAR>, using the formula given above.
1682
 
</DL>
1683
 
 
1684
 
</P>
1685
 
<P>
1686
 
 
1687
 
 
1688
 
 
1689
 
<H2><A NAME="SEC317" HREF="gsl-ref_toc.html#TOC317">The Binomial Distribution</A></H2>
1690
 
<P>
1691
 
<DL>
1692
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_binomial</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>, unsigned int <VAR>n</VAR>)</I>
1693
 
<DD><A NAME="IDX1648"></A>
1694
 
<A NAME="IDX1649"></A>
1695
 
This function returns a random integer from the binomial distribution,
1696
 
the number of successes in <VAR>n</VAR> independent trials with probability
1697
 
<VAR>p</VAR>.  The probability distribution for binomial variates is,
1698
 
 
1699
 
</P>
1700
 
 
1701
 
<PRE class="example">
1702
 
p(k) = {n! \over k! (n-k)! } p^k (1-p)^{n-k}
1703
 
</PRE>
1704
 
 
1705
 
<P>
1706
 
for 
1707
 
0 &#60;= k &#60;= n.
1708
 
</DL>
1709
 
 
1710
 
</P>
1711
 
<P>
1712
 
<DL>
1713
 
<DT><U>Function:</U> double <B>gsl_ran_binomial_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>, unsigned int <VAR>n</VAR>)</I>
1714
 
<DD><A NAME="IDX1650"></A>
1715
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1716
 
from a binomial distribution with parameters <VAR>p</VAR> and <VAR>n</VAR>, using
1717
 
the formula given above.
1718
 
</DL>
1719
 
 
1720
 
</P>
1721
 
<P>
1722
 
 
1723
 
 
1724
 
 
1725
 
<H2><A NAME="SEC318" HREF="gsl-ref_toc.html#TOC318">The Multinomial Distribution</A></H2>
1726
 
<P>
1727
 
<DL>
1728
 
<DT><U>Random:</U> void <B>gsl_ran_multinomial</B> <I>(const gsl_rng * <VAR>r</VAR>, size_t <VAR>K</VAR>, unsigned int <VAR>N</VAR>, const double <VAR>p</VAR>[], unsigned int <VAR>n</VAR>[])</I>
1729
 
<DD><A NAME="IDX1651"></A>
1730
 
<A NAME="IDX1652"></A>
1731
 
 
1732
 
</P>
1733
 
<P>
1734
 
This function returns an array of <VAR>K</VAR> random variates from a 
1735
 
multinomial distribution. The distribution function is,
1736
 
 
1737
 
</P>
1738
 
 
1739
 
<PRE class="example">
1740
 
P(n_1, n_2, ..., n_K) = 
1741
 
  (N!/(n_1! n_2! ... n_K!)) p_1^n_1 p_2^n_2 ... p_K^n_K
1742
 
</PRE>
1743
 
 
1744
 
<P>
1745
 
where 
1746
 
(n_1, n_2, ..., n_K) 
1747
 
are nonnegative integers with 
1748
 
sum_{k=1}^K n_k = N,
1749
 
and
1750
 
(p_1, p_2, ..., p_K)
1751
 
is a probability distribution with \sum p_i = 1.  
1752
 
If the array <VAR>p</VAR>[<VAR>K</VAR>] is not normalized then its entries will be
1753
 
treated as weights and normalized appropriately.
1754
 
 
1755
 
</P>
1756
 
<P>
1757
 
Random variates are generated using the conditional binomial method (see
1758
 
C.S. David, <CITE>The computer generation of multinomial random
1759
 
variates</CITE>, Comp. Stat. Data Anal. 16 (1993) 205-217 for details).
1760
 
</DL>
1761
 
 
1762
 
</P>
1763
 
<P>
1764
 
<DL>
1765
 
<DT><U>Function:</U> double <B>gsl_ran_multinomial_pdf</B> <I>(size_t <VAR>K</VAR>, const double <VAR>p</VAR>[], const unsigned int <VAR>n</VAR>[])</I>
1766
 
<DD><A NAME="IDX1653"></A>
1767
 
This function computes the probability 
1768
 
P(n_1, n_2, ..., n_K)
1769
 
of sampling <VAR>n</VAR>[<VAR>K</VAR>] from a multinomial distribution 
1770
 
with parameters <VAR>p</VAR>[<VAR>K</VAR>], using the formula given above.
1771
 
</DL>
1772
 
 
1773
 
</P>
1774
 
<P>
1775
 
<DL>
1776
 
<DT><U>Function:</U> double <B>gsl_ran_multinomial_lnpdf</B> <I>(size_t <VAR>K</VAR>, const double <VAR>p</VAR>[], const unsigned int <VAR>n</VAR>[])</I>
1777
 
<DD><A NAME="IDX1654"></A>
1778
 
This function returns the logarithm of the probability for the
1779
 
multinomial distribution 
1780
 
P(n_1, n_2, ..., n_K) with parameters <VAR>p</VAR>[<VAR>K</VAR>].
1781
 
</DL>
1782
 
 
1783
 
</P>
1784
 
 
1785
 
 
1786
 
 
1787
 
<H2><A NAME="SEC319" HREF="gsl-ref_toc.html#TOC319">The Negative Binomial Distribution</A></H2>
1788
 
<P>
1789
 
<DL>
1790
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_negative_binomial</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>, double <VAR>n</VAR>)</I>
1791
 
<DD><A NAME="IDX1655"></A>
1792
 
<A NAME="IDX1656"></A>
1793
 
This function returns a random integer from the negative binomial
1794
 
distribution, the number of failures occurring before <VAR>n</VAR> successes
1795
 
in independent trials with probability <VAR>p</VAR> of success.  The
1796
 
probability distribution for negative binomial variates is,
1797
 
 
1798
 
</P>
1799
 
 
1800
 
<PRE class="example">
1801
 
p(k) = {\Gamma(n + k) \over \Gamma(k+1) \Gamma(n) } p^n (1-p)^k
1802
 
</PRE>
1803
 
 
1804
 
<P>
1805
 
Note that n is not required to be an integer.
1806
 
</DL>
1807
 
 
1808
 
</P>
1809
 
<P>
1810
 
<DL>
1811
 
<DT><U>Function:</U> double <B>gsl_ran_negative_binomial_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>, double <VAR>n</VAR>)</I>
1812
 
<DD><A NAME="IDX1657"></A>
1813
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1814
 
from a negative binomial distribution with parameters <VAR>p</VAR> and
1815
 
<VAR>n</VAR>, using the formula given above.
1816
 
</DL>
1817
 
 
1818
 
</P>
1819
 
<P>
1820
 
 
1821
 
 
1822
 
 
1823
 
<H2><A NAME="SEC320" HREF="gsl-ref_toc.html#TOC320">The Pascal Distribution</A></H2>
1824
 
 
1825
 
<P>
1826
 
<DL>
1827
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_pascal</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>, unsigned int <VAR>n</VAR>)</I>
1828
 
<DD><A NAME="IDX1658"></A>
1829
 
This function returns a random integer from the Pascal distribution.  The
1830
 
Pascal distribution is simply a negative binomial distribution with an
1831
 
integer value of n.
1832
 
 
1833
 
</P>
1834
 
 
1835
 
<PRE class="example">
1836
 
p(k) = {(n + k - 1)! \over k! (n - 1)! } p^n (1-p)^k
1837
 
</PRE>
1838
 
 
1839
 
<P>
1840
 
for 
1841
 
k &#62;= 0
1842
 
</DL>
1843
 
 
1844
 
</P>
1845
 
<P>
1846
 
<DL>
1847
 
<DT><U>Function:</U> double <B>gsl_ran_pascal_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>, unsigned int <VAR>n</VAR>)</I>
1848
 
<DD><A NAME="IDX1659"></A>
1849
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1850
 
from a Pascal distribution with parameters <VAR>p</VAR> and
1851
 
<VAR>n</VAR>, using the formula given above.
1852
 
</DL>
1853
 
 
1854
 
</P>
1855
 
<P>
1856
 
 
1857
 
 
1858
 
 
1859
 
<H2><A NAME="SEC321" HREF="gsl-ref_toc.html#TOC321">The Geometric Distribution</A></H2>
1860
 
<P>
1861
 
<DL>
1862
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_geometric</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>)</I>
1863
 
<DD><A NAME="IDX1660"></A>
1864
 
<A NAME="IDX1661"></A>
1865
 
This function returns a random integer from the geometric distribution,
1866
 
the number of independent trials with probability <VAR>p</VAR> until the
1867
 
first success.  The probability distribution for geometric variates
1868
 
is,
1869
 
 
1870
 
</P>
1871
 
 
1872
 
<PRE class="example">
1873
 
p(k) =  p (1-p)^(k-1)
1874
 
</PRE>
1875
 
 
1876
 
<P>
1877
 
for 
1878
 
k &#62;= 1.
1879
 
</DL>
1880
 
 
1881
 
</P>
1882
 
<P>
1883
 
<DL>
1884
 
<DT><U>Function:</U> double <B>gsl_ran_geometric_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>)</I>
1885
 
<DD><A NAME="IDX1662"></A>
1886
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1887
 
from a geometric distribution with probability parameter <VAR>p</VAR>, using
1888
 
the formula given above.
1889
 
</DL>
1890
 
 
1891
 
</P>
1892
 
<P>
1893
 
 
1894
 
 
1895
 
 
1896
 
<H2><A NAME="SEC322" HREF="gsl-ref_toc.html#TOC322">The Hypergeometric Distribution</A></H2>
1897
 
<P>
1898
 
<A NAME="IDX1663"></A>
1899
 
<DL>
1900
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_hypergeometric</B> <I>(const gsl_rng * <VAR>r</VAR>, unsigned int <VAR>n1</VAR>, unsigned int <VAR>n2</VAR>, unsigned int <VAR>t</VAR>)</I>
1901
 
<DD><A NAME="IDX1664"></A>
1902
 
<A NAME="IDX1665"></A>
1903
 
This function returns a random integer from the hypergeometric
1904
 
distribution.  The probability distribution for hypergeometric
1905
 
random variates is,
1906
 
 
1907
 
</P>
1908
 
 
1909
 
<PRE class="example">
1910
 
p(k) =  C(n_1, k) C(n_2, t - k) / C(n_1 + n_2, t)
1911
 
</PRE>
1912
 
 
1913
 
<P>
1914
 
where C(a,b) = a!/(b!(a-b)!) and 
1915
 
t &#60;= n_1 + n_2.  The
1916
 
domain of k is 
1917
 
max(0,t-n_2), ..., min(t,n_1).
1918
 
</DL>
1919
 
 
1920
 
</P>
1921
 
<P>
1922
 
<DL>
1923
 
<DT><U>Function:</U> double <B>gsl_ran_hypergeometric_pdf</B> <I>(unsigned int <VAR>k</VAR>, unsigned int <VAR>n1</VAR>, unsigned int <VAR>n2</VAR>, unsigned int <VAR>t</VAR>)</I>
1924
 
<DD><A NAME="IDX1666"></A>
1925
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1926
 
from a hypergeometric distribution with parameters <VAR>n1</VAR>, <VAR>n2</VAR>,
1927
 
<VAR>t</VAR>, using the formula given above.
1928
 
</DL>
1929
 
 
1930
 
</P>
1931
 
<P>
1932
 
 
1933
 
 
1934
 
 
1935
 
<H2><A NAME="SEC323" HREF="gsl-ref_toc.html#TOC323">The Logarithmic Distribution</A></H2>
1936
 
<P>
1937
 
<DL>
1938
 
<DT><U>Random:</U> unsigned int <B>gsl_ran_logarithmic</B> <I>(const gsl_rng * <VAR>r</VAR>, double <VAR>p</VAR>)</I>
1939
 
<DD><A NAME="IDX1667"></A>
1940
 
<A NAME="IDX1668"></A>
1941
 
This function returns a random integer from the logarithmic
1942
 
distribution.  The probability distribution for logarithmic random variates
1943
 
is,
1944
 
 
1945
 
</P>
1946
 
 
1947
 
<PRE class="example">
1948
 
p(k) = {-1 \over \log(1-p)} {(p^k \over k)}
1949
 
</PRE>
1950
 
 
1951
 
<P>
1952
 
for 
1953
 
k &#62;= 1.
1954
 
</DL>
1955
 
 
1956
 
</P>
1957
 
<P>
1958
 
<DL>
1959
 
<DT><U>Function:</U> double <B>gsl_ran_logarithmic_pdf</B> <I>(unsigned int <VAR>k</VAR>, double <VAR>p</VAR>)</I>
1960
 
<DD><A NAME="IDX1669"></A>
1961
 
This function computes the probability p(k) of obtaining <VAR>k</VAR>
1962
 
from a logarithmic distribution with probability parameter <VAR>p</VAR>,
1963
 
using the formula given above.
1964
 
</DL>
1965
 
 
1966
 
</P>
1967
 
<P>
1968
 
 
1969
 
 
1970
 
 
1971
 
<H2><A NAME="SEC324" HREF="gsl-ref_toc.html#TOC324">Shuffling and Sampling</A></H2>
1972
 
 
1973
 
<P>
1974
 
The following functions allow the shuffling and sampling of a set of
1975
 
objects.  The algorithms rely on a random number generator as a source of
1976
 
randomness and a poor quality generator can lead to correlations in the
1977
 
output.  In particular it is important to avoid generators with a short
1978
 
period.  For more information see Knuth, v2, 3rd ed, Section 3.4.2,
1979
 
"Random Sampling and Shuffling".
1980
 
 
1981
 
</P>
1982
 
<P>
1983
 
<DL>
1984
 
<DT><U>Random:</U> void <B>gsl_ran_shuffle</B> <I>(const gsl_rng * <VAR>r</VAR>, void * <VAR>base</VAR>, size_t <VAR>n</VAR>, size_t <VAR>size</VAR>)</I>
1985
 
<DD><A NAME="IDX1670"></A>
1986
 
 
1987
 
</P>
1988
 
<P>
1989
 
This function randomly shuffles the order of <VAR>n</VAR> objects, each of
1990
 
size <VAR>size</VAR>, stored in the array <VAR>base</VAR>[0..<VAR>n</VAR>-1].  The
1991
 
output of the random number generator <VAR>r</VAR> is used to produce the
1992
 
permutation.  The algorithm generates all possible n!
1993
 
permutations with equal probability, assuming a perfect source of random
1994
 
numbers.
1995
 
 
1996
 
</P>
1997
 
<P>
1998
 
The following code shows how to shuffle the numbers from 0 to 51,
1999
 
 
2000
 
</P>
2001
 
 
2002
 
<PRE class="example">
2003
 
int a[52];
2004
 
 
2005
 
for (i = 0; i &#60; 52; i++)
2006
 
  {
2007
 
    a[i] = i;
2008
 
  }
2009
 
 
2010
 
gsl_ran_shuffle (r, a, 52, sizeof (int));
2011
 
</PRE>
2012
 
 
2013
 
</DL>
2014
 
 
2015
 
<P>
2016
 
<DL>
2017
 
<DT><U>Random:</U> int <B>gsl_ran_choose</B> <I>(const gsl_rng * <VAR>r</VAR>, void * <VAR>dest</VAR>, size_t <VAR>k</VAR>, void * <VAR>src</VAR>, size_t <VAR>n</VAR>, size_t <VAR>size</VAR>)</I>
2018
 
<DD><A NAME="IDX1671"></A>
2019
 
This function fills the array <VAR>dest</VAR>[k] with <VAR>k</VAR> objects taken
2020
 
randomly from the <VAR>n</VAR> elements of the array
2021
 
<VAR>src</VAR>[0..<VAR>n</VAR>-1].  The objects are each of size <VAR>size</VAR>.  The
2022
 
output of the random number generator <VAR>r</VAR> is used to make the
2023
 
selection.  The algorithm ensures all possible samples are equally
2024
 
likely, assuming a perfect source of randomness.
2025
 
 
2026
 
</P>
2027
 
<P>
2028
 
The objects are sampled <EM>without</EM> replacement, thus each object can
2029
 
only appear once in <VAR>dest</VAR>[k].  It is required that <VAR>k</VAR> be less
2030
 
than or equal to <CODE>n</CODE>.  The objects in <VAR>dest</VAR> will be in the
2031
 
same relative order as those in <VAR>src</VAR>.  You will need to call
2032
 
<CODE>gsl_ran_shuffle(r, dest, n, size)</CODE> if you want to randomize the
2033
 
order.
2034
 
 
2035
 
</P>
2036
 
<P>
2037
 
The following code shows how to select a random sample of three unique
2038
 
numbers from the set 0 to 99,
2039
 
 
2040
 
</P>
2041
 
 
2042
 
<PRE class="example">
2043
 
double a[3], b[100];
2044
 
 
2045
 
for (i = 0; i &#60; 100; i++)
2046
 
  {
2047
 
    b[i] = (double) i;
2048
 
  }
2049
 
 
2050
 
gsl_ran_choose (r, a, 3, b, 100, sizeof (double));
2051
 
</PRE>
2052
 
 
2053
 
</DL>
2054
 
 
2055
 
<P>
2056
 
<DL>
2057
 
<DT><U>Random:</U> void <B>gsl_ran_sample</B> <I>(const gsl_rng * <VAR>r</VAR>, void * <VAR>dest</VAR>, size_t <VAR>k</VAR>, void * <VAR>src</VAR>, size_t <VAR>n</VAR>, size_t <VAR>size</VAR>)</I>
2058
 
<DD><A NAME="IDX1672"></A>
2059
 
This function is like <CODE>gsl_ran_choose</CODE> but samples <VAR>k</VAR> items
2060
 
from the original array of <VAR>n</VAR> items <VAR>src</VAR> with replacement, so
2061
 
the same object can appear more than once in the output sequence
2062
 
<VAR>dest</VAR>.  There is no requirement that <VAR>k</VAR> be less than <VAR>n</VAR>
2063
 
in this case.
2064
 
</DL>
2065
 
 
2066
 
</P>
2067
 
 
2068
 
 
2069
 
 
2070
 
<H2><A NAME="SEC325" HREF="gsl-ref_toc.html#TOC325">Examples</A></H2>
2071
 
 
2072
 
<P>
2073
 
The following program demonstrates the use of a random number generator
2074
 
to produce variates from a distribution.  It prints 10 samples from the
2075
 
Poisson distribution with a mean of 3.
2076
 
 
2077
 
</P>
2078
 
 
2079
 
<PRE class="example">
2080
 
#include &#60;stdio.h&#62;
2081
 
#include &#60;gsl/gsl_rng.h&#62;
2082
 
#include &#60;gsl/gsl_randist.h&#62;
2083
 
 
2084
 
int
2085
 
main (void)
2086
 
{
2087
 
  const gsl_rng_type * T;
2088
 
  gsl_rng * r;
2089
 
 
2090
 
  int i, n = 10;
2091
 
  double mu = 3.0;
2092
 
 
2093
 
  /* create a generator chosen by the 
2094
 
     environment variable GSL_RNG_TYPE */
2095
 
 
2096
 
  gsl_rng_env_setup();
2097
 
 
2098
 
  T = gsl_rng_default;
2099
 
  r = gsl_rng_alloc (T);
2100
 
 
2101
 
  /* print n random variates chosen from 
2102
 
     the poisson distribution with mean 
2103
 
     parameter mu */
2104
 
 
2105
 
  for (i = 0; i &#60; n; i++) 
2106
 
    {
2107
 
      unsigned int k = gsl_ran_poisson (r, mu);
2108
 
      printf (" %u", k);
2109
 
    }
2110
 
 
2111
 
  printf ("\n");
2112
 
  return 0;
2113
 
}
2114
 
</PRE>
2115
 
 
2116
 
<P>
2117
 
If the library and header files are installed under <TT>'/usr/local'</TT>
2118
 
(the default location) then the program can be compiled with these
2119
 
options,
2120
 
 
2121
 
</P>
2122
 
 
2123
 
<PRE class="example">
2124
 
gcc demo.c -lgsl -lgslcblas -lm
2125
 
</PRE>
2126
 
 
2127
 
<P>
2128
 
Here is the output of the program,
2129
 
 
2130
 
</P>
2131
 
 
2132
 
<PRE class="example">
2133
 
$ ./a.out 
2134
 
 2 5 5 2 1 0 3 4 1 1
2135
 
</PRE>
2136
 
 
2137
 
<P>
2138
 
The variates depend on the seed used by the generator.  The seed for the
2139
 
default generator type <CODE>gsl_rng_default</CODE> can be changed with the
2140
 
<CODE>GSL_RNG_SEED</CODE> environment variable to produce a different stream
2141
 
of variates,
2142
 
 
2143
 
</P>
2144
 
 
2145
 
<PRE class="example">
2146
 
$ GSL_RNG_SEED=123 ./a.out 
2147
 
GSL_RNG_SEED=123
2148
 
 4 5 6 3 3 1 4 2 5 5
2149
 
</PRE>
2150
 
 
2151
 
<P>
2152
 
The following program generates a random walk in two dimensions.
2153
 
 
2154
 
</P>
2155
 
 
2156
 
<PRE class="example">
2157
 
#include &#60;stdio.h&#62;
2158
 
#include &#60;gsl/gsl_rng.h&#62;
2159
 
#include &#60;gsl/gsl_randist.h&#62;
2160
 
 
2161
 
int
2162
 
main (void)
2163
 
{
2164
 
  int i;
2165
 
  double x = 0, y = 0, dx, dy;
2166
 
 
2167
 
  const gsl_rng_type * T;
2168
 
  gsl_rng * r;
2169
 
 
2170
 
  gsl_rng_env_setup();
2171
 
  T = gsl_rng_default;
2172
 
  r = gsl_rng_alloc (T);
2173
 
 
2174
 
  printf ("%g %g\n", x, y);
2175
 
 
2176
 
  for (i = 0; i &#60; 10; i++)
2177
 
    {
2178
 
      gsl_ran_dir_2d (r, &#38;dx, &#38;dy);
2179
 
      x += dx; y += dy; 
2180
 
      printf ("%g %g\n", x, y);
2181
 
    }
2182
 
  return 0;
2183
 
}
2184
 
</PRE>
2185
 
 
2186
 
<P>
2187
 
Example output from the program, three 10-step random walks from the origin.
2188
 
 
2189
 
</P>
2190
 
<P>
2191
 
 
2192
 
<P>
2193
 
The following program computes the upper and lower cumulative
2194
 
distribution functions for the standard normal distribution at
2195
 
x=2.
2196
 
 
2197
 
</P>
2198
 
 
2199
 
<PRE class="example">
2200
 
#include &#60;stdio.h&#62;
2201
 
#include &#60;gsl/gsl_cdf.h&#62;
2202
 
 
2203
 
int
2204
 
main (void)
2205
 
{
2206
 
  double P, Q;
2207
 
  double x = 2.0;
2208
 
 
2209
 
  P = gsl_cdf_ugaussian_P (x);
2210
 
  printf ("prob(x &#60; %f) = %f\n", x, P);
2211
 
 
2212
 
  Q = gsl_cdf_ugaussian_Q (x);
2213
 
  printf ("prob(x &#62; %f) = %f\n", x, Q);
2214
 
 
2215
 
  x = gsl_cdf_ugaussian_Pinv (P);
2216
 
  printf ("Pinv(%f) = %f\n", P, x);
2217
 
 
2218
 
  x = gsl_cdf_ugaussian_Qinv (Q);
2219
 
  printf ("Qinv(%f) = %f\n", Q, x);
2220
 
 
2221
 
  return 0;
2222
 
}
2223
 
</PRE>
2224
 
 
2225
 
<P>
2226
 
Here is the output of the program,
2227
 
 
2228
 
</P>
2229
 
 
2230
 
<PRE class="example">
2231
 
prob(x &#60; 2.000000) = 0.977250
2232
 
prob(x &#62; 2.000000) = 0.022750
2233
 
Pinv(0.977250) = 2.000000
2234
 
Qinv(0.022750) = 2.000000
2235
 
</PRE>
2236
 
 
2237
 
 
2238
 
 
2239
 
<H2><A NAME="SEC326" HREF="gsl-ref_toc.html#TOC326">References and Further Reading</A></H2>
2240
 
 
2241
 
<P>
2242
 
For an encyclopaedic coverage of the subject readers are advised to
2243
 
consult the book <CITE>Non-Uniform Random Variate Generation</CITE> by Luc
2244
 
Devroye.  It covers every imaginable distribution and provides hundreds
2245
 
of algorithms.
2246
 
 
2247
 
</P>
2248
 
 
2249
 
<UL class="itemize">
2250
 
<LI>
2251
 
 
2252
 
Luc Devroye, <CITE>Non-Uniform Random Variate Generation</CITE>,
2253
 
Springer-Verlag, ISBN 0-387-96305-7.
2254
 
</UL>
2255
 
 
2256
 
<P>
2257
 
The subject of random variate generation is also reviewed by Knuth, who
2258
 
describes algorithms for all the major distributions.
2259
 
 
2260
 
</P>
2261
 
 
2262
 
<UL class="itemize">
2263
 
<LI>
2264
 
 
2265
 
Donald E. Knuth, <CITE>The Art of Computer Programming: Seminumerical
2266
 
Algorithms</CITE> (Vol 2, 3rd Ed, 1997), Addison-Wesley, ISBN 0201896842.
2267
 
</UL>
2268
 
 
2269
 
<P>
2270
 
The Particle Data Group provides a short review of techniques for
2271
 
generating distributions of random numbers in the "Monte Carlo"
2272
 
section of its Annual Review of Particle Physics.
2273
 
 
2274
 
</P>
2275
 
 
2276
 
<UL class="itemize">
2277
 
<LI>
2278
 
 
2279
 
<CITE>Review of Particle Properties</CITE>
2280
 
R.M. Barnett et al., Physical Review D54, 1 (1996)
2281
 
<A HREF="http://pdg.lbl.gov/">http://pdg.lbl.gov/</A>.
2282
 
</UL>
2283
 
 
2284
 
<P>
2285
 
The Review of Particle Physics is available online in postscript and pdf
2286
 
format.
2287
 
 
2288
 
</P>
2289
 
<P>
2290
 
An overview of methods used to compute cumulative distribution functions
2291
 
can be found in <CITE>Statistical Computing</CITE> by W.J. Kennedy and
2292
 
J.E. Gentle. Another general reference is <CITE>Elements of Statistical
2293
 
Computing</CITE> by R.A. Thisted.
2294
 
 
2295
 
</P>
2296
 
 
2297
 
<UL class="itemize">
2298
 
<LI>
2299
 
 
2300
 
William E. Kennedy and James E. Gentle, <CITE>Statistical Computing</CITE> (1980),
2301
 
Marcel Dekker, ISBN 0-8247-6898-1.
2302
 
</UL>
2303
 
 
2304
 
 
2305
 
<UL class="itemize">
2306
 
<LI>
2307
 
 
2308
 
Ronald A. Thisted, <CITE>Elements of Statistical Computing</CITE> (1988), 
2309
 
Chapman &#38; Hall, ISBN 0-412-01371-1.
2310
 
</UL>
2311
 
 
2312
 
<P>
2313
 
The cumulative distribution functions for the Gaussian distribution
2314
 
are based on the following papers,
2315
 
 
2316
 
</P>
2317
 
 
2318
 
<UL class="itemize">
2319
 
<LI>
2320
 
 
2321
 
<CITE>Rational Chebyshev Approximations Using Linear Equations</CITE>,
2322
 
W.J. Cody, W. Fraser, J.F. Hart. Numerische Mathematik 12, 242-251 (1968).
2323
 
</UL>
2324
 
 
2325
 
 
2326
 
<UL class="itemize">
2327
 
<LI>
2328
 
 
2329
 
<CITE>Rational Chebyshev Approximations for the Error Function</CITE>,
2330
 
W.J. Cody. Mathematics of Computation 23, n107, 631-637 (July 1969).
2331
 
</UL>
2332
 
 
2333
 
<P><HR><P>
2334
 
<p>Go to the <A HREF="gsl-ref_1.html">first</A>, <A HREF="gsl-ref_18.html">previous</A>, <A HREF="gsl-ref_20.html">next</A>, <A HREF="gsl-ref_50.html">last</A> section, <A HREF="gsl-ref_toc.html">table of contents</A>.
2335
 
</BODY>
2336
 
</HTML>