51#ifndef DOXYGEN_SHOULD_SKIP_THIS
66 _internal_prior_ = from._internal_prior_;
75 _internal_prior_ = std::move(from._internal_prior_);
90 return std::format(
"The prior '{}' is not yet compatible with the score 'fNML'.",
97 std::vector< double > N_ijk(this->
counter_.counts(idset,
true));
98 const bool informative_external_prior = this->
prior_->isInformative();
99 if (informative_external_prior) this->
prior_->addJointPseudoCount(idset, N_ijk);
100 const std::size_t all_size = N_ijk.size();
104 if (idset.hasConditioningSet()) {
106 std::vector< double > N_ij(this->
marginalize_(idset[0], N_ijk));
107 const std::size_t target_domsize = all_size / N_ij.size();
114 for (
const auto n_ijk: N_ijk) {
115 if (n_ijk) {
score += n_ijk * std::log(n_ijk); }
117 for (
const auto n_ij: N_ij) {
118 if (n_ij) {
score -= n_ij * std::log(n_ij); }
125 double penalty = 0.0;
126 for (
const auto n_ij: N_ij) {
127 penalty += _ctable_.log2Cnr(target_domsize, n_ij);
142 for (
const auto n_ijk: N_ijk) {
144 score += n_ijk * std::log(n_ijk);
148 score -= N * std::log(N);
154 score -= _ctable_.log2Cnr(all_size, N);
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
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
the class for computing fNML scores
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScorefNML & operator=(const ScorefNML &from)
copy operator
double score_(const IdCondSet &idset) final
returns the score for a given IdCondSet
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 fNML scores
the class for computing fNML scores