Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
test_copulas.cpp
Go to the documentation of this file.
1#include "JointDistribution.h"
2#include "MarginalFactory.h"
3#include "CopulaFactory.h"
4#include "Matrix.h"
5#include "FlatMarginal.h"
6#include "GaussianMarginal.h"
8#include "GaussianCopula.h"
9
10int main() {
11
12 unsigned int seed = 123456789;
13
14 RealMatrix R ({
15 {1.0, 0.7},
16 {0.7, 1.0}}
17 );
18
20 c_cfg.R = R;
21 // c_cfg.nu = 4;
22
23 FlatMarginalCfg m_cfg_1 {1.0, 2.0};
24 FlatMarginalCfg m_cfg_2 {2.0, 4.0};
25
26 auto m_1 = MarginalFactory::create(MarginalType::FLAT, m_cfg_1, seed);
27 auto m_2 = MarginalFactory::create(MarginalType::FLAT, m_cfg_2, seed);
28 auto cop = CopulaFactory::create(CopulaType::GAUSSIAN, c_cfg, seed);
29
30 std::vector<std::unique_ptr<IMarginalDistribution>> marginals;
31 marginals.push_back(std::move(m_1));
32 marginals.push_back(std::move(m_2));
33
34 JointDistribution rvg(std::move(marginals), std::move(cop));
35
36 LOG_INFO("JointDistribution initialized");
37
38 // Sampling joint distribution
39 std::vector<Vector> smpl = rvg.sample(10000);
40
41 std::ofstream os;
42 os.open("sample.csv");
43
44 for (const Vector& z : smpl) {
45 os << z[0] << "," << z[1] << "\n";
46 }
47
48 os.close();
49
50 // Scanning pdf
51 double x_1 {0.0}, x_2 {1.0};
52 double dx = 1e-2;
53 double x1_max {2.0};
54 double x2_max {5.0};
55 std::size_t n1 = x1_max / dx;
56 std::size_t n2 = x2_max / dx;
57
58 printf("(%li,%li)\n", n1, n2);
59
60 os.open("logpdf.csv");
61
62 for (size_t i = 0; i < n1; i++) {
63 x_2 = 0.0;
64 for (size_t j = 0; j < n2; j++) {
65 os << x_1 << "," << x_2 << "," << rvg.logpdf({x_1, x_2}) << "\n";
66 x_2 += dx;
67 }
68 x_1 += dx;
69 }
70
71 os.close();
72
73 return 0;
74}
Factory utilities for constructing copula objects from typed configurations.
@ GAUSSIAN
Gaussian copula, defined by a correlation matrix.
Gaussian copula implementation.
Joint probability distribution built from marginals and a copula.
#define LOG_INFO(...)
Macro for logging informational messages.
Definition Logger.h:39
Factory for instantiating concrete marginal distributions.
@ FLAT
Uniform (flat) marginal on a finite interval.
Lightweight dense real-matrix utilities built on top of STL storage and GSL backends.
Asymmetric split-Gaussian marginal distribution.
static std::unique_ptr< ICopula > create(CopulaType name, CopulaConfig config, unsigned int seed=std::random_device{}())
Creates a concrete copula instance.
double logpdf(std::vector< double > x) const
Evaluates the joint log-density at a given point.
std::vector< std::vector< double > > sample(std::size_t n) const
Draws multiple samples from the joint distribution.
static std::unique_ptr< IMarginalDistribution > create(MarginalType name, MarginalConfig cfg, unsigned int seed=std::random_device{}())
Creates a concrete marginal-distribution object.
std::vector< double > Vector
Configuration object for FlatMarginal.
Configuration object for a Gaussian copula.
int main()