50 template < GUM_Numeric GUM_SCALAR >
52 const BayesNet< GUM_SCALAR >& bn,
53 const std::vector< std::string >& missing_symbols) {
58 std::size_t nb_vars = xvar_names.size();
60 for (std::size_t i = std::size_t(0); i < nb_vars; ++i)
61 var_names.
insert(xvar_names[i], i);
64 std::vector< NodeId > nodes;
65 nodes.reserve(bn.internalDag().sizeNodes());
66 for (
const auto node: bn.internalDag())
67 nodes.push_back(node);
68 std::sort(nodes.begin(), nodes.end());
69 std::size_t i = std::size_t(0);
70 for (
auto node: nodes) {
71 const Variable& var = bn.variable(node);
74 _database_.insertTranslator(var, *p, missing_symbols);
89 template < GUM_Numeric GUM_SCALAR >
91 BayesNet< GUM_SCALAR > bn;
92 const std::size_t nb_vars =
_database_.nbVariables();
93 for (std::size_t i = 0; i < nb_vars; ++i) {
100 template < GUM_Numeric GUM_SCALAR >
103 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.
optional_ref< Val > tryGet(const Key &key)
Returns a pointer to the value associated with a given key, or nullptr if the key does not exist.
Error: A name of variable is not found in the database.
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.
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
Database(std::string_view file, const std::vector< std::string > &missing_symbols, const bool induceTypes=false)
default constructor
DBRowGeneratorParser * _parser_
the parser used for reading the database
BayesNet< GUM_SCALAR > _BNVars_() const
Database scoreDatabase_
the database to be used by the scores and parameter estimators
static void isCSVFileName_(std::string_view filename)
checks whether the extension of a CSV filename is correct
std::string filename_
the filename database
IBNLearner(std::string_view filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
read the database file for the score / parameter estimation and var names
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