49 template <
typename GUM_SCALAR >
51 const BayesNet< GUM_SCALAR >& bn,
52 const std::vector< std::string >& missing_symbols) {
57 std::size_t nb_vars = xvar_names.size();
59 for (std::size_t i = std::size_t(0); i < nb_vars; ++i)
60 var_names.
insert(xvar_names[i], i);
63 std::vector< NodeId > nodes;
64 nodes.reserve(bn.dag().sizeNodes());
65 for (
const auto node: bn.dag())
66 nodes.push_back(node);
67 std::sort(nodes.begin(), nodes.end());
68 std::size_t i = std::size_t(0);
69 for (
auto node: nodes) {
70 const Variable& var = bn.variable(node);
72 _database_.insertTranslator(var, var_names[var.
name()], missing_symbols);
90 template <
typename GUM_SCALAR >
92 BayesNet< GUM_SCALAR > bn;
93 const std::size_t nb_vars =
_database_.nbVariables();
94 for (std::size_t i = 0; i < nb_vars; ++i) {
101 template <
typename GUM_SCALAR >
104 const std::vector< std::string >& missing_symbols) :
A class for generic framework of learning algorithms that can easily be used.
Class representing a Bayesian network.
Base class for discrete random variable.
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Error: A name of variable is not found in the database.
Exception : the element we looked for cannot be found.
Base class for every random variable.
const std::string & name() const
returns the name of the variable
The class for initializing DatabaseTable and RawDatabaseTable instances from CSV files.
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
The class used to pack sets of generators.
Database(const std::string &file, const std::vector< std::string > &missing_symbols, const bool induceTypes=false)
default constructor
std::vector< std::size_t > _domain_sizes_
the domain sizes of the variables (useful to speed-up computations)
DatabaseTable _database_
the database itself
Bijection< NodeId, std::size_t > _nodeId2cols_
a bijection assigning to each variable name its NodeId
DBRowGeneratorParser * _parser_
the parser used for reading the database
BayesNet< GUM_SCALAR > _BNVars_() const
IBNLearner(const std::string &filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
read the database file for the score / parameter estimation and var names
Database scoreDatabase_
the database to be used by the scores and parameter estimators
std::string filename_
the filename database
static void isCSVFileName_(const std::string &filename)
checks whether the extension of a CSV filename is correct
bool inducedTypes_
the policy for typing variables
void fillDatabase(DATABASE &database, const bool retry_insertion=false)
fills the rows of the database table
const std::vector< std::string > & variableNames()
returns the names of the variables in the input dataset
the no a priorclass: corresponds to 0 weight-sample
#define GUM_ERROR(type, msg)
Size NodeId
Type for node ids.
include the inlined functions if necessary