3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2006, 2007 James Theiler, Brian Gough
4 * Copyright (C) 2006 Giulio Bottazzi
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_sf_gamma.h>
25 #include <gsl/gsl_rng.h>
26 #include <gsl/gsl_randist.h>
28 /* The exponential power probability distribution is
30 p(x) dx = (1/(2 a Gamma(1+1/b))) * exp(-|x/a|^b) dx
32 for -infty < x < infty. For b = 1 it reduces to the Laplace
35 The exponential power distribution is related to the gamma
36 distribution by E = a * pow(G(1/b),1/b), where E is an exponential
37 power variate and G is a gamma variate.
39 We use this relation for b < 1. For b >=1 we use rejection methods
40 based on the laplace and gaussian distributions which should be
41 faster. For b>4 we revert to the gamma method.
43 See P. R. Tadikamalla, "Random Sampling from the Exponential Power
44 Distribution", Journal of the American Statistical Association,
45 September 1980, Volume 75, Number 371, pages 683-686.
50 gsl_ran_exppow (const gsl_rng * r, const double a, const double b)
54 double u = gsl_rng_uniform (r);
55 double v = gsl_ran_gamma (r, 1 / b, 1.0);
56 double z = a * pow (v, 1 / b);
69 /* Laplace distribution */
70 return gsl_ran_laplace (r, a);
74 /* Use laplace distribution for rejection method, from Tadikamalla */
78 double B = pow (1 / b, 1 / b);
82 x = gsl_ran_laplace (r, B);
83 u = gsl_rng_uniform_pos (r);
84 h = -pow (fabs (x), b) + fabs (x) / B - 1 + (1 / b);
92 /* Gaussian distribution */
93 return gsl_ran_gaussian (r, a / sqrt (2.0));
97 /* Use gaussian for rejection method, from Tadikamalla */
101 double B = pow (1 / b, 1 / b);
105 x = gsl_ran_gaussian (r, B);
106 u = gsl_rng_uniform_pos (r);
107 h = -pow (fabs (x), b) + (x * x) / (2 * B * B) + (1 / b) - 0.5;
116 gsl_ran_exppow_pdf (const double x, const double a, const double b)
119 double lngamma = gsl_sf_lngamma (1 + 1 / b);
120 p = (1 / (2 * a)) * exp (-pow (fabs (x / a), b) - lngamma);