51#ifndef DOXYGEN_SHOULD_SKIP_THIS
66 _internal_prior_ = from._internal_prior_;
75 _internal_prior_ = std::move(from._internal_prior_);
90 std::stringstream msg;
92 <<
"' is not yet compatible with the score 'BIC'.";
99 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
100 const bool informative_external_prior = this->
prior_->isInformative();
101 if (informative_external_prior) this->
prior_->addJointPseudoCount(idset, N_ijk);
102 const std::size_t all_size = N_ijk.size();
106 if (idset.hasConditioningSet()) {
108 std::vector< double > N_ij(this->
marginalize_(idset[0], N_ijk));
109 const std::size_t conditioning_size = N_ij.size();
113 const std::size_t target_domsize = all_size / conditioning_size;
114 const double penalty = conditioning_size * double(target_domsize - std::size_t(1));
121 for (
const auto n_ijk: N_ijk) {
122 if (n_ijk) {
score += n_ijk * std::log(n_ijk); }
125 for (
const auto n_ij: N_ij) {
127 score -= n_ij * std::log(n_ij);
133 score -= penalty * std::log(
N) * 0.5;
144 const double penalty = double(all_size - std::size_t(1));
152 for (
const auto n_ijk: N_ijk) {
154 score += n_ijk * std::log(n_ijk);
161 score -= penalty * std::log(
N) * 0.5;
173 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
174 if (this->
prior_->isInformative()) this->
prior_->addJointPseudoCount(idset, N_ijk);
177 for (
const auto n_ijk: N_ijk) {
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
the class for computing BIC scores
double N(const IdCondSet &idset)
returns the size of the database w.r.t. a given idset
ScoreBIC & operator=(const ScoreBIC &from)
copy operator
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
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
const double one_log2_
1 / log(2)
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 BIC scores
the class for computing BIC scores