gsl_cdf__exppow.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* cdf/exppow.c
  2. *
  3. * Copyright (C) 2004 Giulio Bottazzi
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. #include "gsl__config.h"
  20. #include <math.h>
  21. #include "gsl_cdf.h"
  22. #include "gsl_sf_gamma.h"
  23. /* The exponential power density is parametrized according to
  24. p(x) dx = (1/(2 a Gamma(1 + 1/b))) * exp(-|x/a|^b) dx
  25. so that the distribution reads
  26. / x<0 0.5 - Gamma_inc_P(1/b,|x/a|^b)
  27. P(x) = | x=0 0.5
  28. \ x>0 0.5 + Gamma_inc_P(1/b,|x/a|^b)
  29. for x in (-infty,+infty) */
  30. double
  31. gsl_cdf_exppow_P (const double x, const double a, const double b)
  32. {
  33. const double u = x / a;
  34. if (u < 0)
  35. {
  36. double P = 0.5 * gsl_sf_gamma_inc_Q (1.0 / b, pow (-u, b));
  37. return P;
  38. }
  39. else
  40. {
  41. double P = 0.5 * (1.0 + gsl_sf_gamma_inc_P (1.0 / b, pow (u, b)));
  42. return P;
  43. }
  44. }
  45. double
  46. gsl_cdf_exppow_Q (const double x, const double a, const double b)
  47. {
  48. const double u = x / a;
  49. if (u < 0)
  50. {
  51. double Q = 0.5 * (1.0 + gsl_sf_gamma_inc_P (1.0 / b, pow (-u, b)));
  52. return Q;
  53. }
  54. else
  55. {
  56. double Q = 0.5 * gsl_sf_gamma_inc_Q (1.0 / b, pow (u, b));
  57. return Q;
  58. }
  59. }