![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
a helper to easily read databases More...
#include <genericBNLearner.h>
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 | |
Database & | operator= (const Database &from) |
copy operator More... | |
Database & | operator= (Database &&from) |
move operator More... | |
Accessors / Modifiers | |
DBRowGeneratorParser & | parser () |
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 DatabaseTable & | databaseTable () 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... | |
std::size_t | nbRows () const |
returns the number of records in the database More... | |
std::size_t | size () const |
returns the number of records in the database More... | |
void | setWeight (const std::size_t i, const double weight) |
sets the weight of the ith record More... | |
double | weight (const std::size_t i) const |
returns the weight of the ith record More... | |
double | weight () const |
returns the weight of the whole database 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... | |
a helper to easily read databases
Definition at line 145 of file genericBNLearner.h.
|
explicit |
default constructor
file | the name of the CSV file containing the data |
missing_symbols | the set of symbols in the CSV file that correspond to missing data |
Definition at line 67 of file genericBNLearner.cpp.
|
explicit |
default constructor
db | an already initialized database table that is used to fill the Database |
Definition at line 52 of file genericBNLearner.cpp.
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.
file | the name of the CSV file containing the data |
score_database | the main database used for the learning |
missing_symbols | the set of symbols in the CSV file that correspond to missing data |
Definition at line 72 of file genericBNLearner.cpp.
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
file | the name of the CSV file containing the data |
bn | a Bayesian network indicating which variables of the CSV file are used for learning |
missing_symbols | the set of symbols in the CSV file that correspond to missing data |
gum::learning::genericBNLearner::Database::Database | ( | const Database & | from | ) |
copy constructor
Definition at line 130 of file genericBNLearner.cpp.
gum::learning::genericBNLearner::Database::Database | ( | Database && | from | ) |
move constructor
Definition at line 138 of file genericBNLearner.cpp.
gum::learning::genericBNLearner::Database::~Database | ( | ) |
destructor
Definition at line 146 of file genericBNLearner.cpp.
gum::learning::genericBNLearner::Database::Database | ( | const std::string & | filename, |
const BayesNet< GUM_SCALAR > & | bn, | ||
const std::vector< std::string > & | missing_symbols | ||
) |
Definition at line 31 of file genericBNLearner_tpl.h.
References Database().
Referenced by _BNVars_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::Miic::_existsNonTrivialDirectedPath_(), gum::learning::Miic::_isNotLatentCouple_(), gum::learning::Miic::_orientingVstructureMiic_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::genericBNLearner::_setAprioriWeight_(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::_varOrderFromCSV_(), gum::learning::Miic::addConstraints(), gum::learning::genericBNLearner::addForbiddenArc(), gum::learning::genericBNLearner::addMandatoryArc(), gum::learning::genericBNLearner::addPossibleEdge(), gum::learning::BNLearnerListener::BNLearnerListener(), gum::learning::genericBNLearner::clearDatabaseRanges(), gum::learning::DAG2BNLearner< ALLOC >::clone(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::learning::DAG2BNLearner< ALLOC >::DAG2BNLearner(), Database(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::database(), gum::learning::genericBNLearner::database(), gum::learning::genericBNLearner::databaseRanges(), databaseTable(), gum::learning::genericBNLearner::databaseWeight(), gum::learning::genericBNLearner::domainSize(), domainSizes(), gum::learning::genericBNLearner::domainSizes(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::learning::genericBNLearner::eraseForbiddenArc(), gum::learning::genericBNLearner::eraseMandatoryArc(), gum::learning::genericBNLearner::erasePossibleEdge(), gum::learning::Miic::findBestContributor_(), gum::learning::genericBNLearner::genericBNLearner(), gum::learning::genericBNLearner::getAprioriType_(), gum::learning::GreedyHillClimbing::GreedyHillClimbing(), gum::learning::genericBNLearner::hasMissingValues(), idFromName(), gum::learning::genericBNLearner::idFromName(), gum::learning::Miic::initiation_(), gum::learning::Miic::isForbidenArc_(), gum::learning::Miic::isOrientable_(), gum::learning::Miic::iteration_(), gum::learning::Miic::latentVariables(), gum::learning::genericBNLearner::latentVariables(), gum::learning::K2::learnBN(), gum::learning::GreedyHillClimbing::learnBN(), gum::learning::LocalSearchWithTabuList::learnBN(), gum::learning::Miic::learnBN(), gum::learning::Miic::learnMixedStructure(), gum::learning::K2::learnStructure(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::learning::Miic::learnStructure(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::log2likelihood(), gum::learning::Miic::Miic(), missingSymbols(), nameFromId(), gum::learning::genericBNLearner::nameFromId(), names(), gum::learning::genericBNLearner::names(), gum::learning::genericBNLearner::nbCols(), nbRows(), gum::learning::genericBNLearner::nbRows(), nodeId2Columns(), gum::learning::GreaterPairOn2nd::operator()(), gum::learning::GreaterAbsPairOn2nd::operator()(), gum::learning::GreaterTupleOnLast::operator()(), gum::learning::StructuralConstraintMandatoryArcs::operator=(), gum::learning::StructuralConstraintPossibleEdges::operator=(), gum::learning::StructuralConstraintForbiddenArcs::operator=(), gum::learning::BNLearnerListener::operator=(), gum::learning::StructuralConstraintIndegree::operator=(), gum::learning::StructuralConstraintUndiGraph::operator=(), gum::learning::StructuralConstraintDAG::operator=(), gum::learning::StructuralConstraintDiGraph::operator=(), gum::learning::GreedyHillClimbing::operator=(), gum::learning::DAG2BNLearner< ALLOC >::operator=(), gum::learning::StructuralConstraintTabuList::operator=(), gum::learning::StructuralConstraintSliceOrder::operator=(), gum::learning::Miic::operator=(), gum::learning::Miic::orientation3off2_(), gum::learning::Miic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), parser(), gum::learning::Miic::propagatesOrientationInChainOfRemainingEdges_(), gum::learning::Miic::propagatesRemainingOrientableEdges_(), gum::learning::genericBNLearner::recordWeight(), gum::learning::Miic::set3of2Behaviour(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setAntiTopologicalVarOrder(), setDatabaseWeight(), gum::learning::genericBNLearner::setDatabaseWeight(), gum::learning::genericBNLearner::setForbiddenArcs(), gum::learning::genericBNLearner::setInitialDAG(), gum::learning::genericBNLearner::setMandatoryArcs(), gum::learning::genericBNLearner::setMaxIndegree(), gum::learning::Miic::setMiicBehaviour(), gum::learning::genericBNLearner::setPossibleEdges(), gum::learning::genericBNLearner::setPossibleSkeleton(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setRandomVarOrder(), gum::learning::genericBNLearner::setRecordWeight(), gum::learning::genericBNLearner::setSliceOrder(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setTopologicalVarOrder(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setVarOrder(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::setVarOrderFromCSV(), setWeight(), size(), gum::learning::StructuralConstraintDAG::StructuralConstraintDAG(), gum::learning::StructuralConstraintDiGraph::StructuralConstraintDiGraph(), gum::learning::StructuralConstraintForbiddenArcs::StructuralConstraintForbiddenArcs(), gum::learning::StructuralConstraintIndegree::StructuralConstraintIndegree(), gum::learning::StructuralConstraintMandatoryArcs::StructuralConstraintMandatoryArcs(), gum::learning::StructuralConstraintPossibleEdges::StructuralConstraintPossibleEdges(), gum::learning::StructuralConstraintSliceOrder::StructuralConstraintSliceOrder(), gum::learning::StructuralConstraintTabuList::StructuralConstraintTabuList(), gum::learning::StructuralConstraintUndiGraph::StructuralConstraintUndiGraph(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::toCSV(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::toDatabaseTable(), gum::learning::GraphChange::toString(), gum::learning::ArcAddition::toString(), gum::learning::ArcDeletion::toString(), gum::learning::ArcReversal::toString(), gum::learning::EdgeAddition::toString(), gum::learning::EdgeDeletion::toString(), gum::learning::Miic::unshieldedTriples_(), gum::learning::Miic::unshieldedTriplesMiic_(), gum::learning::Miic::updateProbaTriples_(), gum::learning::genericBNLearner::use3off2(), gum::learning::genericBNLearner::useAprioriBDeu(), gum::learning::genericBNLearner::useAprioriDirichlet(), gum::learning::genericBNLearner::useAprioriSmoothing(), gum::learning::genericBNLearner::useDatabaseRanges(), gum::learning::genericBNLearner::useEM(), gum::learning::genericBNLearner::useGreedyHillClimbing(), gum::learning::genericBNLearner::useK2(), gum::learning::genericBNLearner::useLocalSearchWithTabuList(), gum::learning::genericBNLearner::useMDLCorrection(), gum::learning::genericBNLearner::useMIIC(), gum::learning::genericBNLearner::useNMLCorrection(), gum::learning::genericBNLearner::useNoApriori(), gum::learning::genericBNLearner::useNoCorrection(), gum::learning::genericBNLearner::useScoreAIC(), gum::learning::genericBNLearner::useScoreBD(), gum::learning::genericBNLearner::useScoreBDeu(), gum::learning::genericBNLearner::useScoreBIC(), gum::learning::genericBNLearner::useScoreK2(), gum::learning::genericBNLearner::useScoreLog2Likelihood(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::varOrder(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::varOrderNames(), weight(), gum::learning::BNLearnerListener::whenProgress(), gum::learning::BNLearnerListener::whenStop(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::~BNDatabaseGenerator(), gum::learning::BNLearnerListener::~BNLearnerListener(), gum::learning::DAG2BNLearner< ALLOC >::~DAG2BNLearner(), gum::learning::GreedyHillClimbing::~GreedyHillClimbing(), gum::learning::Miic::~Miic(), gum::learning::StructuralConstraintDAG::~StructuralConstraintDAG(), gum::learning::StructuralConstraintDiGraph::~StructuralConstraintDiGraph(), gum::learning::StructuralConstraintForbiddenArcs::~StructuralConstraintForbiddenArcs(), gum::learning::StructuralConstraintIndegree::~StructuralConstraintIndegree(), gum::learning::StructuralConstraintMandatoryArcs::~StructuralConstraintMandatoryArcs(), gum::learning::StructuralConstraintPossibleEdges::~StructuralConstraintPossibleEdges(), gum::learning::StructuralConstraintSliceOrder::~StructuralConstraintSliceOrder(), gum::learning::StructuralConstraintTabuList::~StructuralConstraintTabuList(), and gum::learning::StructuralConstraintUndiGraph::~StructuralConstraintUndiGraph().
|
private |
Definition at line 73 of file genericBNLearner_tpl.h.
References Database().
INLINE const DatabaseTable & gum::learning::genericBNLearner::Database::databaseTable | ( | ) | const |
returns the internal database table
Definition at line 83 of file genericBNLearner_inl.h.
References Database().
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 Database().
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 60 of file genericBNLearner_inl.h.
References Database().
INLINE const std::vector< std::string > & gum::learning::genericBNLearner::Database::missingSymbols | ( | ) | const |
returns the set of missing symbols taken into account
Definition at line 89 of file genericBNLearner_inl.h.
References Database().
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 72 of file genericBNLearner_inl.h.
References Database().
INLINE const std::vector< std::string > & gum::learning::genericBNLearner::Database::names | ( | ) | const |
returns the names of the variables in the database
Definition at line 48 of file genericBNLearner_inl.h.
References Database().
INLINE std::size_t gum::learning::genericBNLearner::Database::nbRows | ( | ) | const |
returns the number of records in the database
Definition at line 102 of file genericBNLearner_inl.h.
References Database().
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 96 of file genericBNLearner_inl.h.
References Database().
genericBNLearner::Database & gum::learning::genericBNLearner::Database::operator= | ( | const Database & | from | ) |
copy operator
Definition at line 148 of file genericBNLearner.cpp.
genericBNLearner::Database & gum::learning::genericBNLearner::Database::operator= | ( | Database && | from | ) |
move operator
Definition at line 162 of file genericBNLearner.cpp.
INLINE DBRowGeneratorParser & gum::learning::genericBNLearner::Database::parser | ( | ) |
returns the parser for the database
Definition at line 40 of file genericBNLearner_inl.h.
References Database().
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 53 of file genericBNLearner_inl.h.
References Database().
INLINE void gum::learning::genericBNLearner::Database::setWeight | ( | const std::size_t | i, |
const double | weight | ||
) |
sets the weight of the ith record
OutOfBounds | if i is outside the set of indices of the records or if the weight is negative |
Definition at line 110 of file genericBNLearner_inl.h.
References Database().
INLINE std::size_t gum::learning::genericBNLearner::Database::size | ( | ) | const |
returns the number of records in the database
Definition at line 106 of file genericBNLearner_inl.h.
References Database().
INLINE double gum::learning::genericBNLearner::Database::weight | ( | const std::size_t | i | ) | const |
returns the weight of the ith record
OutOfBounds | if i is outside the set of indices of the records |
Definition at line 116 of file genericBNLearner_inl.h.
References Database().
INLINE double gum::learning::genericBNLearner::Database::weight | ( | ) | const |
returns the weight of the whole database
Definition at line 122 of file genericBNLearner_inl.h.
References Database().
|
protected |
the database itself
Definition at line 273 of file genericBNLearner.h.
|
protected |
the domain sizes of the variables (useful to speed-up computations)
Definition at line 279 of file genericBNLearner.h.
|
protected |
the max number of threads authorized
Definition at line 288 of file genericBNLearner.h.
|
protected |
the minimal number of rows to parse (on average) by thread
Definition at line 292 of file genericBNLearner.h.
a bijection assigning to each variable name its NodeId
Definition at line 282 of file genericBNLearner.h.
|
protected |
the parser used for reading the database
Definition at line 276 of file genericBNLearner.h.