50#ifndef DOXYGEN_SHOULD_SKIP_THIS
59 Prior(from), _counter_(from._counter_), _internal_weight_(from._internal_weight_) {
60 GUM_CONS_CPY(DirichletPriorFromDatabase);
65 DirichletPriorFromDatabase::DirichletPriorFromDatabase(
66 DirichletPriorFromDatabase&& from) noexcept :
67 Prior(std::move(from)), _counter_(std::move(from._counter_)),
68 _internal_weight_(from._internal_weight_) {
69 GUM_CONS_MOV(DirichletPriorFromDatabase);
73 INLINE DirichletPriorFromDatabase* DirichletPriorFromDatabase::clone()
const {
74 return new DirichletPriorFromDatabase(*
this);
78 INLINE DirichletPriorFromDatabase::~DirichletPriorFromDatabase() {
79 GUM_DESTRUCTOR(DirichletPriorFromDatabase);
83 INLINE DirichletPriorFromDatabase&
84 DirichletPriorFromDatabase::operator=(
const DirichletPriorFromDatabase& from) {
86 Prior::operator=(from);
87 _counter_ = from._counter_;
88 _internal_weight_ = from._internal_weight_;
94 INLINE DirichletPriorFromDatabase&
95 DirichletPriorFromDatabase::operator=(DirichletPriorFromDatabase&& from) {
97 Prior::operator=(std::move(from));
98 _counter_ = std::move(from._counter_);
99 _internal_weight_ = from._internal_weight_;
105 INLINE
PriorType DirichletPriorFromDatabase::getType()
const {
106 return PriorType::DirichletPriorType;
110 INLINE
bool DirichletPriorFromDatabase::isInformative()
const {
return (this->weight_ != 0.0); }
113 INLINE
void DirichletPriorFromDatabase::setWeight(
const double weight) {
114 Prior::setWeight(weight);
115 if (_counter_.database().nbRows() == 0) _internal_weight_ = 0.0;
116 else _internal_weight_ = this->weight_ /
double(_counter_.database().nbRows());
120 INLINE
void DirichletPriorFromDatabase::addJointPseudoCount(
const IdCondSet& idset,
121 std::vector< double >& counts) {
122 if (this->weight_ == 0.0)
return;
124 const auto& prior = _counter_.counts(idset);
125 const std::size_t size = prior.size();
126 if (_internal_weight_ != 1.0) {
127 for (
auto i = std::size_t(0); i < size; ++i) {
128 counts[i] += prior[i] * _internal_weight_;
131 for (
auto i = std::size_t(0); i < size; ++i) {
132 counts[i] += prior[i];
139 DirichletPriorFromDatabase::addConditioningPseudoCount(
const IdCondSet& idset,
140 std::vector< double >& counts) {
141 if (_internal_weight_ == 0.0)
return;
143 const auto& prior = _counter_.counts(idset.conditionalIdCondSet());
144 const std::size_t size = prior.size();
145 if (_internal_weight_ != 1.0) {
146 for (std::size_t i = std::size_t(0); i < size; ++i) {
147 counts[i] += prior[i] * _internal_weight_;
150 for (std::size_t i = std::size_t(0); i < size; ++i) {
151 counts[i] += prior[i];
A dirichlet priori: computes its N'_ijk from a database.
A dirichlet priori: computes its N'_ijk from a database.
DirichletPriorFromDatabase(const DatabaseTable &learning_db, const DBRowGeneratorParser &prior_parser, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
the base class for all a priori
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities