27 #ifndef DOXYGEN_SHOULD_SKIP_THIS 35 template <
template <
typename >
class ALLOC >
36 AprioriDirichletFromDatabase< ALLOC >::AprioriDirichletFromDatabase(
37 const DatabaseTable< ALLOC >& learning_db,
38 const DBRowGeneratorParser< ALLOC >& apriori_parser,
39 const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
41 const typename AprioriDirichletFromDatabase< ALLOC >::allocator_type&
43 Apriori< ALLOC >(apriori_parser.database(),
44 Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
48 std::vector< std::pair< std::size_t, std::size_t >,
49 ALLOC< std::pair< std::size_t, std::size_t > > >(alloc),
54 const DatabaseTable< ALLOC >& apriori_db = apriori_parser.database();
55 const auto& apriori_names = apriori_db.variableNames();
56 const std::size_t apriori_size = apriori_names.size();
57 HashTable< std::string, std::size_t > names2col(apriori_size);
58 for (std::size_t i = std::size_t(0); i < apriori_size; ++i)
59 names2col.insert(apriori_names[i], i);
61 const auto& learning_names = learning_db.variableNames();
62 const std::size_t learning_size = learning_names.size();
63 HashTable< std::size_t, std::size_t > learning2apriori_index(learning_size);
64 bool different_index =
false;
65 for (std::size_t i = std::size_t(0); i < learning_size; ++i) {
67 std::size_t apriori_col;
69 apriori_col = names2col[learning_names[i]];
71 GUM_ERROR(DatabaseError,
72 "Variable " << learning_names[i]
73 <<
" could not be found in the apriori database");
77 const Variable& learning_var = learning_db.variable(i);
78 const Variable& apriori_var = apriori_db.variable(apriori_col);
79 if (learning_var.varType() != apriori_var.varType()) {
80 GUM_ERROR(DatabaseError,
83 <<
" has not the same type in the learning database " 84 " and the apriori database");
86 if (learning_var.domain() != apriori_var.domain()) {
87 GUM_ERROR(DatabaseError,
88 "Variable " << learning_names[i] <<
" has domain " 89 << learning_var.domain()
90 <<
" in the learning database and domain " 91 << apriori_var.domain()
92 <<
" in the aprioi database");
96 learning2apriori_index.insert(i, apriori_col);
97 if (i != apriori_col) different_index =
true;
103 if (!different_index) {
104 this->nodeId2columns_ = nodeId2columns;
106 if (nodeId2columns.empty()) {
107 for (std::size_t i = std::size_t(0); i < learning_size; ++i) {
108 this->nodeId2columns_.insert(NodeId(i), learning2apriori_index[i]);
111 for (
auto iter = nodeId2columns.begin(); iter != nodeId2columns.end();
113 this->nodeId2columns_.insert(iter.first(),
114 learning2apriori_index[iter.second()]);
120 std::vector< std::pair< std::size_t, std::size_t >,
121 ALLOC< std::pair< std::size_t, std::size_t > > >
123 RecordCounter< ALLOC > good_counter(apriori_parser,
125 this->nodeId2columns_,
127 counter__ = std::move(good_counter);
129 if (apriori_db.nbRows() == std::size_t(0))
130 internal_weight__ = 0.0;
132 internal_weight__ =
this->weight_ / apriori_db.nbRows();
134 GUM_CONSTRUCTOR(AprioriDirichletFromDatabase);
139 template <
template <
typename >
class ALLOC >
152 template <
template <
typename >
class ALLOC >
159 template <
template <
typename >
class ALLOC >
172 template <
template <
typename >
class ALLOC >
180 template <
template <
typename >
class ALLOC >
199 template <
template <
typename >
class ALLOC >
207 template <
template <
typename >
class ALLOC >
214 template <
template <
typename >
class ALLOC >
228 template <
template <
typename >
class ALLOC >
242 template <
template <
typename >
class ALLOC >
250 template <
template <
typename >
class ALLOC >
258 template <
template <
typename >
class ALLOC >
265 template <
template <
typename >
class ALLOC >
277 template <
template <
typename >
class ALLOC >
281 if (
this->
weight_ == 0.0)
return;
298 template <
template <
typename >
class ALLOC >
INLINE void emplace(Args &&... args)
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)