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 > >& nodeId2columns,
40 const typename AprioriDirichletFromDatabase< ALLOC >::allocator_type& alloc) :
41 Apriori< ALLOC >(apriori_parser.database(),
42 Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
44 _counter_(apriori_parser,
45 std::vector< std::pair< std::size_t, std::size_t >,
46 ALLOC< std::pair< std::size_t, std::size_t > > >(alloc),
51 const DatabaseTable< ALLOC >& apriori_db = apriori_parser.database();
52 const auto& apriori_names = apriori_db.variableNames();
53 const std::size_t apriori_size = apriori_names.size();
54 HashTable< std::string, std::size_t > names2col(apriori_size);
55 for (std::size_t i = std::size_t(0); i < apriori_size; ++i)
56 names2col.insert(apriori_names[i], i);
58 const auto& learning_names = learning_db.variableNames();
59 const std::size_t learning_size = learning_names.size();
60 HashTable< std::size_t, std::size_t > learning2apriori_index(learning_size);
61 bool different_index =
false;
62 for (std::size_t i = std::size_t(0); i < learning_size; ++i) {
64 std::size_t apriori_col;
66 apriori_col = names2col[learning_names[i]];
68 GUM_ERROR(DatabaseError,
69 "Variable " << learning_names[i]
70 <<
" could not be found in the apriori database");
74 const Variable& learning_var = learning_db.variable(i);
75 const Variable& apriori_var = apriori_db.variable(apriori_col);
76 if (learning_var.varType() != apriori_var.varType()) {
77 GUM_ERROR(DatabaseError,
78 "Variable " << learning_names[i]
79 <<
" has not the same type in the learning database " 80 " and the apriori database");
82 if (learning_var.domain() != apriori_var.domain()) {
83 GUM_ERROR(DatabaseError,
84 "Variable " << learning_names[i] <<
" has domain " << learning_var.domain()
85 <<
" in the learning database and domain " << apriori_var.domain()
86 <<
" in the aprioi database");
90 learning2apriori_index.insert(i, apriori_col);
91 if (i != apriori_col) different_index =
true;
97 if (!different_index) {
98 this->nodeId2columns_ = nodeId2columns;
100 if (nodeId2columns.empty()) {
101 for (std::size_t i = std::size_t(0); i < learning_size; ++i) {
102 this->nodeId2columns_.insert(NodeId(i), learning2apriori_index[i]);
105 for (
auto iter = nodeId2columns.begin(); iter != nodeId2columns.end(); ++iter) {
106 this->nodeId2columns_.insert(iter.first(), learning2apriori_index[iter.second()]);
112 std::vector< std::pair< std::size_t, std::size_t >,
113 ALLOC< std::pair< std::size_t, std::size_t > > >
115 RecordCounter< ALLOC > good_counter(apriori_parser, ranges,
this->nodeId2columns_, alloc);
116 _counter_ = std::move(good_counter);
118 if (apriori_db.nbRows() == std::size_t(0))
119 _internal_weight_ = 0.0;
121 _internal_weight_ =
this->weight_ / apriori_db.nbRows();
123 GUM_CONSTRUCTOR(AprioriDirichletFromDatabase);
128 template <
template <
typename >
class ALLOC >
139 template <
template <
typename >
class ALLOC >
146 template <
template <
typename >
class ALLOC >
157 template <
template <
typename >
class ALLOC >
164 template <
template <
typename >
class ALLOC >
181 template <
template <
typename >
class ALLOC >
189 template <
template <
typename >
class ALLOC >
196 template <
template <
typename >
class ALLOC >
209 template <
template <
typename >
class ALLOC >
222 template <
template <
typename >
class ALLOC >
229 template <
template <
typename >
class ALLOC >
236 template <
template <
typename >
class ALLOC >
243 template <
template <
typename >
class ALLOC >
254 template <
template <
typename >
class ALLOC >
258 if (
this->
weight_ == 0.0)
return;
275 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)