13 unsigned long seed = 1234567890;
15 auto model_fn = [] (
const std::vector<double>& p,
const std::vector<double> eta) {
22 auto f = [a, b, c, d, e] (
double x,
double y) {
23 return a * x * x + b * y * y + c * x * y + d * x + e * y;
26 return std::vector<double> ({
f(1, 0),
f(0, 1),
f(1, 1),
f(-1, 0),
f(0, -1),
f(-1, -1),
f(1, -1),
f(-1, 1)});
29 std::vector<std::unique_ptr<IMarginalDistribution>> nuis_marginals;
30 nuis_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>(3, 1, seed)));
31 nuis_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>(-1, 0.5, seed)));
38 std::unique_ptr<ICopula> nuis_copula = std::make_unique<GaussianCopula>(seed, R_nuis);
39 std::unique_ptr<JointDistribution> nuis_dist = std::make_unique<JointDistribution>(std::move(nuis_marginals), std::move(nuis_copula));
41 std::vector<std::unique_ptr<IMarginalDistribution>> obs_marginals;
42 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.1, seed)));
43 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.3, seed)));
44 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.2, seed)));
45 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.1, seed)));
46 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.3, seed)));
47 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.2, seed)));
48 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.5, seed)));
49 obs_marginals.emplace_back(std::move(std::make_unique<GaussianMarginal>( 0, 0.3, seed)));
52 {1, 0, 0.1, 0, 0, 0, 0, 0},
53 {0, 1, 0, 0, 0, 0, 0.5, 0},
54 {0.1, 0, 1, 0, 0, 0, 0, 0},
55 {0, 0, 0, 1, 0, 0, 0, 0},
56 {0, 0, 0, 0, 1, 0, 0, 0},
57 {0, 0, 0, 0, 0, 1, 0, 0},
58 {0, 0.5, 0, 0, 0, 0, 1, 0.1},
59 {0, 0, 0, 0, 0, 0, 0.1, 1}
62 std::unique_ptr<ICopula> obs_copula = std::make_unique<GaussianCopula>(seed, R_obs);
63 std::unique_ptr<JointDistribution> obs_dist = std::make_unique<JointDistribution>(std::move(obs_marginals), std::move(obs_copula));
65 std::shared_ptr<LikelihoodContext> ctx = std::make_shared<LikelihoodContext>();
66 ctx->exp_obs_dist = std::move(obs_dist);
67 ctx->nuisance_dist = std::move(nuis_dist);
68 ctx->exp_obs_values = {5, 0, 3, -1, 2, -1, 9, 1};
79 std::shared_ptr<ILikelihood> base = std::make_shared<BaseLikelihood>(model_fn, ctx, 3);
81 std::cout <<
"Base likelihood:" << std::endl;
82 std::cout <<
"dim = " << base->dim() << std::endl;
83 std::cout <<
"nll(2, 1, -2, 3, -1) = " << base->nll({2, 1, -2, 3, -1}) << std::endl;
85 auto of = [base] (std::vector<double> theta) {
86 return base->nll(theta);
90 MinimizationResult res =
minimize_combined(of, {0, 0, 0, 3.0, -1.0}, {1, 1, 1, 1, 1}, min_ctx);
92 auto of_profiled = [base, min_ctx] (std::vector<double> p) {
93 auto wrapped = [base, p] (std::vector<double> eta) {
94 std::vector<double> theta = p;
95 theta.insert(theta.end(), eta.begin(), eta.end());
96 return base->nll(theta);
105 for (
size_t i = 0; i < 3; i++) {
106 for (
size_t j = 0; j < 3; j++)
107 corr.
at(i, j) /= std::sqrt(cov.
at(i, i) * cov.
at(j, j));
114 fr.
p_hat_std = {std::sqrt(cov.
at(0, 0)), std::sqrt(cov.
at(1, 1)), std::sqrt(cov.
at(2, 2))};
117 std::cout <<
"Toy master fit:" << std::endl;
118 std::cout <<
"min nll =" << fr.
ell_hat << std::endl;
119 std::cout <<
"p_hat = (" << fr.
p_hat[0] <<
", " << fr.
p_hat[1] <<
", " << fr.
p_hat[2] <<
")" << std::endl;
120 std::cout <<
"eta_hat = (" << fr.
eta_hat[0] <<
", " << fr.
eta_hat[1] <<
")" << std::endl;
122 std::cout <<
"p_hat_corr:" << std::endl;
165 os.open(
"contour_proj_constrained.csv");
168 for (
const Point& point: path) {
169 os << point.first <<
"," << point.second <<
"\n";