summaryrefslogtreecommitdiff
path: root/gsl-1.9/cdf/exppow.c
blob: 440f5c4753b42c6d97addad6280bbd728cb03063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* cdf/exppow.c
 * 
 * Copyright (C) 2004 Giulio Bottazzi
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <config.h>
#include <math.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_sf_gamma.h>

/* The exponential power density is parametrized according to

   p(x) dx = (1/(2 a Gamma(1 + 1/b))) * exp(-|x/a|^b) dx

   so that the distribution reads

           / x<0   0.5 - Gamma_inc_P(1/b,|x/a|^b)
   P(x) = |  x=0   0.5
           \ x>0   0.5 + Gamma_inc_P(1/b,|x/a|^b)


   for x in (-infty,+infty) */

double
gsl_cdf_exppow_P (const double x, const double a, const double b)
{
  const double u = x / a;

  if (u < 0)
    {
      double P = 0.5 * gsl_sf_gamma_inc_Q (1.0 / b, pow (-u, b));
      return P;
    }
  else
    {
      double P = 0.5 * (1.0 + gsl_sf_gamma_inc_P (1.0 / b, pow (u, b)));
      return P;
    }
}

double
gsl_cdf_exppow_Q (const double x, const double a, const double b)
{
  const double u = x / a;

  if (u < 0)
    {
      double Q = 0.5 * (1.0 + gsl_sf_gamma_inc_P (1.0 / b, pow (-u, b)));
      return Q;
    }
  else
    {
      double Q = 0.5 * gsl_sf_gamma_inc_Q (1.0 / b, pow (u, b));
      return Q;
    }
}