Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
example_main_adapter.cpp
Go to the documentation of this file.
1#include <iostream>
2#include <random>
3#include <gsl/gsl_cdf.h>
4
5
9#include "MCEngine.h"
10#include "Fit.h"
11#include "BToMuMuToy.h"
12// #include "LinearAlgebra.h"
13#include "MarginalFactory.h"
14#include "RvgNuisanceSampler.h"
15#include "HyperisoMaster.h"
16#include "BlockProxy.h"
17#include "StatParameterProxy.h"
21
22
23using Matrix = std::vector<std::vector<double>>;
24
25int main() {
26
28 HyperisoConfig config;
29 config.model = Model::SM;
30
31 hyp.init("lha/si_input.flha", config);
32
33 std::map<ObservableId, QCDOrder> obs_ids = {
37 };
38
39
40 std::shared_ptr<ObservableInterface> oi = std::make_shared<ObservableInterface>();
41 // for (auto oid : obs_ids) oi.add_observable(oid, QCDOrder::LO, /*add_dependencies=*/true);
42 oi->add_observables(obs_ids, true);
43
44 for (auto id : oi->get_all_ops_deps(Observables::BR_BS_MUMU)) {
45 std::cout << id << std::endl;
46 }
47
48 //Build experimental vector/covariance
49 Vec Oexp{3.52e-9, 3.52e-9, 1.3e-10};
50 Matrix SigmaO = {
51 { (1.2e-10)*(1.2e-10), -0.2*(1.2e-10)*(1.2e-10), -0.2*(1.2e-10)*(0.2e-10) },
52 { -0.2*(1.2e-10)*(1.2e-10), (1.2e-10)*(1.2e-10), 0.0 },
53 { -0.2*(1.2e-10)*(0.2e-10), 0.0, (0.2e-10)*(0.2e-10) }
54 };
55
56
57 // Nuisances
58 Vec eta_mean{0.194, 0.234, 0.0635, 0.04111, 0.00858};
59 Matrix SigmaEta = {
60 {0.010*0.010, 0,0,0,0},
61 {0, 0.010*0.010, 0,0,0},
62 {0,0, 0.014*0.014, 0,0},
63 {0,0,0, 0.00077*0.00077, 0},
64 {0,0,0,0, 0.00019*0.00019}
65 };
66
67 std::vector<ParamId> p_specs = {
68 {ParameterType::WILSON, "BCoefficients_B_SCALE_STANDARD", LhaID(3051313,4137,0,2)}, // C10
69 {ParameterType::WILSON, "BPrimeCoefficients_B_SCALE_STANDARD", LhaID(3051313,4234,0,2)} // C10'
70 };
71 std::vector<ParamId> eta_specs = {
72 {ParameterType::FLAVOR, "FCONST", /*code_fBd*/ 521},
73 {ParameterType::FLAVOR, "FCONST", /*code_fBs*/ 531},
74 {ParameterType::DECAY, "B_ll", /*code_y_s*/ 1},
75 {ParameterType::SM, "VCKM", /*code_Vts*/ LhaID(2,1)},
76 {ParameterType::SM, "VCKM", /*code_Vtd*/ LhaID(2,0)}
77 };
78
80 std::vector<ParamId> eta_specs_real;
81 Vec eta_mean_real;
82 for (auto elem : obs_ids) {
83 for (auto _ : oi->get_all_ops_deps(elem.first))
84 if (!(std::find(eta_specs_real.begin(), eta_specs_real.end(), _) != eta_specs_real.end())) {
85 eta_specs_real.push_back(_);
86 }
87 }
88
89 std::unordered_set<ParamId> good;
90
91 for (auto elem : eta_specs_real) {
92 std::cout << "FIIIRST : " << elem << std::endl;
93 good.insert(elem);
94 }
95 std::unordered_set<ParamId> truc = ParamSourcesProvider().get_all_leaf_sources(good);
96
97 std::vector<ParamId> good_all;
98
99 for (auto elem : truc) {
100 good_all.push_back(elem);
101 }
102 for (ParamId elem : truc) {
103 std::cout << "WHAAATS : " << elem << std::endl;
104 }
105 std::shared_ptr<IStatCorrelationProxy> pscp = std::make_shared<StatCorrelationProxy>();
106 std::shared_ptr<IStatParameterProxy> pspp = std::make_shared<StatParameterProxy>();
107
109 std::vector<ParamId> eta_specs_real_with_corr = ct.check_if_corr(eta_specs_real);
110
111 for (auto elem : eta_specs_real_with_corr) {
112 // std::cout << elem << std::endl;
113 eta_mean_real.push_back(spp(elem, DataType::VALUE));
114 }
115
116 Matrix SigmaEtaReal = ct.transform(eta_specs_real_with_corr);
117
118 for (int i = 0; i < eta_specs_real_with_corr.size(); i++) {
119 for (int j = 0; j < eta_specs_real_with_corr.size(); j++) {
120 std::cout << "[" << eta_specs_real_with_corr[i] << ", " << eta_specs_real_with_corr[j] << "] = " << SigmaEtaReal[i][j] << " | ";
121 // std::cout << "[" << i << ", " << j << "] = " << SigmaEtaReal[i][j] << " | ";
122 }
123 std::cout << std::endl;
124 }
125
126 std::shared_ptr<ObservableInterfaceProxy> model = std::make_shared<ObservableInterfaceProxy> (oi, p_specs, eta_specs_real_with_corr);
127
128 // model->add_observables(obs_ids);
129 std::cout << "creating RandomVectorGenerator" << std::endl;
130
131 unsigned int seed = std::random_device{}();
133 // auto decomp = std::make_unique<CholeskyDecomposition>();
135
136 std::vector<std::unique_ptr<IMarginalDistribution>> truc2{};
137
138 truc2.emplace_back(std::move(dist));
139
140 std::unique_ptr<JointDistribution> rvg = std::make_unique<JointDistribution>(std::move(truc2), std::move(copul));
141
142 std::cout << "RandomVectorGenerator created" << std::endl;
143
144 RvgNuisanceSampler sampler(eta_specs_real_with_corr, std::move(rvg));
145
146 std::cout << "Creating MonteCarloPredictor" << std::endl;
147
148 // MC prediction with pluggable sampler
149 MonteCarloEngine mc(model, sampler, {10, 0.2});
150 std::mt19937 rng(1234);
151
152 std::cout << "MonteCarloPredictor created" << std::endl;
153
154 std::map<ParamId, double> p_test{{ParamId(ParameterType::WILSON, "WILSON", 10), -4.5}, {ParamId(ParameterType::WILSON, "WILSON_p", 10), 0.0}};
155 auto sums = mc.summarize(p_test);
156
157 std::cout << "summarize ented" << std::endl;
158
159 std::cout << "Skewness[0]=" << sums.summary[0].skew << " ok=" << sums.summary[0].symmetric << std::endl;
160
161 for (auto sum : sums.summary) {
162 std::cout << "value = " << sum.mu << " +- " << sum.sigma << std::endl;
163 }
164
165 std::cout << "Now doing likelihood : " << std::endl;
166 // Likelihood/MLE/intervals
167 // SPDMatrix SO = SPDMatrix::cholesky(SigmaO);
168 // SPDMatrix SE = SPDMatrix::cholesky(SigmaEtaReal);
169 // LikelihoodContext ctx{Oexp, SO, eta_mean_real, SE};
170 // MLEstimator est(ctx, [&model](const Vec& p, const Vec& eta){ return model->predict(p, eta); }, 100);
171
172 // std::cout << "Now doing MLE : " << std::endl;
173 // Vec p0{-4.5, 0.0}; Vec eta0 = eta_mean_real;
174 // auto fr = est.fit(p0, eta0);
175
176 // std::cout << "MLE fit done: " << std::endl;
177
178 // std::cout << "MLE: C10=" << fr.p_hat[0] << ", Cp10=" << fr.p_hat[1]
179 // << ", ell_hat=" << fr.ell_hat << std::endl;
180
181 // std::cout << "finding thr95 " << std::endl;
182 // const double thr95 = gsl_cdf_chisq_Pinv(0.95, 1);
183
184 // std::cout << "thr95 : " << thr95 << std::endl;
185
186 // auto T = [&](double c10){ return est.wilks_T(Vec{c10, 0.0}, fr, eta0); };
187 // double a=-7,b=-1; int N=10; double left=std::nan(""), right=std::nan("");
188 // double prev=a, prevT=T(prev);
189 // for(int i=1;i<=N;++i){ double x=a+(b-a)*i/double(N); double t=T(x);
190 // if (std::isnan(left) && (prevT-thr95)*(t-thr95)<=0) left=prev; if ((prevT-thr95)*(t-thr95)<=0) right=x; prev=x; prevT=t; }
191 // std::cout << "95% CI C10|Cp10=0: ["<<left<<","<<right<<"]";
192
193
194 return 0;
195}
Facade combining block existence/logging (BlockProvider) and block listing (APIAdapter).
@ GAUSSIAN
Gaussian copula, defined by a correlation matrix.
Helper used to transform collections of identifiers into correlation matrices/maps.
High-level maximum-likelihood fitting and confidence-contour API.
High-level helpers for initializing and monitoring the Hyperiso framework.
Monte Carlo propagation of nuisance-parameter uncertainties.
Factory for instantiating concrete marginal distributions.
@ GAUSSIAN
Symmetric Gaussian marginal.
Adapter from ObservableInterface to the statistical model interface.
High-level, user-facing entry point to compute flavor observables.
Concrete ISourcesProvider implementation using MemoryManager.
Nuisance sampler backed by a joint random-vector generator.
Concrete statistical proxy forwarding correlation queries to CorrelationProvider.
Statistics-layer proxy for read-only access to parameters and observables.
static std::unique_ptr< ICopula > create(CopulaType name, CopulaConfig config, unsigned int seed=std::random_device{}())
Creates a concrete copula instance.
Builds correlation tables/matrices from parameter or observable collections.
std::vector< ParamId > check_if_corr(const std::vector< ParamId > &ids)
Filters a parameter list, keeping only entries with positive combined uncertainty.
std::vector< std::vector< double > > transform(const std::vector< ParamId > &ids)
Builds a dense correlation matrix for a list of parameters.
static IdOf< ObservableTag > to_id(Observables e)
Converts an enum value to an IdOf<Tag>.
High-level interface to initialize and monitor the main framework configuration.
void init(const std::string &lhaFile, HyperisoConfig config)
Initializes Hyperiso using a LHA file and a full Config object.
static std::unique_ptr< IMarginalDistribution > create(MarginalType name, MarginalConfig cfg, unsigned int seed=std::random_device{}())
Creates a concrete marginal-distribution object.
Samples nuisance parameters and propagates them through a model.
Definition MCEngine.h:171
Provides access to leaf source parameters via MemoryManager.
std::unordered_set< ParamId > get_all_leaf_sources(const std::unordered_set< ParamId > &param_ids) const override
Retrieves all leaf source parameters for the given set of ParamIds.
Draws nuisance-parameter maps from a JointDistribution.
Concrete read-only proxy used by the statistics layer.
std::vector< std::vector< double > > Matrix
int main()
Configuration object for a Gaussian copula.
Configuration object for GaussianMarginal.
Configuration object controlling model, input flags and optional MARTY resources.
Definition Config.h:24
Model model
Current model.
Definition Config.h:33
Represents an identifier of a LHA element, possibly containing several sub-ids.
Definition LhaID.h:56
Composite identifier for a single parameter.
Definition ParamID.h:57
std::vector< double > Vec