aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
genericBNLearner_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #include <algorithm>
23 
24 #include <agrum/BN/learning/BNLearnUtils/genericBNLearner.h>
25 
26 namespace gum {
27 
28  namespace learning {
29 
30  template < typename GUM_SCALAR >
32  const std::string& filename,
33  const BayesNet< GUM_SCALAR >& bn,
34  const std::vector< std::string >& missing_symbols) {
35  // assign to each column name in the database its position
38  const auto& xvar_names = initializer.variableNames();
41  for (std::size_t i = std::size_t(0); i < nb_vars; ++i)
43 
44  // we use the bn to insert the translators into the database table
45  std::vector< NodeId > nodes;
47  for (const auto node: bn.dag())
49  std::sort(nodes.begin(), nodes.end());
50  std::size_t i = std::size_t(0);
51  for (auto node: nodes) {
52  const Variable& var = bn.variable(node);
53  try {
55  } catch (NotFound&) {
57  "Variable '" << var.name() << "' is missing");
58  }
60  }
61 
62  // fill the database
64 
65  // get the domain sizes of the variables
66  for (auto dom: database__.domainSizes())
68 
69  // create the parser
70  parser__
72  }
73 
74 
75  template < typename GUM_SCALAR >
79  for (std::size_t i = 0; i < nb_vars; ++i) {
80  const DiscreteVariable& var
81  = dynamic_cast< const DiscreteVariable& >(database__.variable(i));
82  bn.add(var);
83  }
84  return bn;
85  }
86 
87 
88  template < typename GUM_SCALAR >
90  const std::string& filename,
91  const gum::BayesNet< GUM_SCALAR >& bn,
92  const std::vector< std::string >& missing_symbols) :
96  }
97 
98 
99  /// use a new set of database rows' ranges to perform learning
100  template < template < typename > class XALLOC >
102  const std::vector< std::pair< std::size_t, std::size_t >,
103  XALLOC< std::pair< std::size_t, std::size_t > > >&
104  new_ranges) {
105  // use a score to detect whether the ranges are ok
108  ranges__ = score.ranges();
109  }
110  } // namespace learning
111 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)