51#ifndef DOXYGEN_SHOULD_SKIP_THIS
66 _internal_prior_ = from._internal_prior_;
75 _internal_prior_ = std::move(from._internal_prior_);
85 return "The prior is currently compatible with the BD score but if "
86 "you change the weight, it may become biased";
90 return std::format(
"The prior '{}' is not yet compatible with the score 'BD'.",
97 if (!this->
prior_->isInformative()) {
99 "The BD score requires its external prior to " <<
"be strictly positive");
103 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
104 const std::size_t all_size = N_ijk.size();
105 std::vector< double > N_prime_ijk(all_size, 0.0);
106 this->
prior_->addJointPseudoCount(idset, N_prime_ijk);
112 if (idset.hasConditioningSet()) {
114 std::vector< double > N_ij(this->
marginalize_(idset[0], N_ijk));
115 const std::size_t conditioning_size = N_ij.size();
117 std::vector< double > N_prime_ij(N_ij.size(), 0.0);
118 this->
prior_->addConditioningPseudoCount(idset, N_prime_ij);
124 for (std::size_t j = std::size_t(0); j < conditioning_size; ++j) {
125 score += _gammalog2_(N_prime_ij[j]) - _gammalog2_(N_ij[j] + N_prime_ij[j]);
127 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
128 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k]) - _gammalog2_(N_prime_ijk[k]);
135 double N_prime = 0.0;
136 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
137 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k]) - _gammalog2_(N_prime_ijk[k]);
139 N_prime += N_prime_ijk[k];
141 score += _gammalog2_(N_prime) - _gammalog2_(N + N_prime);
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
the class for computing Bayesian Dirichlet (BD) log2 scores
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreBD & operator=(const ScoreBD &from)
copy operator
double score_(const IdCondSet &idset) final
returns the score for a given IdCondSet
Prior * prior_
the expert knowledge a priorwe add to the score
double score(const NodeId var)
returns the score of a single node
Score & operator=(const Score &from)
copy operator
RecordCounter counter_
the record counter used for the counts over discrete variables
std::vector< double > marginalize_(const NodeId X_id, const std::vector< double > &N_xyz) const
returns a counting vector where variables are marginalized from N_xyz
#define GUM_ERROR(type, msg)
include the inlined functions if necessary
constexpr const char * priorTypeToString(PriorType e) noexcept
gum is the global namespace for all aGrUM entities
the class for computing Bayesian Dirichlet (BD) log2 scores
the class for computing BD scores