51#ifndef DOXYGEN_SHOULD_SKIP_THIS
66 _internal_prior_ = from._internal_prior_;
75 _internal_prior_ = std::move(from._internal_prior_);
86 return "The prior is currently compatible with the BDeu score but "
87 "if you change the weight, it will become incompatible.";
93 return "The BDeu score already contains a different 'implicit' prior. "
94 "Therefore, the learning will probably be biased.";
98 std::stringstream msg;
100 <<
"' is not yet compatible with the score 'BDeu'.";
107 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
108 const std::size_t all_size = N_ijk.size();
111 const double ess = _internal_prior_.weight();
112 const bool informative_external_prior = this->
prior_->isInformative();
117 if (idset.hasConditioningSet()) {
119 std::vector< double > N_ij(this->
marginalize_(idset[0], N_ijk));
120 const std::size_t conditioning_size = N_ij.size();
121 const double ess_qi = ess / conditioning_size;
122 const double ess_riqi = ess / all_size;
124 if (informative_external_prior) {
129 std::vector< double > N_prime_ijk(all_size, 0.0);
130 this->
prior_->addJointPseudoCount(idset, N_prime_ijk);
131 std::vector< double > N_prime_ij(N_ij.size(), 0.0);
132 this->
prior_->addConditioningPseudoCount(idset, N_prime_ij);
139 for (std::size_t j = std::size_t(0); j < conditioning_size; ++j) {
140 score += _gammalog2_(N_prime_ij[j] + ess_qi)
141 - _gammalog2_(N_ij[j] + N_prime_ij[j] + ess_qi);
143 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
144 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k] + ess_riqi)
145 - _gammalog2_(N_prime_ijk[k] + ess_riqi);
153 score = conditioning_size * _gammalog2_(ess_qi) - all_size * _gammalog2_(ess_riqi);
155 for (
const auto n_ij: N_ij) {
156 score -= _gammalog2_(n_ij + ess_qi);
158 for (
const auto n_ijk: N_ijk) {
159 score += _gammalog2_(n_ijk + ess_riqi);
164 const double ess_ri = ess / all_size;
166 if (informative_external_prior) {
171 std::vector< double > N_prime_ijk(all_size, 0.0);
172 this->
prior_->addJointPseudoCount(idset, N_prime_ijk);
179 double N_prime = 0.0;
180 for (std::size_t k = std::size_t(0); k < all_size; ++k) {
181 score += _gammalog2_(N_ijk[k] + N_prime_ijk[k] + ess_ri)
182 - _gammalog2_(N_prime_ijk[k] + ess_ri);
184 N_prime += N_prime_ijk[k];
186 score += _gammalog2_(N_prime + ess) - _gammalog2_(N + N_prime + ess);
193 score = _gammalog2_(ess) - all_size * _gammalog2_(ess_ri);
195 for (
const auto n_ijk: N_ijk) {
196 score += _gammalog2_(n_ijk + ess_ri);
199 score -= _gammalog2_(N + ess);
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
the class for computing BDeu scores
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreBDeu & operator=(const ScoreBDeu &from)
copy operator
virtual 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
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 BDeu scores
the class for computing BDeu scores