Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
GaussianMarginal.cpp
Go to the documentation of this file.
1#include "GaussianMarginal.h"
2
3GaussianMarginal::GaussianMarginal(double mu, double sigma, unsigned int seed)
4 : mu(mu), sigma(sigma)
5{
6 gsl_rng_set(eng_.get(), seed);
7}
8
9std::vector<double> GaussianMarginal::rvs(std::size_t n) {
10 std::vector<double> z(n);
11 for (std::size_t i = 0; i < n; ++i)
12 z[i] = mu + gsl_ran_gaussian(eng_.get(), sigma);
13 return z;
14}
15
16double GaussianMarginal::logpdf(double x) {
17 return -0.5 * (std::log(2 * PI * sigma * sigma) + std::pow((x - mu) / sigma, 2));
18}
19
20// PDFDiff GaussianMarginal::f_df_ddf(double x) {
21// double s2 = sigma * sigma;
22// double f = std::exp(-std::pow((x - mu) / sigma, 2)) / std::sqrt(2 * PI) / sigma;
23// double df = -(x - mu) / s2 * f;
24// double ddf = ((std::pow(x - mu / sigma, 2)) - 1) * f / s2;
25
26// return {f, df, ddf};
27// }
28
30 const double s2 = sigma * sigma;
31 const double z = (x - mu) / sigma;
32
33 const double f =
34 std::exp(-0.5 * z * z) / (std::sqrt(2.0 * PI) * sigma);
35
36 const double df =
37 -(x - mu) / s2 * f;
38
39 const double ddf =
40 (z * z - 1.0) / s2 * f;
41
42 return {f, df, ddf};
43}
44
45double GaussianMarginal::cdf(double x) {
46 return gsl_cdf_gaussian_P(x - mu, sigma);
47}
48
49double GaussianMarginal::ppf(double p) {
50 return mu + gsl_cdf_gaussian_Pinv(p, sigma);
51}
52
54 return mu;
55}
56
58 return sigma;
59}
PDFDiff f_df_ddf(double x) override
double std() override
Returns the mean of the distribution.
double cdf(double x) override
Evaluates the cumulative distribution function at x.
double ppf(double p) override
Evaluates the quantile function (inverse CDF).
GaussianMarginal(unsigned int seed=std::random_device{}())
std::vector< double > rvs(std::size_t n) override
Draws random samples from the marginal distribution.
double logpdf(double x) override
Evaluates the logarithm of the probability density at x.
double mean() override
Returns the mean of the distribution.
constexpr double PI
Definition constants.h:7
double f(double x)
Wilson special function f depending on x.