#ifndef gauss_distr_H #define gauss_distr_H /* Tools for parameters of a Gaussian distribution (with integral 1.0). */ /* Last edited on 2019-12-07 14:44:59 by jstolfi */ #include #include typedef gauss_bell_parms_t gauss_distr_parms_t; /* Parameters of a generic Gaussian distribution, namely mean {.avg} and standard deviation {.dev}. */ #define gauss_distr_HUGE_ARG (gauss_bell_HUGE_ARG) /* A value such that {|z| >= gauss_distr_HUGE_ARG} implies that the standard PDF at {z} underflows. */ #define gauss_distr_BIG_ARG (gauss_bell_BIG_ARG) /* A value such that {|z| >= gauss_distr_BIG_ARG} implies that the standard PDF at {z} is less than {10^{-16}}. */ #define gauss_distr_TINY_ARG (gauss_bell_TINY_ARG) /* A value such that {|z| <= gauss_distr_TINY_ARG} implies that the standard PDF at {z} is greater than {1 - 10^{-16}}. */ double gauss_distr_PDF(double x, double avg, double dev); /* The probability density function of a normal deviate with mean {avg} and deviation {dev}, evaluated at {x}. Namely, returns {A*exp[-((x-avg)/dev)^2/2]} where {A = 1/(|dev|*sqrt(2*PI))} is such that the integral is over all {x} is 1.0. Possibly safer and/or faster for very large or very small {x}. The sign of {dev} is ignored. If {dev} is {±INF}, returns 0 for any {x}. If {dev} is zero, returns {+INF} for {x=avg} (or {NAN} if {avg} is {±INF}) and 0 otherwise. */ double gauss_distr_CDF(double x, double avg, double dev); /* The cumulative distribution function of a Gaussian deviate with average {avg} and deviation {dev}. Namely, the integral of {gauss_distr_PDF(y, avg, dev)} for {y} from {-INF} to {x}. The sign of {dev} is ignored. If {dev} is {±INF}, returns 0 {x < +INF} and {NAN} for {x=+INF}. If {dev} is zero, returns 0 for {xavg}, and {NAN} for {x=avg}. */ double gauss_distr_integral(double x0, double x1, double avg, double dev); /* Returns the integral from {x0} to {x1} of the normalized Gaussian PDF with average {avg} and deviation {dev}. Namely, the probability that a Gaussian deviate with those parameters will be between {x0} and {x1}. The sign of {dev} is ignored. If {dev} is zero, returns {+1} if {x0