Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
SplitGaussianMarginal.cpp
Go to the documentation of this file.
2
3SplitGaussianMarginal::SplitGaussianMarginal(double mu, double sigma_p, double sigma_m, unsigned int seed)
4 : mu(mu), sigma_p(sigma_p), sigma_m(sigma_m)
5{
6 N = 2.0 / (sigma_p + sigma_m);
7 w = sigma_m / (sigma_p + sigma_m);
8
9 gsl_rng_set(eng_.get(), seed);
10}
11
12std::vector<double> SplitGaussianMarginal::rvs(std::size_t n) {
13 std::vector<double> z(n);
14 for (std::size_t i = 0; i < n; ++i)
15 z[i] = ppf(gsl_ran_flat(eng_.get(), 0, 1));
16 return z;
17}
18
20 double sigma_local = x > mu ? sigma_p : sigma_m;
21 // return std::log(N) - 0.5 * std::log(2 * PI) - 0.5 * std::pow((x - mu) / sigma_local, 2);
22 return -0.5 * std::pow((x - mu) / sigma_local, 2);
23}
24
26 double sigma_local = x > mu ? sigma_p : sigma_m;
27 double s2 = sigma_local * sigma_local;
28 double f = N / std::sqrt(2 * PI) * std::exp(-0.5 * std::pow((x - mu) / sigma_local, 2));
29 double df = -(x - mu) / s2 * f;
30 double ddf = ((std::pow(x - mu / sigma_local, 2)) - 1) * f / s2;
31
32 return {f, df, ddf};
33}
34
36 if (x > mu) {
37 return 2 * w * gsl_cdf_gaussian_P((x - mu) / sigma_m, 1);
38 } else {
39 return w + 2 * (1 - w) * (gsl_cdf_gaussian_P((x - mu) / sigma_p, 1) - 0.5);
40 }
41}
42
44 double u, s;
45 if (p > w) {
46 u = (1 - 2 * w + p) / (2 * (1 - w));
47 s = sigma_p;
48 } else {
49 u = p / (2 * w);
50 s = sigma_m;
51 }
52 return mu + s * gsl_cdf_gaussian_Pinv(u, 1);
53}
54
56 return mu + std::sqrt(2 / PI) * (sigma_p - sigma_m);
57}
58
60 return std::sqrt((1 - 2 / PI) * std::pow(sigma_p - sigma_m, 2) + sigma_p * sigma_m);
61}
Asymmetric split-Gaussian marginal distribution.
double logpdf(double x) override
Evaluates the logarithm of the probability density at x.
double cdf(double x) override
Evaluates the cumulative distribution function at x.
double std() override
Returns the standard deviation of the distribution.
double mean() override
Returns the mean of the distribution.
std::vector< double > rvs(std::size_t n) override
Draws random samples from the marginal distribution.
double ppf(double p) override
Evaluates the quantile function (inverse CDF).
SplitGaussianMarginal(double mu, double sigma_p, double sigma_m, unsigned int seed=std::random_device{}())
Constructs an asymmetric split-Gaussian marginal.
PDFDiff f_df_ddf(double x) override
constexpr double PI
Definition constants.h:7
double f(double x)
Wilson special function f depending on x.