ex-1: add Moyal functions
This commit is contained in:
parent
ec0af36d77
commit
2aca14f0c9
39
ex-1/moyal.c
Normal file
39
ex-1/moyal.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* 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;
|
||||||
|
}
|
23
ex-1/moyal.h
Normal file
23
ex-1/moyal.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* This file contains functions to
|
||||||
|
* compute the Moyal distribution
|
||||||
|
* PDF, CDF and QDF functions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
|
||||||
|
|
||||||
|
/* The cumulative function of the Moyal distribution.
|
||||||
|
*/
|
||||||
|
double moyal_cdf(double x, void* params);
|
||||||
|
|
||||||
|
|
||||||
|
/* The quantile function (inverse CDF) of the Moyal
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
double moyal_qdf(double p0, void* params);
|
Loading…
Reference in New Issue
Block a user