49#ifndef DOXYGEN_SHOULD_SKIP_THIS
58 Prior(from), _counter_(from._counter_), _internal_weight_(from._internal_weight_) {
59 GUM_CONS_CPY(DirichletPriorFromDatabase);
64 DirichletPriorFromDatabase::DirichletPriorFromDatabase(
65 DirichletPriorFromDatabase&& from) noexcept :
66 Prior(std::move(from)), _counter_(std::move(from._counter_)),
67 _internal_weight_(from._internal_weight_) {
68 GUM_CONS_MOV(DirichletPriorFromDatabase);
72 INLINE DirichletPriorFromDatabase* DirichletPriorFromDatabase::clone()
const {
73 return new DirichletPriorFromDatabase(*
this);
77 INLINE DirichletPriorFromDatabase::~DirichletPriorFromDatabase() {
78 GUM_DESTRUCTOR(DirichletPriorFromDatabase);
82 INLINE DirichletPriorFromDatabase&
83 DirichletPriorFromDatabase::operator=(
const DirichletPriorFromDatabase& from) {
85 Prior::operator=(from);
86 _counter_ = from._counter_;
87 _internal_weight_ = from._internal_weight_;
93 INLINE DirichletPriorFromDatabase&
94 DirichletPriorFromDatabase::operator=(DirichletPriorFromDatabase&& from) {
96 Prior::operator=(std::move(from));
97 _counter_ = std::move(from._counter_);
98 _internal_weight_ = from._internal_weight_;
104 INLINE
PriorType DirichletPriorFromDatabase::getType()
const {
105 return PriorType::DirichletPriorType;
109 INLINE
bool DirichletPriorFromDatabase::isInformative()
const {
return (this->weight_ != 0.0); }
112 INLINE
void DirichletPriorFromDatabase::setWeight(
const double weight) {
113 Prior::setWeight(weight);
114 if (_counter_.database().nbRows() == 0) _internal_weight_ = 0.0;
115 else _internal_weight_ = this->weight_ /
double(_counter_.database().nbRows());
119 INLINE
void DirichletPriorFromDatabase::addJointPseudoCount(
const IdCondSet& idset,
120 std::vector< double >& counts) {
121 if (this->weight_ == 0.0)
return;
123 const auto& prior = _counter_.counts(idset);
124 const std::size_t size = prior.size();
125 if (_internal_weight_ != 1.0) {
126 for (
auto i = std::size_t(0); i < size; ++i) {
127 counts[i] += prior[i] * _internal_weight_;
130 for (
auto i = std::size_t(0); i < size; ++i) {
131 counts[i] += prior[i];
138 DirichletPriorFromDatabase::addConditioningPseudoCount(
const IdCondSet& idset,
139 std::vector< double >& counts) {
140 if (_internal_weight_ == 0.0)
return;
142 const auto& prior = _counter_.counts(idset.conditionalIdCondSet());
143 const std::size_t size = prior.size();
144 if (_internal_weight_ != 1.0) {
145 for (std::size_t i = std::size_t(0); i < size; ++i) {
146 counts[i] += prior[i] * _internal_weight_;
149 for (std::size_t i = std::size_t(0); i < size; ++i) {
150 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