aGrUM  0.14.1
gum::learning::genericBNLearner::Database Class Reference

a helper to easily read databases More...

#include <genericBNLearner.h>

+ Collaboration diagram for gum::learning::genericBNLearner::Database:

Public Member Functions

template<typename GUM_SCALAR >
 Database (const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
 
Constructors / Destructors
 Database (const std::string &file, const std::vector< std::string > &missing_symbols)
 default constructor More...
 
 Database (const DatabaseTable<> &db)
 default constructor More...
 
 Database (const std::string &filename, Database &score_database, const std::vector< std::string > &missing_symbols)
 constructor for the aprioris More...
 
template<typename GUM_SCALAR >
 Database (const std::string &filename, const gum::BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
 constructor with a BN providing the variables of interest More...
 
 Database (const Database &from)
 copy constructor More...
 
 Database (Database &&from)
 move constructor More...
 
 ~Database ()
 destructor More...
 
Operators
Databaseoperator= (const Database &from)
 copy operator More...
 
Databaseoperator= (Database &&from)
 move operator More...
 
Accessors / Modifiers
DBRowGeneratorParserparser ()
 returns the parser for the database More...
 
const std::vector< std::size_t > & domainSizes () const
 returns the domain sizes of the variables More...
 
const std::vector< std::string > & names () const
 returns the names of the variables in the database More...
 
NodeId idFromName (const std::string &var_name) const
 returns the node id corresponding to a variable name More...
 
const std::string & nameFromId (NodeId id) const
 returns the variable name corresponding to a given node id More...
 
const DatabaseTabledatabaseTable () const
 returns the internal database table More...
 
void setDatabaseWeight (const double new_weight)
 assign a weight to all the rows of the database so that the sum of their weights is equal to new_weight More...
 
const Bijection< NodeId, std::size_t > & nodeId2Columns () const
 returns the mapping between node ids and their columns in the database More...
 
const std::vector< std::string > & missingSymbols () const
 returns the set of missing symbols taken into account More...
 

Protected Attributes

DatabaseTable __database
 the database itself More...
 
DBRowGeneratorParser__parser {nullptr}
 the parser used for reading the database More...
 
std::vector< std::size_t > __domain_sizes
 the domain sizes of the variables (useful to speed-up computations) More...
 
Bijection< NodeId, std::size_t > __nodeId2cols
 a bijection assigning to each variable name its NodeId More...
 
Size __max_threads_number {1}
 the max number of threads authorized More...
 
Size __min_nb_rows_per_thread {100}
 the minimal number of rows to parse (on average) by thread More...
 

Detailed Description

a helper to easily read databases

Definition at line 131 of file genericBNLearner.h.

Constructor & Destructor Documentation

◆ Database() [1/7]

gum::learning::genericBNLearner::Database::Database ( const std::string &  file,
const std::vector< std::string > &  missing_symbols 
)
explicit

default constructor

Parameters
filethe name of the CSV file containing the data
missing_symbolsthe set of symbols in the CSV file that correspond to missing data

Definition at line 64 of file genericBNLearner.cpp.

66  :
67  Database(genericBNLearner::__readFile(filename, missing_symbols)) {}
static DatabaseTable __readFile(const std::string &filename, const std::vector< std::string > &missing_symbols)
reads a file and returns a databaseVectInRam
Database(const std::string &file, const std::vector< std::string > &missing_symbols)
default constructor

◆ Database() [2/7]

gum::learning::genericBNLearner::Database::Database ( const DatabaseTable<> &  db)
explicit

default constructor

Parameters
dban already initialized database table that is used to fill the Database

Definition at line 47 of file genericBNLearner.cpp.

References __database, __domain_sizes, __nodeId2cols, __parser, gum::learning::DatabaseTable< ALLOC >::domainSizes(), gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), and gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableNames().

47  :
48  __database(db) {
49  // get the variables names
50  const auto& var_names = __database.variableNames();
51  const std::size_t nb_vars = var_names.size();
52  for (auto dom : __database.domainSizes())
53  __domain_sizes.push_back(dom);
54  for (std::size_t i = 0; i < nb_vars; ++i) {
56  }
57 
58  // create the parser
59  __parser =
60  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
61  }
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
DBVector< std::size_t > domainSizes() const
returns the domain sizes of all the variables in the database table
DatabaseTable __database
the database itself
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
const DBVector< std::string > & variableNames() const noexcept
returns the variable names for all the columns of the database
Size NodeId
Type for node ids.
Definition: graphElements.h:97
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
+ Here is the call graph for this function:

◆ Database() [3/7]

gum::learning::genericBNLearner::Database::Database ( const std::string &  filename,
Database score_database,
const std::vector< std::string > &  missing_symbols 
)

constructor for the aprioris

We must ensure that the variables of the Database are identical to those of the score database (else the countings used by the scores might be erroneous). However, we allow the variables to be ordered differently in the two databases: variables with the same name in both databases are supposed to be the same.

Parameters
filethe name of the CSV file containing the data
score_databasethe main database used for the learning
missing_symbolsthe set of symbols in the CSV file that correspond to missing data

Definition at line 70 of file genericBNLearner.cpp.

References gum::learning::genericBNLearner::__checkFileName(), __database, __domain_sizes, __nodeId2cols, __parser, databaseTable(), gum::learning::DatabaseTable< ALLOC >::domainSizes(), gum::learning::IDBInitializer< ALLOC >::fillDatabase(), GUM_ERROR, gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler(), gum::HashTable< Key, Val, Alloc >::insert(), gum::learning::DatabaseTable< ALLOC >::insertTranslator(), gum::learning::IDatabaseTable< T_DATA, ALLOC >::nbVariables(), nodeId2Columns(), gum::learning::DatabaseTable< ALLOC >::variable(), gum::learning::IDBInitializer< ALLOC >::variableNames(), and gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableNames().

73  {
74  // assign to each column name in the CSV file its column
76  DBInitializerFromCSV<> initializer(CSV_filename);
77  const auto& apriori_names = initializer.variableNames();
78  std::size_t apriori_nb_vars = apriori_names.size();
79  HashTable< std::string, std::size_t > apriori_names2col(apriori_nb_vars);
80  for (std::size_t i = std::size_t(0); i < apriori_nb_vars; ++i)
81  apriori_names2col.insert(apriori_names[i], i);
82 
83  // check that there are at least as many variables in the a priori
84  // database as those in the score_database
85  if (apriori_nb_vars < score_database.__database.nbVariables()) {
86  GUM_ERROR(InvalidArgument,
87  "the a apriori database has fewer variables "
88  "than the observed database");
89  }
90 
91  // get the mapping from the columns of score_database to those of
92  // the CSV file
93  const std::vector< std::string >& score_names =
94  score_database.databaseTable().variableNames();
95  const std::size_t score_nb_vars = score_names.size();
96  HashTable< std::size_t, std::size_t > mapping(score_nb_vars);
97  for (std::size_t i = std::size_t(0); i < score_nb_vars; ++i) {
98  try {
99  mapping.insert(i, apriori_names2col[score_names[i]]);
100  } catch (Exception&) {
101  GUM_ERROR(MissingVariableInDatabase,
102  "Variable "
103  << score_names[i]
104  << " of the observed database does not belong to the "
105  << "apriori database");
106  }
107  }
108 
109  // create the translators for CSV database
110  for (std::size_t i = std::size_t(0); i < score_nb_vars; ++i) {
111  const Variable& var = score_database.databaseTable().variable(i);
112  __database.insertTranslator(var, mapping[i], missing_symbols);
113  }
114 
115  // fill the database
116  initializer.fillDatabase(__database);
117 
118  // get the domain sizes of the variables
119  for (auto dom : __database.domainSizes())
120  __domain_sizes.push_back(dom);
121 
122  // compute the mapping from node ids to column indices
123  __nodeId2cols = score_database.nodeId2Columns();
124 
125  // create the parser
126  __parser =
127  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
128  }
static void __checkFileName(const std::string &filename)
checks whether the extension of a CSV filename is correct
DBVector< std::size_t > domainSizes() const
returns the domain sizes of all the variables in the database table
DatabaseTable __database
the database itself
std::size_t insertTranslator(const DBTranslator< ALLOC > &translator, const std::size_t input_column, const bool unique_column=true)
insert a new translator into the database table
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ Database() [4/7]

template<typename GUM_SCALAR >
gum::learning::genericBNLearner::Database::Database ( const std::string &  filename,
const gum::BayesNet< GUM_SCALAR > &  bn,
const std::vector< std::string > &  missing_symbols 
)

constructor with a BN providing the variables of interest

Parameters
filethe name of the CSV file containing the data
bna Bayesian network indicating which variables of the CSV file are used for learning
missing_symbolsthe set of symbols in the CSV file that correspond to missing data

◆ Database() [5/7]

gum::learning::genericBNLearner::Database::Database ( const Database from)

copy constructor

Definition at line 131 of file genericBNLearner.cpp.

References __database, __parser, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler().

131  :
132  __database(from.__database), __domain_sizes(from.__domain_sizes),
133  __nodeId2cols(from.__nodeId2cols) {
134  // create the parser
135  __parser =
136  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
137  }
DatabaseTable __database
the database itself
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
+ Here is the call graph for this function:

◆ Database() [6/7]

gum::learning::genericBNLearner::Database::Database ( Database &&  from)

move constructor

Definition at line 140 of file genericBNLearner.cpp.

References __database, __parser, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler().

140  :
141  __database(std::move(from.__database)),
142  __domain_sizes(std::move(from.__domain_sizes)),
143  __nodeId2cols(std::move(from.__nodeId2cols)) {
144  // create the parser
145  __parser =
146  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
147  }
DatabaseTable __database
the database itself
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
+ Here is the call graph for this function:

◆ ~Database()

gum::learning::genericBNLearner::Database::~Database ( )

destructor

Definition at line 150 of file genericBNLearner.cpp.

References __parser, and operator=().

150 { delete __parser; }
DBRowGeneratorParser * __parser
the parser used for reading the database
+ Here is the call graph for this function:

◆ Database() [7/7]

template<typename GUM_SCALAR >
gum::learning::genericBNLearner::Database::Database ( const std::string &  filename,
const BayesNet< GUM_SCALAR > &  bn,
const std::vector< std::string > &  missing_symbols 
)

Definition at line 30 of file genericBNLearner_tpl.h.

References gum::learning::genericBNLearner::__checkFileName(), __database, __domain_sizes, __nodeId2cols, __parser, gum::DAGmodel::dag(), gum::learning::DatabaseTable< ALLOC >::domainSizes(), gum::learning::IDBInitializer< ALLOC >::fillDatabase(), GUM_ERROR, gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::learning::DatabaseTable< ALLOC >::insertTranslator(), gum::Variable::name(), gum::BayesNet< GUM_SCALAR >::variable(), and gum::learning::IDBInitializer< ALLOC >::variableNames().

33  {
34  // assign to each column name in the database its position
36  DBInitializerFromCSV<> initializer(filename);
37  const auto& xvar_names = initializer.variableNames();
38  std::size_t nb_vars = xvar_names.size();
39  HashTable< std::string, std::size_t > var_names(nb_vars);
40  for (std::size_t i = std::size_t(0); i < nb_vars; ++i)
41  var_names.insert(xvar_names[i], i);
42 
43  // we use the bn to insert the translators into the database table
44  std::vector< NodeId > nodes;
45  nodes.reserve(bn.dag().sizeNodes());
46  for (const auto node : bn.dag())
47  nodes.push_back(node);
48  std::sort(nodes.begin(), nodes.end());
49  try {
50  std::size_t i = std::size_t(0);
51  for (auto node : nodes) {
52  const Variable& var = bn.variable(node);
53  __database.insertTranslator(var, var_names[var.name()], missing_symbols);
54  __nodeId2cols.insert(NodeId(node), i++);
55  }
56  } catch (NotFound&) {
57  GUM_ERROR(MissingVariableInDatabase,
58  "the database does not contain variable ");
59  }
60 
61  // fill the database
62  initializer.fillDatabase(__database);
63 
64  // get the domain sizes of the variables
65  for (auto dom : __database.domainSizes())
66  __domain_sizes.push_back(dom);
67 
68  // create the parser
69  __parser =
70  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
71  }
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
static void __checkFileName(const std::string &filename)
checks whether the extension of a CSV filename is correct
DBVector< std::size_t > domainSizes() const
returns the domain sizes of all the variables in the database table
DatabaseTable __database
the database itself
std::size_t insertTranslator(const DBTranslator< ALLOC > &translator, const std::size_t input_column, const bool unique_column=true)
insert a new translator into the database table
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
Size NodeId
Type for node ids.
Definition: graphElements.h:97
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

Member Function Documentation

◆ __BNVars()

template<typename GUM_SCALAR >
BayesNet< GUM_SCALAR > gum::learning::genericBNLearner::Database::__BNVars ( ) const
private

Definition at line 75 of file genericBNLearner_tpl.h.

References __database, gum::BayesNet< GUM_SCALAR >::add(), gum::learning::IDatabaseTable< T_DATA, ALLOC >::nbVariables(), and gum::learning::DatabaseTable< ALLOC >::variable().

75  {
76  BayesNet< GUM_SCALAR > bn;
77  const std::size_t nb_vars = __database.nbVariables();
78  for (std::size_t i = 0; i < nb_vars; ++i) {
79  const DiscreteVariable& var =
80  dynamic_cast< const DiscreteVariable& >(__database.variable(i));
81  bn.add(var);
82  }
83  return bn;
84  }
DatabaseTable __database
the database itself
std::size_t nbVariables() const noexcept
returns the number of variables (columns) of the database
const Variable & variable(const std::size_t k, const bool k_is_input_col=false) const
returns either the kth variable of the database table or the first one corresponding to the kth colum...
+ Here is the call graph for this function:

◆ databaseTable()

◆ domainSizes()

INLINE const std::vector< std::size_t > & gum::learning::genericBNLearner::Database::domainSizes ( ) const

returns the domain sizes of the variables

Definition at line 43 of file genericBNLearner_inl.h.

References __domain_sizes.

Referenced by gum::learning::genericBNLearner::domainSizes(), and gum::learning::genericBNLearner::nbCols().

43  {
44  return __domain_sizes;
45  }
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
+ Here is the caller graph for this function:

◆ idFromName()

INLINE NodeId gum::learning::genericBNLearner::Database::idFromName ( const std::string &  var_name) const

returns the node id corresponding to a variable name

Definition at line 63 of file genericBNLearner_inl.h.

References __database, __nodeId2cols, gum::learning::IDatabaseTable< T_DATA, ALLOC >::columnsFromVariableName(), gum::BijectionImplementation< T1, T2, Alloc, Gen >::first(), and GUM_ERROR.

Referenced by gum::learning::genericBNLearner::addForbiddenArc(), gum::learning::genericBNLearner::addMandatoryArc(), gum::learning::genericBNLearner::eraseForbiddenArc(), gum::learning::genericBNLearner::eraseMandatoryArc(), gum::learning::genericBNLearner::idFromName(), and gum::learning::genericBNLearner::setSliceOrder().

63  {
64  try {
65  const auto cols = __database.columnsFromVariableName(var_name);
66  return __nodeId2cols.first(cols[0]);
67  } catch (...) {
68  GUM_ERROR(MissingVariableInDatabase,
69  "Variable " << var_name
70  << " could not be found in the database");
71  }
72  }
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
DBVector< std::size_t > columnsFromVariableName(const std::string &name) const
returns the indices of all the columns whose name is passed in argument
DatabaseTable __database
the database itself
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ missingSymbols()

INLINE const std::vector< std::string > & gum::learning::genericBNLearner::Database::missingSymbols ( ) const

returns the set of missing symbols taken into account

Definition at line 97 of file genericBNLearner_inl.h.

References __database, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::missingSymbols().

Referenced by gum::learning::genericBNLearner::__createApriori().

97  {
98  return __database.missingSymbols();
99  }
const DBVector< std::string > & missingSymbols() const
returns the set of missing symbols
DatabaseTable __database
the database itself
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nameFromId()

INLINE const std::string & gum::learning::genericBNLearner::Database::nameFromId ( NodeId  id) const

returns the variable name corresponding to a given node id

Definition at line 77 of file genericBNLearner_inl.h.

References __database, __nodeId2cols, GUM_ERROR, gum::BijectionImplementation< T1, T2, Alloc, Gen >::second(), and gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableName().

Referenced by gum::learning::genericBNLearner::nameFromId().

77  {
78  try {
80  } catch (...) {
81  GUM_ERROR(MissingVariableInDatabase,
82  "Variable of Id " << id
83  << " could not be found in the database");
84  }
85  }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
DatabaseTable __database
the database itself
const std::string & variableName(const std::size_t k) const
returns the name of the kth column of the IDatabaseTable
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ names()

INLINE const std::vector< std::string > & gum::learning::genericBNLearner::Database::names ( ) const

returns the names of the variables in the database

Definition at line 49 of file genericBNLearner_inl.h.

References __database, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableNames().

Referenced by gum::learning::genericBNLearner::names().

49  {
50  return __database.variableNames();
51  }
DatabaseTable __database
the database itself
const DBVector< std::string > & variableNames() const noexcept
returns the variable names for all the columns of the database
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nodeId2Columns()

INLINE const Bijection< NodeId, std::size_t > & gum::learning::genericBNLearner::Database::nodeId2Columns ( ) const

returns the mapping between node ids and their columns in the database

Definition at line 103 of file genericBNLearner_inl.h.

References __nodeId2cols.

Referenced by gum::learning::genericBNLearner::__createApriori(), gum::learning::genericBNLearner::__createCorrectedMutualInformation(), gum::learning::genericBNLearner::__createParamEstimator(), gum::learning::genericBNLearner::__createScore(), and Database().

103  {
104  return __nodeId2cols;
105  }
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
+ Here is the caller graph for this function:

◆ operator=() [1/2]

genericBNLearner::Database & gum::learning::genericBNLearner::Database::operator= ( const Database from)

copy operator

Definition at line 153 of file genericBNLearner.cpp.

References __database, __domain_sizes, __nodeId2cols, __parser, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler().

Referenced by ~Database().

153  {
154  if (this != &from) {
155  delete __parser;
156  __database = from.__database;
157  __domain_sizes = from.__domain_sizes;
158  __nodeId2cols = from.__nodeId2cols;
159 
160  // create the parser
161  __parser =
162  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
163  }
164 
165  return *this;
166  }
DatabaseTable __database
the database itself
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [2/2]

genericBNLearner::Database & gum::learning::genericBNLearner::Database::operator= ( Database &&  from)

move operator

Definition at line 169 of file genericBNLearner.cpp.

References __database, __domain_sizes, __nodeId2cols, __parser, and gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler().

169  {
170  if (this != &from) {
171  delete __parser;
172  __database = std::move(from.__database);
173  __domain_sizes = std::move(from.__domain_sizes);
174  __nodeId2cols = std::move(from.__nodeId2cols);
175 
176  // create the parser
177  __parser =
178  new DBRowGeneratorParser<>(__database.handler(), DBRowGeneratorSet<>());
179  }
180 
181  return *this;
182  }
DatabaseTable __database
the database itself
DBRowGeneratorParser * __parser
the parser used for reading the database
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
+ Here is the call graph for this function:

◆ parser()

INLINE DBRowGeneratorParser & gum::learning::genericBNLearner::Database::parser ( )

returns the parser for the database

Definition at line 37 of file genericBNLearner_inl.h.

References __parser.

Referenced by gum::learning::genericBNLearner::__createApriori(), gum::learning::genericBNLearner::__createCorrectedMutualInformation(), gum::learning::genericBNLearner::__createScore(), and gum::learning::genericBNLearner::useDatabaseRanges().

37  {
38  return *__parser;
39  }
DBRowGeneratorParser * __parser
the parser used for reading the database
+ Here is the caller graph for this function:

◆ setDatabaseWeight()

INLINE void gum::learning::genericBNLearner::Database::setDatabaseWeight ( const double  new_weight)

assign a weight to all the rows of the database so that the sum of their weights is equal to new_weight

assign new weight to the rows of the learning database

Definition at line 55 of file genericBNLearner_inl.h.

References __database, gum::learning::IDatabaseTable< T_DATA, ALLOC >::nbRows(), and gum::learning::IDatabaseTable< T_DATA, ALLOC >::setAllRowsWeight().

Referenced by gum::learning::genericBNLearner::setDatabaseWeight().

55  {
56  if (__database.nbRows() == std::size_t(0)) return;
57  const double weight = new_weight / double(__database.nbRows());
59  }
DatabaseTable __database
the database itself
std::size_t nbRows() const noexcept
returns the number of records (rows) in the database
void setAllRowsWeight(const double new_weight)
assign a given weight to all the rows of the database
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __database

DatabaseTable gum::learning::genericBNLearner::Database::__database
protected

◆ __domain_sizes

std::vector< std::size_t > gum::learning::genericBNLearner::Database::__domain_sizes
protected

the domain sizes of the variables (useful to speed-up computations)

Definition at line 243 of file genericBNLearner.h.

Referenced by Database(), domainSizes(), and operator=().

◆ __max_threads_number

Size gum::learning::genericBNLearner::Database::__max_threads_number {1}
protected

the max number of threads authorized

Definition at line 252 of file genericBNLearner.h.

◆ __min_nb_rows_per_thread

Size gum::learning::genericBNLearner::Database::__min_nb_rows_per_thread {100}
protected

the minimal number of rows to parse (on average) by thread

Definition at line 256 of file genericBNLearner.h.

◆ __nodeId2cols

Bijection< NodeId, std::size_t > gum::learning::genericBNLearner::Database::__nodeId2cols
protected

a bijection assigning to each variable name its NodeId

Definition at line 246 of file genericBNLearner.h.

Referenced by Database(), idFromName(), nameFromId(), nodeId2Columns(), and operator=().

◆ __parser

DBRowGeneratorParser* gum::learning::genericBNLearner::Database::__parser {nullptr}
protected

the parser used for reading the database

Definition at line 240 of file genericBNLearner.h.

Referenced by Database(), operator=(), parser(), and ~Database().


The documentation for this class was generated from the following files: