Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
main_rng.cpp
Go to the documentation of this file.
1#include "JointDistribution.h"
2#include "MarginalFactory.h"
3#include "CopulaFactory.h"
4#include "Math.h"
5
6using Matrix = std::vector<std::vector<double>>;
7void printUsage(const char* prog) {
8 std::cerr
9 << "Usage: " << prog << " [distribution=gaussian] [optional seed] < matrix.txt\n"
10 << " - The input matrix is read from standard input with the format:\n"
11 << " n\n"
12 << " r11 r12 ... r1n\n"
13 << " ...\n"
14 << " rn1 rn2 ... rnn\n"
15 << " - Supported distributions: gaussian | normal\n"
16 << "Example:\n"
17 << " " << prog << " gaussian 12345 < my_corr.txt\n";
18}
19
21 int n;
22 if (!(std::cin >> n) || n <= 0) {
23 throw std::runtime_error("Failed to read matrix size n.");
24 }
25 Matrix A(static_cast<size_t>(n), std::vector<double>(static_cast<size_t>(n)));
26 for (int i = 0; i < n; ++i) {
27 for (int j = 0; j < n; ++j) {
28 if (!(std::cin >> A[i][j])) {
29 throw std::runtime_error("Matrix lecture has failed.");
30 }
31 }
32 }
33 return A;
34}
35
36void printVector(const Vector& v) {
37 std::cout << std::fixed << std::setprecision(15);
38 for (size_t i = 0; i < v.size(); ++i) {
39 if (i) std::cout << " ";
40 std::cout << v[i];
41 }
42 std::cout << "\n";
43}
44
45int main(int argc, char** argv) {
46 try {
47 std::string distName = "gaussian";
48 unsigned int seed = std::random_device{}();
49
50 if (argc >= 2) {
51 std::string arg1 = argv[1];
52 if (arg1 == "-h" || arg1 == "--help") {
53 printUsage(argv[0]);
54 return 0;
55 }
56 distName = arg1;
57 }
58 if (argc >= 3) {
59 try {
60 seed = static_cast<unsigned int>(std::stoul(argv[2]));
61 } catch (...) {
62 std::cerr << "Avertissement: seed invalide, utilisation d'un seed aleatoire.\n";
63 seed = std::random_device{}();
64 }
65 }
66
68
70 // auto decomp = std::make_unique<CholeskyDecomposition>();
72
73 std::vector<std::unique_ptr<IMarginalDistribution>> truc{};
74
75 truc.emplace_back(std::move(dist));
76
77 JointDistribution generator(std::move(truc), std::move(copul));
78 Vector y = generator.sample();
79
80 printVector(y);
81 return 0;
82 } catch (const std::exception& ex) {
83 std::cerr << "Erreur: " << ex.what() << "\n";
84 printUsage(argv[0]);
85 return 1;
86 }
87}
Factory utilities for constructing copula objects from typed configurations.
@ GAUSSIAN
Gaussian copula, defined by a correlation matrix.
Joint probability distribution built from marginals and a copula.
Factory for instantiating concrete marginal distributions.
@ GAUSSIAN
Symmetric Gaussian marginal.
static std::unique_ptr< ICopula > create(CopulaType name, CopulaConfig config, unsigned int seed=std::random_device{}())
Creates a concrete copula instance.
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< std::vector< double > > Matrix
std::vector< double > Vector
void printUsage(const char *prog)
Definition main_rng.cpp:7
void printVector(const Vector &v)
Definition main_rng.cpp:36
Matrix readMatrixFromStdin()
Definition main_rng.cpp:20
Configuration object for a Gaussian copula.
Configuration object for GaussianMarginal.