18 int compare( std::string
name,
double v1,
double v2,
double scale = 2.0) {
26 double delta = v2 - v1;
28 if (delta < 0 ) delta = -
delta;
29 if (v1 == 0 || v2 == 0) {
40 if ( delta/d > eps && delta > eps )
47 int pr = std::cout.precision (18);
48 std::cout <<
"\nDiscrepancy in " << name.c_str() <<
"() :\n " << v1 <<
" != " << v2 <<
" discr = " << int(delta/d/eps)
49 <<
" (Allowed discrepancy is " << eps <<
")\n\n";
50 std::cout.precision (pr);
62 typedef double ( * Pdf) ( double, double, double);
63 typedef double ( * Cdf) ( double, double, double);
64 typedef double ( * Quant) ( double, double);
68 PdfFunction( Pdf pdf,
double p1 ) : fPdf(pdf), fP1(p1) {}
69 double operator() (
double x)
const {
return fPdf(x,fP1,0.0); }
76 TestFunc1(
double p1,
double s = 2) :
82 #ifndef NO_MATHCORE // skip cdf test when Mathcore is missing 84 int testCdf( Pdf f_pdf, Cdf f_cdf,
bool c =
false) {
87 double q1 = f_cdf(val, p[0],0.0);
89 PdfFunction
f(f_pdf,p[0]);
97 iret |=
compare(
"test _cdf", q1, q2, 1.0E6);
102 iret |=
compare(
"test _cdf_c", q1, q2, 1.0E6);
109 int testQuantile (Cdf f_cdf, Quant f_quantile,
bool c=
false) {
113 for (
int i = 0; i < 10; ++i) {
114 q = f_quantile(z1,p[0]);
115 z2 = f_cdf(q, p[0],0.);
117 iret |=
compare(
"test quantile", z1, z2, scale);
119 iret |=
compare(
"test quantile_c", z1, z2, scale);
134 typedef double ( * Pdf) ( double, double, double, double);
135 typedef double ( * Cdf) ( double, double, double, double);
136 typedef double ( * Quant) ( double, double, double);
140 PdfFunction( Pdf pdf,
double p1,
double p2 ) : fPdf(pdf), fP1(p1), fP2(p2) {}
141 double operator() (
double x)
const {
return fPdf(x,fP1,fP2,0.0); }
148 TestFunc2(
double p1,
double p2,
double s = 2) :
155 #ifndef NO_MATHCORE // skip cdf test when Mathcore is missing 157 int testCdf( Pdf f_pdf, Cdf f_cdf,
bool c =
false) {
160 double q1 = f_cdf(val, p[0],p[1],0.0);
162 PdfFunction
f(f_pdf,p[0],p[1]);
170 iret |=
compare(
"test _cdf", q1, q2, 1.0E6);
175 iret |=
compare(
"test _cdf_c", q1, q2, 1.0E6);
182 int testQuantile (Cdf f_cdf, Quant f_quantile,
bool c=
false) {
186 for (
int i = 0; i < 10; ++i) {
187 q = f_quantile(z1,p[0],p[1]);
188 z2 = f_cdf(q, p[0],p[1],0.0);
190 iret |=
compare(
"test quantile", z1, z2, scale);
192 iret |=
compare(
"test quantile_c", z1, z2, scale);
204 std::cout <<
"\t\t\t\t OK" << std::endl;
206 std::cout <<
"\t\t\t\t FAILED " << std::endl;
211 #define TESTDIST1(name, p1, s) {\ 214 ir |= t.testCdf( name ## _pdf , name ## _cdf );\ 215 ir |= t.testCdf( name ##_pdf , name ##_cdf_c,true);\ 216 ir |= t.testQuantile( name ## _cdf, name ##_quantile);\ 217 ir |= t.testQuantile( name ##_cdf_c, name ##_quantile_c,true);\ 221 #define TESTDIST2(name, p1, p2, s) {\ 223 TestFunc2 t(p1,p2,s);\ 224 ir |= t.testCdf( name ## _pdf , name ## _cdf );\ 225 ir |= t.testCdf( name ##_pdf , name ##_cdf_c,true);\ 226 ir |= t.testQuantile( name ## _cdf, name ##_quantile);\ 227 ir |= t.testQuantile( name ##_cdf_c, name ##_quantile_c,true);\ 236 #define TESTDIST1(name, p1, s) {\ 239 ir |= t.testQuantile( name ## _cdf, name ##_quantile);\ 240 ir |= t.testQuantile( name ##_cdf_c, name ##_quantile_c,true);\ 244 #define TESTDIST2(name, p1, p2, s) {\ 246 TestFunc2 t(p1,p2,s);\ 247 ir |= t.testQuantile( name ## _cdf, name ##_quantile);\ 248 ir |= t.testQuantile( name ##_cdf_c, name ##_quantile_c,true);\ 276 for (
int i = 0; i < 12; ++i) {
280 for (
int j = 0; j <= i; ++j) {
283 iret |=
compare(
"test cdf",q1,q2,tol);
284 iret |=
compare(
"test cdf_c",q1c,q2,tol);
292 for (
int i = 0; i < 12; ++i) {
296 for (
int j = 0; j <= i; ++j) {
299 iret |=
compare(
"test cdf",q1,q2,tol);
300 iret |=
compare(
"test cdf_c",q1c,q2,tol);
317 std::cout <<
"Poisson distrib. \t: ";
322 std::cout <<
"Binomial distrib. \t: ";
323 double p = 0.5;
int nt = 9;
327 std::cout <<
"BreitWigner distrib\t: ";
330 std::cout <<
"Cauchy distribution\t: ";
333 std::cout <<
"Exponential distrib\t: ";
336 std::cout <<
"Gaussian distribution\t: ";
339 std::cout <<
"Log-normal distribution\t: ";
342 std::cout <<
"Normal distribution\t: ";
345 std::cout <<
"Uniform distribution\t: ";
352 std::cout <<
"Chisquare distribution\t: ";
358 std::cout <<
"F distribution\t\t: ";
359 double n = 5;
double m = 6;
362 std::cout <<
"Gamma distribution\t: ";
363 double a = 1;
double b = 2;
366 std::cout <<
"t distribution\t\t: ";
370 std::cout <<
"Beta distribution\t: ";
double binomial_cdf(unsigned int k, double p, unsigned int n)
Cumulative distribution function of the Binomial distribution Lower tail of the integral of the binom...
double gaussian(const double *x, const double *p)
double IntegralUp(const IGenFunction &f, double a)
evaluate the Integral of a function f over the semi-infinite interval (a,+inf)
double beta_pdf(double x, double a, double b)
Probability density function of the beta distribution.
double mbeta_quantile_c(double x, double a, double b)
double poisson_cdf(unsigned int n, double mu)
Cumulative distribution function of the Poisson distribution Lower tail of the integral of the poisso...
double poisson_cdf_c(unsigned int n, double mu)
Complement of the cumulative distribution function of the Poisson distribution.
double binomial_cdf_c(unsigned int k, double p, unsigned int n)
Complement of the cumulative distribution function of the Binomial distribution.
double mbeta_cdf_c(double x, double a, double b, double)
double mbeta_pdf(double x, double a, double b, double)
TRObject operator()(const T1 &t1) const
Template class to wrap any C++ callable object which takes one argument i.e.
static double p2(double t, double a, double b, double c)
Class for performing numerical integration of a function in one dimension.
double beta_cdf(double x, double a, double b)
Cumulative distribution function of the beta distribution Upper tail of the integral of the beta_pdf...
int compare(std::string name, double v1, double v2, double scale=2.0)
double IntegralLow(const IGenFunction &f, double b)
evaluate the Integral of a function f over the over the semi-infinite interval (-inf,b)
int testBinomialCdf(double p, int n, double tol)
double binomial_pdf(unsigned int k, double p, unsigned int n)
Probability density function of the binomial distribution.
void SetFunction(const IGenFunction &f)
method to set the a generic integration function
double mbeta_quantile(double x, double a, double b)
static double p1(double t, double a, double b)
double beta_quantile_c(double x, double a, double b)
Inverse ( ) of the cumulative distribution function of the lower tail of the beta distribution (beta_...
int testPoissonCdf(double mu, double tol)
double mbeta_cdf(double x, double a, double b, double)
void printStatus(int iret)
double poisson_pdf(unsigned int n, double mu)
Probability density function of the Poisson distribution.
double beta_cdf_c(double x, double a, double b)
Complement of the cumulative distribution function of the beta distribution.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
def normal(shape, name=None)
#define TESTDIST2(name, p1, p2, s)
double beta_quantile(double x, double a, double b)
Inverse ( ) of the cumulative distribution function of the upper tail of the beta distribution (beta_...
#define TESTDIST1(name, p1, s)