4 std::shared_ptr<ILikelihood> base,
5 std::shared_ptr<JointDistribution> constraints_dist,
6 std::vector<std::size_t> constrained_params)
7 : base(
std::move(base)),
8 constraints_dist(
std::move(constraints_dist)),
9 constrained_params(
std::move(constrained_params))
13 double base_nll = this->base->nll(theta);
15 std::vector<double> constrained_vals;
16 for (std::size_t i : this->constrained_params) {
17 constrained_vals.emplace_back(theta[i]);
20 double constraint_nll = -this->constraints_dist->logpdf(constrained_vals);
22 return base_nll + constraint_nll;
26 return base->get_param_defs();
30 return this->base->dim();
Likelihood decorator adding an external Gaussian constraint term.
WithGaussianConstraints(std::shared_ptr< ILikelihood > base, std::shared_ptr< JointDistribution > constraints_dist, std::vector< std::size_t > constrained_params)
Constructs a constrained likelihood wrapper.
double nll(const std::vector< double > &theta) const override
Evaluates the constrained negative log-likelihood.
std::vector< fit_app::ParameterDefinition > get_param_defs() const override
Returns the metadata describing the likelihood parameters.
std::size_t dim() const override
Returns the total dimension of the parameter vector.
Hash specialization for SymbolId<Tag>.