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(ScoreAIC);
76 ScoreAIC::ScoreAIC(
const DBRowGeneratorParser& parser,
78 const Bijection< NodeId, std::size_t >& nodeId2columns) :
79 Score(parser, prior, nodeId2columns), _internal_prior_(parser.database(), nodeId2columns) {
80 GUM_CONSTRUCTOR(ScoreAIC);
84 ScoreAIC::ScoreAIC(
const ScoreAIC& from) :
85 Score(from), _internal_prior_(from._internal_prior_) {
86 GUM_CONS_CPY(ScoreAIC);
90 ScoreAIC::ScoreAIC(ScoreAIC&& from) :
91 Score(
std::move(from)), _internal_prior_(
std::move(from._internal_prior_)) {
92 GUM_CONS_MOV(ScoreAIC);
96 ScoreAIC::~ScoreAIC() { GUM_DESTRUCTOR(ScoreAIC); }
99 ScoreAIC& ScoreAIC::operator=(
const ScoreAIC& from) {
101 Score::operator=(from);
102 _internal_prior_ = from._internal_prior_;
108 ScoreAIC& ScoreAIC::operator=(ScoreAIC&& from) {
110 Score::operator=(std::move(from));
111 _internal_prior_ = std::move(from._internal_prior_);
117 std::string ScoreAIC::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 'AIC'.",
131 double ScoreAIC::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 conditioning_size = N_ij.size();
147 const std::size_t target_domsize = all_size / conditioning_size;
148 const double penalty = conditioning_size *
double(target_domsize - std::size_t(1));
155 for (
const auto n_ijk: N_ijk) {
156 if (n_ijk) { score += n_ijk * std::log(n_ijk); }
158 for (
const auto n_ij: N_ij) {
159 if (n_ij) { score -= n_ij * std::log(n_ij); }
163 score *= this->one_log2_;
174 const double penalty =
double(all_size - std::size_t(1));
182 for (
const auto n_ijk: N_ijk) {
184 score += n_ijk * std::log(n_ijk);
188 score -= N * std::log(N);
191 score *= this->one_log2_;
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
ScoreAIC(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
The base class for all the scores used for learning (BIC, BDeu, etc).
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 AIC scores
the class for computing AIC scores