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 std::stringstream msg;
92 <<
"' is not yet compatible with the score 'BD'.";
99 if (!this->
prior_->isInformative()) {
101 "The BD score requires its external prior to " <<
"be strictly positive");
105 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
106 const std::size_t all_size = N_ijk.size();
107 std::vector< double > N_prime_ijk(all_size, 0.0);
108 this->
prior_->addJointPseudoCount(idset, N_prime_ijk);
114 if (idset.hasConditioningSet()) {
116 std::vector< double > N_ij(this->
marginalize_(idset[0], N_ijk));
117 const std::size_t conditioning_size = N_ij.size();
119 std::vector< double > N_prime_ij(N_ij.size(), 0.0);
120 this->
prior_->addConditioningPseudoCount(idset, N_prime_ij);
126 for (std::size_t j = std::size_t(0); j < conditioning_size; ++j) {
127 score += _gammalog2_(N_prime_ij[j]) - _gammalog2_(N_ij[j] + N_prime_ij[j]);
129 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
130 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k]) - _gammalog2_(N_prime_ijk[k]);
137 double N_prime = 0.0;
138 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
139 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k]) - _gammalog2_(N_prime_ijk[k]);
141 N_prime += N_prime_ijk[k];
143 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
virtual double score_(const IdCondSet &idset) final
returns the score for a given IdCondSet
virtual std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreBD & operator=(const ScoreBD &from)
copy operator
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