6#ifndef THEORETICA_DISTRIBUTIONS 
    7#define THEORETICA_DISTRIBUTIONS 
    9#include "../core/real_analysis.h" 
   10#include "../algebra/vec.h" 
   12#include "../core/function.h" 
   13#include "../core/special.h" 
   31            for (
unsigned int i = 0; i < X.size(); ++i)
 
   32                res *= f(X[i], theta);
 
 
   48            for (
unsigned int i = 0; i < X.size(); ++i)
 
   49                res += 
ln(f(X[i], theta));
 
 
 
   57    namespace distribution {
 
   71            if(theta.
size() != 2) {
 
   76            return gaussian(x, theta[0], theta[1]);
 
 
   83            return pow(p, k) * 
pow(1 - p, 1 - k);
 
 
   90            if(theta.
size() != 1) {
 
   95            return bernoulli(
static_cast<unsigned int>(k), theta[0]);
 
 
  110            if(theta.
size() != 1) {
 
  115            return poisson(
static_cast<unsigned int>(k), theta[0]);
 
 
  123                pow(p, nu) * 
pow(1 - p, n - nu);
 
 
  130            if(theta.
size() != 2) {
 
  135            return binomial(
static_cast<unsigned int>(nu),
 
  136                static_cast<unsigned int>(theta[0]), theta[1]);
 
 
  142            std::vector<unsigned int> x,
 
  145            std::vector<real> p) {
 
  147            if(x.size() != p.size() || x.size() != k) {
 
  148                TH_MATH_ERROR(
"distribution::multinomial", x.size(), INVALID_ARGUMENT);
 
  154            for (
unsigned int i = 0; i < k; ++i)
 
  155                res *= 
pow(p[i], x[i]) / 
fact(x[i]);
 
 
  173                return pow(x, 
int(k / 2) - 1) * 
exp(-x / 2.0)
 
 
  196                return pow(x, 
int(k / 2) - 1) * 
exp(-x / 2.0)
 
 
  207            if(theta.
size() != 1) {
 
  212            return chi_squared(x, 
static_cast<unsigned int>(theta[0]));
 
 
  228            if(theta.
size() != 2) {
 
  233            return gamma(x, theta[0], theta[1]);
 
 
  249            if(theta.
size() != 2) {
 
  254            return beta(x, theta[0], theta[1]);
 
 
  261            const real a = 1 + (x * x / nu);
 
 
  271            if(theta.
size() != 1) {
 
  276            return student(x, 
static_cast<unsigned int>(theta[0]));
 
 
  283            return 1.0 / (2.50662827463 * sigma * x) *
 
 
  291            if(theta.
size() != 2) {
 
 
  306            return lambda * 
exp(-lambda * x);
 
 
  313            if(theta.
size() != 1) {
 
 
  340            if(theta.
size() != 1) {
 
 
  352            return 1.0 / (
PI * alpha * (1 + (
square(x - mu) / 
square(alpha))));
 
 
  359            if(theta.
size() != 2) {
 
  364            return cauchy(x, theta[0], theta[1]);
 
 
  378            if(theta.
size() != 2) {
 
 
  397            if(theta.
size() != 1) {
 
 
  409            return (1.0 / (2.0 * b)) * 
exp(-
abs(x - mu) / b);
 
 
  416            if(theta.
size() != 2) {
 
  421            return (1.0 / (2.0 * theta[1])) * 
exp(-
abs(x - theta[0]) / theta[1]);
 
 
  436            return alpha * 
powf(x_m, alpha) / 
powf(x, alpha + 1);
 
 
  443            if(theta.
size() != 2) {
 
  448            return pareto(x, theta[0], theta[1]);
 
 
  460            return pow(lambda, k) * 
pow(x, k - 1)
 
  461                    * 
exp(-lambda * x) / 
fact(k - 1);
 
 
  468            if(theta.
size() != 2) {
 
  473            return erlang(x, 
static_cast<unsigned int>(theta[0]), theta[1]);
 
 
TH_CONSTEXPR unsigned int size() const
Returns the size of the vector (N)
Definition vec.h:412
 
#define TH_MATH_ERROR(F_NAME, VALUE, EXCEPTION)
TH_MATH_ERROR is a macro which throws exceptions or modifies errno (depending on which compiling opti...
Definition error.h:225
 
real maxwell(real x, real a)
Maxwell-Boltzmann distribution.
Definition distributions.h:388
 
real binomial(unsigned int nu, unsigned int n, real p)
Binomial distribution function.
Definition distributions.h:120
 
real exponential(real x, real lambda)
Exponential distribution.
Definition distributions.h:301
 
real poisson(unsigned int k, real lambda)
Poisson distribution.
Definition distributions.h:101
 
real pareto(real x, real x_m, real alpha)
Pareto distribution.
Definition distributions.h:426
 
real bernoulli(unsigned int k, real p)
Bernoulli distribution.
Definition distributions.h:81
 
real beta(real x, real alpha, real beta)
Beta distribution density function with parameters alpha (shape) and beta (shape)
Definition distributions.h:239
 
real breit_wigner(real x, real M, real Gamma)
Breit Wigner distribution.
Definition distributions.h:369
 
real chi_squared(real x, unsigned int k)
Chi-squared distribution.
Definition distributions.h:165
 
real erlang(real x, unsigned int k, real lambda)
Erlang distribution.
Definition distributions.h:453
 
real laplace(real x, real mu, real b)
Laplace distribution.
Definition distributions.h:407
 
real student(real x, unsigned int nu)
Student's t distribution.
Definition distributions.h:259
 
real log_normal(real x, real mu, real sigma)
Log-normal distribution.
Definition distributions.h:281
 
real multinomial(std::vector< unsigned int > x, unsigned int n, unsigned int k, std::vector< real > p)
Multinomial distribution.
Definition distributions.h:141
 
real gamma(real x, real alpha, real beta)
Gamma distribution density function with parameters alpha (shape) and beta (rate)
Definition distributions.h:218
 
real cauchy(real x, real mu, real alpha)
Cauchy distribution.
Definition distributions.h:350
 
real gaussian(real x, real X, real sigma)
Gaussian distribution function.
Definition distributions.h:61
 
real rayleigh(real x, real sigma)
Rayleigh distribution.
Definition distributions.h:323
 
real beta(real x1, real x2)
Beta special function of real argument.
Definition special.h:141
 
real half_gamma(unsigned int k)
Half Gamma special function, defined as HG(n) = Gamma(n / 2) for any positive integer n.
Definition special.h:41
 
real gamma(unsigned int k)
Gamma special function of positive integer argument.
Definition special.h:23
 
real likelihood(const vec< real > &X, const vec< real > &theta, stat_function f)
Compute the likelihood of a distribution <f> with the given parameters <theta> and measures <X>
Definition distributions.h:27
 
real log_likelihood(const vec< real > &X, const vec< real > &theta, stat_function f)
Compute the log likelihood of a distribution <f> with the given parameters <theta> and measures <X>
Definition distributions.h:44
 
Main namespace of the library which contains all functions and objects.
Definition algebra.h:27
 
double real
A real number, defined as a floating point type.
Definition constants.h:198
 
TH_CONSTEXPR IntType binomial_coeff(unsigned int n, unsigned int m)
Compute the binomial coefficient.
Definition real_analysis.h:1229
 
dual2 sqrt(dual2 x)
Compute the square root of a second order dual number.
Definition dual2_functions.h:54
 
dual2 ln(dual2 x)
Compute the natural logarithm of a second order dual number.
Definition dual2_functions.h:151
 
dual2 abs(dual2 x)
Compute the absolute value of a second order dual number.
Definition dual2_functions.h:198
 
constexpr real SQRTPI
The square root of Pi.
Definition constants.h:234
 
dual2 exp(dual2 x)
Compute the exponential of a second order dual number.
Definition dual2_functions.h:138
 
real powf(real x, real a)
Approximate x elevated to a real exponent.
Definition real_analysis.h:795
 
TH_CONSTEXPR real nan()
Return a quiet NaN number in floating point representation.
Definition error.h:54
 
TH_CONSTEXPR IntType fact(unsigned int n)
Compute the factorial of n.
Definition real_analysis.h:670
 
constexpr real MACH_EPSILON
Machine epsilon for the real type.
Definition constants.h:207
 
std::function< real(real, const vec< real > &)> stat_function
Function pointer to a probability distribution function where the first argument is the variable and ...
Definition function.h:30
 
constexpr real SQRT2
The square root of 2.
Definition constants.h:261
 
dual2 square(dual2 x)
Return the square of a second order dual number.
Definition dual2_functions.h:23
 
constexpr real PI
The Pi mathematical constant.
Definition constants.h:216
 
dual2 pow(dual2 x, int n)
Compute the n-th power of a second order dual number.
Definition dual2_functions.h:41
 
dual2 cube(dual2 x)
Return the cube of a second order dual number.
Definition dual2_functions.h:29