51#ifndef DOXYGEN_SHOULD_SKIP_THIS
68 const std::vector< std::pair< std::size_t, std::size_t > >& ranges,
69 const Bijection< NodeId, std::size_t >& nodeId2columns) :
70 Score(parser, prior, ranges, nodeId2columns),
71 _internal_prior_(parser.database(), nodeId2columns) {
72 GUM_CONSTRUCTOR(ScorefNML);
76 ScorefNML::ScorefNML(
const DBRowGeneratorParser& parser,
78 const Bijection< NodeId, std::size_t >& nodeId2columns) :
79 Score(parser, prior, nodeId2columns), _internal_prior_(parser.database(), nodeId2columns) {
80 GUM_CONSTRUCTOR(ScorefNML);
84 ScorefNML::ScorefNML(
const ScorefNML& from) :
85 Score(from), _internal_prior_(from._internal_prior_) {
86 GUM_CONS_CPY(ScorefNML);
90 ScorefNML::ScorefNML(ScorefNML&& from) :
91 Score(
std::move(from)), _internal_prior_(
std::move(from._internal_prior_)) {
92 GUM_CONS_MOV(ScorefNML);
96 ScorefNML::~ScorefNML() { GUM_DESTRUCTOR(ScorefNML); }
99 ScorefNML& ScorefNML::operator=(
const ScorefNML& from) {
101 Score::operator=(from);
102 _internal_prior_ = from._internal_prior_;
108 ScorefNML& ScorefNML::operator=(ScorefNML&& from) {
110 Score::operator=(std::move(from));
111 _internal_prior_ = std::move(from._internal_prior_);
117 std::string ScorefNML::isPriorCompatible(PriorType prior_type,
double weight) {
119 if ((prior_type == PriorType::DirichletPriorType)
120 || (prior_type == PriorType::SmoothingPriorType)
121 || (prior_type == PriorType::NoPriorType)) {
126 return std::format(
"The prior '{}' is not yet compatible with the score 'fNML'.",
131 double ScorefNML::score_(
const IdCondSet& idset) {
133 std::vector< double > N_ijk(this->counter_.counts(idset,
true));
134 const bool informative_external_prior = this->prior_->isInformative();
135 if (informative_external_prior) this->prior_->addJointPseudoCount(idset, N_ijk);
136 const std::size_t all_size = N_ijk.size();
140 if (idset.hasConditioningSet()) {
142 std::vector< double > N_ij(this->marginalize_(idset[0], N_ijk));
143 const std::size_t target_domsize = all_size / N_ij.size();
150 for (
const auto n_ijk: N_ijk) {
151 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
153 for (
const auto n_ij: N_ij) {
154 if (n_ij) { score -= n_ij * std::log(n_ij); }
158 score *= this->one_log2_;
161 double penalty = 0.0;
162 for (
const auto n_ij: N_ij) {
163 penalty += _ctable_.log2Cnr(target_domsize, n_ij);
178 for (
const auto n_ijk: N_ijk) {
180 score += n_ijk * std::log(n_ijk);
184 score -= N * std::log(N);
187 score *= this->one_log2_;
190 score -= _ctable_.log2Cnr(all_size, N);
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
the base class for all a priori
The base class for all the scores used for learning (BIC, BDeu, etc).
ScorefNML(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
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