40 lines
942 B
C
40 lines
942 B
C
/* This file contains functions to
|
|
* compute the Moyal distribution
|
|
* PDF, CDF and QDF functions.
|
|
*/
|
|
|
|
#include <gsl/gsl_sf.h>
|
|
|
|
|
|
/* This is a wrapper needed by `moyal_cdf` and
|
|
* other optimisation functions because the GSL
|
|
* routines expect a function with parameters.
|
|
*/
|
|
double moyal_pdf(double x, void* params) {
|
|
double mu = params[0];
|
|
double sigma = params[1];
|
|
double z = (x - mu)/sigma;
|
|
return exp(-(z + exp(-z))/2) /sqrt(2*M_PI) /sigma;
|
|
}
|
|
|
|
|
|
/* The cumulative function of the Moyal distribution.
|
|
*/
|
|
double moyal_cdf(double x, void* params) {
|
|
double mu = params[0];
|
|
double sigma = params[1];
|
|
double z = (x - mu)/sigma;
|
|
return 2*(1 - gsl_cdf_gaussian_P(exp(-x/2)));
|
|
}
|
|
|
|
|
|
/* The quantile function (inverse CDF) of the Moyal
|
|
* distribution.
|
|
*/
|
|
double moyal_qdf(double p0, void* params) {
|
|
double mu = params[0];
|
|
double sigma = params[1];
|
|
double z = -2*log(gsl_cdf_gaussian_Pinv(1 - p/2));
|
|
return z*sigma + mu;
|
|
}
|