73 const std::size_t nb_vars = var_names.size();
76 for (std::size_t i = 0; i < nb_vars; ++i) {
85 const std::vector< std::string >& missing_symbols,
86 const bool induceTypes) :
101 const std::vector< std::string >& missing_symbols) {
106 std::size_t prior_nb_vars = prior_names.size();
108 for (
auto i = std::size_t(0); i < prior_nb_vars; ++i)
109 prior_names2col.
insert(prior_names[i], i);
115 "the a prior database has fewer variables "
116 "than the observed database")
122 const std::size_t score_nb_vars = score_names.size();
124 for (
auto i = std::size_t(0); i < score_nb_vars; ++i) {
126 mapping.
insert(i, prior_names2col[score_names[i]]);
129 "Variable " << score_names[i]
130 <<
" of the observed database does not belong to the "
136 for (
auto i = std::size_t(0); i < score_nb_vars; ++i) {
138 _database_.insertTranslator(var, mapping[i], missing_symbols);
202 const std::vector< std::string >& missing_symbols,
203 const bool induceTypes) :
419 dag2BN_ = std::move(from.dag2BN_);
425 ranges_ = std::move(from.ranges_);
439 if (
auto filename_size =
Size(filename.size()); filename_size < 4) {
441 "IBNLearner could not determine the "
442 "file type of the database '"
446 std::string extension = filename.substr(filename.size() - 4);
447 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
449 if (extension !=
".csv") {
451 "IBNLearner does not support yet this type ('" << extension
459 const std::size_t nb_vars = var_names.size();
463 for (std::size_t i = 0; i < nb_vars; ++i) {
477 if (
auto filename_size =
Size(filename.size()); filename_size < 4) {
479 "IBNLearner could not determine the "
480 "file type of the database")
483 std::string extension(filename.substr(filename.size() - 4));
484 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
486 if (extension !=
".csv") {
492 const std::vector< std::string >& missing_symbols) {
499 const std::size_t nb_vars = var_names.size();
503 for (std::size_t i = 0; i < nb_vars; ++i) {
582 if (old_score !=
nullptr)
delete old_score;
590 bool take_into_account_score) {
596 if (take_into_account_score && (
score_ !=
nullptr)) {
614 "IBNLearner does not support " <<
"yet this parameter estimator")
624 return param_estimator;
643 if (possible_edges.
empty()) {
645 for (
NodeId j = 0; j < i; ++j) {
651 for (
const auto& edge: possible_edges) {
652 mgraph.
addEdge(edge.first(), edge.second());
662 for (
const auto& arc: mandatory_arcs) {
663 mandatoryGraph.
addArc(arc.tail(), arc.head());
671 for (
const auto& arc: forbidden_arcs) {
672 forbiddenGraph.
addArc(arc.tail(), arc.head());
678 for (
const auto& [n1, r1]: sliceOrder) {
679 for (
const auto& [n2, r2]: copyOrder) {
681 forbiddenGraph.
addArc(n1, n2);
683 }
else if (r2 > r1) {
684 forbiddenGraph.
addArc(n2, n1);
693 for (
auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
694 const auto node1 = *iter1;
695 for (
auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
696 forbiddenGraph.
addArc(*iter2, node1);
701 for (
const auto node2: mgraph.
nodes()) {
702 if (node != node2) { forbiddenGraph.
addArc(node2, node); }
707 for (
const auto node2: mgraph.
nodes()) {
708 if (node != node2) { forbiddenGraph.
addArc(node, node2); }
739 if (possible_edges.
empty()) {
741 for (
NodeId j = 0; j < i; ++j) {
746 for (
const auto& edge: possible_edges) {
747 mgraph.
addEdge(edge.first(), edge.second());
752 mandatoryGraph.
addArc(arc.tail(), arc.head());
753 forbiddenGraph.
addArc(arc.head(), arc.tail());
756 forbiddenGraph.
addArc(arc.tail(), arc.head());
761 for (
const auto& [n1, r1]: sliceOrder) {
762 for (
const auto& [n2, r2]: copyOrder) {
764 forbiddenGraph.
addArc(n1, n2);
765 }
else if (r2 > r1) {
766 forbiddenGraph.
addArc(n2, n1);
773 for (
auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
774 for (
auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
775 forbiddenGraph.
addArc(*iter2, *iter1);
780 for (
const auto node2: mgraph.
nodes()) {
781 if (node != node2) { forbiddenGraph.
addArc(node2, node); }
785 for (
const auto node2: mgraph.
nodes()) {
786 if (node != node2) { forbiddenGraph.
addArc(node, node2); }
832 if (possible_edges.
empty()) {
834 for (
NodeId j = 0; j < i; ++j) {
839 for (
const auto& edge: possible_edges) {
840 mgraph.
addEdge(edge.first(), edge.second());
845 mandatoryGraph.
addArc(arc.tail(), arc.head());
846 forbiddenGraph.
addArc(arc.head(), arc.tail());
849 forbiddenGraph.
addArc(arc.tail(), arc.head());
854 for (
const auto& [n1, r1]: sliceOrder) {
855 for (
const auto& [n2, r2]: copyOrder) {
857 forbiddenGraph.
addArc(n1, n2);
858 }
else if (r2 > r1) {
859 forbiddenGraph.
addArc(n2, n1);
866 for (
auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
867 for (
auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
868 forbiddenGraph.
addArc(*iter2, *iter1);
873 for (
const auto node2: mgraph.
nodes()) {
874 if (node != node2) { forbiddenGraph.
addArc(node2, node); }
878 for (
const auto node2: mgraph.
nodes()) {
879 if (node != node2) { forbiddenGraph.
addArc(node, node2); }
911 const auto name =
gum::config().
typed< std::string >(
"learning",
"BNLearnerPreferredAlgo");
920 "'" << name <<
"' is not a valid value for learning.BNLearnerPreferredAlgo")
927 "Score-based algorithms do not build PDAG. Please use a constraint-based "
933 "For the moment, the BNLearner is unable to learn "
934 <<
"structures with missing values in databases")
958 for (
const auto i: pdag) {
970 "For the moment, the BNLearner is unable to learn "
971 <<
"structures with missing values in databases")
980 for (
const auto i: pag) {
990 for (
const auto i: dag) {
1010 "The BNLearner's corrected mutual information class does "
1011 <<
"not implement yet this correction : " <<
int(
kmodeMiic_))
1022 "For the moment, the BNLearner is unable to cope "
1023 "with missing values in databases")
1034 init_graph.
addArc(arc.tail(), arc.head());
1076 invariable_constraints;
1093 variable_constraints;
1097 invariable_constraints,
1098 variable_constraints);
1120 invariable_constraints;
1137 variable_constraints;
1141 invariable_constraints,
1142 variable_constraints);
1162 invariable_constraints;
1179 variable_constraints;
1183 invariable_constraints,
1184 variable_constraints);
1199 invariable_constraints;
1218 variable_constraints;
1223 invariable_constraints,
1224 variable_constraints);
1243 invariable_constraints;
1259 const ArcSet& mandatory_arcs
1262 bool order_compatible =
true;
1264 for (
const auto& arc: mandatory_arcs) {
1265 if (order.
pos(arc.tail()) >= order.
pos(arc.head())) {
1266 order_compatible =
false;
1271 if (order_compatible) {
1273 variable_constraints;
1277 invariable_constraints,
1278 variable_constraints);
1283 variable_constraints;
1287 invariable_constraints,
1288 variable_constraints);
1296 "the learnDAG method has not been implemented for this "
1297 "learning algorithm")
1323 default :
return "IBNLearner does not support yet this score";
1328 std::pair< std::size_t, std::size_t >
1330 const std::size_t k_fold) {
1333 if (learning_fold >= k_fold) {
1335 "In " << k_fold <<
"-fold cross validation, the learning "
1336 <<
"fold should be strictly lower than " << k_fold
1337 <<
" but, here, it is equal to " << learning_fold)
1341 if (k_fold >= db_size) {
1343 "In " << k_fold <<
"-fold cross validation, the database's "
1344 <<
"size should be strictly greater than " << k_fold
1345 <<
" but, here, the database has only " << db_size <<
"rows")
1349 const std::size_t foldSize = db_size / k_fold;
1350 const std::size_t unfold_deb = learning_fold * foldSize;
1351 const std::size_t unfold_end = unfold_deb + foldSize;
1354 if (learning_fold == std::size_t(0)) {
1355 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1357 ranges_.push_back(std::pair< std::size_t, std::size_t >(std::size_t(0), unfold_deb));
1359 if (learning_fold != k_fold - 1) {
1360 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1364 return std::pair< std::size_t, std::size_t >(unfold_deb, unfold_end);
1367 std::pair< double, double >
1372 return chi2score.
statistics(id1, id2, knowing);
1376 std::string_view name2,
1377 const std::vector< std::string >& knowing) {
1378 std::vector< NodeId > knowingIds;
1379 std::transform(knowing.begin(),
1381 std::back_inserter(knowingIds),
1382 [
this](
const std::string& c) { return this->idFromName(c); });
1386 std::pair< double, double >
1390 return g2score.
statistics(id1, id2, knowing);
1394 std::string_view name2,
1395 const std::vector< std::string >& knowing) {
1396 std::vector< NodeId > knowingIds;
1397 std::transform(knowing.begin(),
1399 std::back_inserter(knowingIds),
1400 [
this](
const std::string& c) { return this->idFromName(c); });
1405 const std::vector< NodeId >& knowing) {
1409 std::vector< NodeId > total(vars);
1410 total.insert(total.end(), knowing.begin(), knowing.end());
1412 if (knowing.size() == (
Size)0) {
1416 return LLtotal - LLknw;
1421 const std::vector< std::string >& knowing) {
1422 std::vector< NodeId > ids;
1423 std::vector< NodeId > knowingIds;
1425 auto mapper = [
this](
const std::string& c) {
return this->
idFromName(c); };
1427 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1428 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1435 const std::vector< NodeId >& knowing) {
1443 case MDL : cmi.
useMDL();
break;
1445 case NML : cmi.
useNML();
break;
1451 "The BNLearner's corrected mutual information class does "
1452 <<
"not implement yet this correction : " <<
int(
kmodeMiic_))
1459 std::string_view var2,
1460 const std::vector< std::string >& knowing) {
1461 std::vector< NodeId > knowingIds;
1463 auto mapper = [
this](
const std::string& c) {
return this->
idFromName(c); };
1465 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1472 const std::vector< NodeId >& knowing) {
1482 std::string_view var2,
1483 const std::vector< std::string >& knowing) {
1484 std::vector< NodeId > knowingIds;
1486 auto mapper = [
this](
const std::string& c) {
return this->
idFromName(c); };
1488 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1501 auto mapper = [
this](
const std::string& c) {
return this->
idFromName(c); };
1504 std::vector< NodeId > knowingIds;
1505 knowingIds.reserve(knowing.size());
1506 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1508 return score(
id, knowingIds);
1514 "BNLearner cannot compute pseudo-counts with missing values in the database")
1523 return count.
get(vars);
1527 std::vector< NodeId > ids;
1529 auto mapper = [
this](
const std::string& c) {
return this->
idFromName(c); };
1531 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1537 const std::vector< std::pair< std::size_t, std::size_t > >& new_ranges) {
A listener that allows BNLearner to be used as a proxy for its inner algorithms.
A class for generic framework of learning algorithms that can easily be used.
A pack of learning algorithms that can easily be used.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
void insert(const T1 &first, const T2 &second)
T typed(std::string_view section, std::string_view key) const
Value of section.key converted according to its declared type.
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Base class for all oriented graphs.
void addArc(const NodeId tail, const NodeId head) override
insert a new arc into the directed graph
Base class for all aGrUM's exceptions.
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.
IApproximationSchemeConfiguration()
Class constructors.
Exception: at least one argument passed to a function is not what was expected.
Error: The database contains some missing values.
Error: A name of variable is not found in the database.
Base class for mixed graphs.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
bool exists(const NodeId id) const
alias for existsNode
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Exception : there is something wrong with an implementation.
Exception : operation not allowed.
Exception : out of bound.
Partial Ancestral Graph: undirected topology with endpoint marks.
Base class for partially directed acyclic graphs.
Idx pos(const Key &key) const
bool empty() const noexcept
Indicates whether the set is the empty set.
bool isGumNumberOfThreadsOverriden() const override
indicates whether the class containing this ThreadNumberManager set its own number of threads
Size getNumberOfThreads() const override
returns the current max number of threads used by the class containing this ThreadNumberManager
ThreadNumberManager(Size nb_threads=0)
default constructor
ThreadNumberManager & operator=(const ThreadNumberManager &from)
copy operator
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Base class for every random variable.
A class that redirects gum_signal from algorithms to the listeners of BNLearn.
void setAlpha(double alpha)
maximum conditioning set size; Size(-1) = unlimited (default)
void setIndependenceTest(IndependenceTest &test)
inject independence test (non-owning: caller manages lifetime)
void setUCPriority(UCPriority p)
collider candidate ordering (default: Standard)
@ Sorted
descending p-value order (strongest evidence first)
@ Standard
process triples in natural traversal order
void setMaxCondSetSize(Size max_k)
maximum conditioning set size; Size(-1) = unlimited (default)
void setStable(bool stable)
stable mode: defer edge removals until end of each depth (default: true)
void setExhaustiveSepSet(bool exhaustive)
exhaustive sepset mode: accumulate union of all separating sets found at each depth,...
void setMandatoryGraph(const gum::DAG &mandaGraph)
void setMaxIndegree(gum::Size n)
void setForbiddenGraph(const gum::DiGraph &forbidGraph)
PDAG learnPDAG(MixedGraph graph)
learns the essential graph (CPDAG)
void addConstraints(const HashTable< std::pair< NodeId, NodeId >, char > &constraints)
DAG learnDAG(MixedGraph graph)
learns a DAG
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...
DBRowGeneratorParser(const typename DatabaseTable::Handler &handler, const DBRowGeneratorSet &generator_set)
default constructor
The class used to pack sets of generators.
The databases' cell translators for labelized variables.
the class for packing together the translators used to preprocess the datasets
std::size_t insertTranslator(const DBTranslator &translator, const std::size_t column, const bool unique_column=true)
inserts a new translator at the end of the translator set
The class representing a tabular database as used by learning tasks.
void changeTranslator(DBTranslator &new_translator, std::size_t k, bool k_is_input_col=false)
change the translator of a database column
DBVector< std::size_t > domainSizes() const
returns the domain sizes of all the variables in the database table
void setVariableNames(const std::vector< std::string > &names, const bool from_external_object=true) override
sets the names of the variables
void reorder(const std::size_t k, const bool k_is_input_col=false)
performs a reordering of the kth translator or of the first translator parsing the kth column of the ...
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...
std::vector< std::pair< Idx, std::shared_ptr< DBTranslator > > > betterTranslators() const
propose a set with translators better suited for the content of the database
PAG learnPAG(MixedGraph graph)
primary FCI output: learn a PAG from the given node-only or partial graph
void setMaxPathLength(Size maxLen)
maximum path length for R4 discriminating-path search; Size(-1) = unlimited
The mecanism to compute the next available graph changes for directed structure learning search algor...
void useArcAdditions(bool use)
sets whether or not the selector allows the application of arc additions
void useArcDeletions(bool use)
sets whether or not the selector allows the application of arc deletions
void useArcReversals(bool use)
sets whether or not the selector allows the application of arc reversals
void useArcTriangleDeletions(bool use)
sets whether or not the selector allows the application of arc triangle deletions
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
a helper to easily read databases
const DatabaseTable & databaseTable() const
returns the internal database table
std::vector< std::size_t > _domain_sizes_
the domain sizes of the variables (useful to speed-up computations)
DatabaseTable _database_
the database itself
double weight(const std::size_t i) const
returns the weight of the ith record
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
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
returns the mapping between node ids and their columns in the database
Database & operator=(const Database &from)
copy operator
DBRowGeneratorParser & parser()
returns the parser for the database
DBRowGeneratorParser * _parser_
the parser used for reading the database
StructuralConstraintPossibleEdges constraintPossibleEdges_
the constraint on possible Edges
MixedGraph preparePC_()
prepares the initial graph and independence test for PC
StructuralConstraintNoParentNodes constraintNoParentNodes_
the constraint on no parent nodes
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
PAG learnPAG()
learn a PAG — only valid when useFCI() has been called
std::string priorDbname_
the filename for the Dirichlet a priori, if any
double priorWeight_
the weight of the prior. It is always written by the useXxxPrior() methods, which read learning....
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done
~IBNLearner() override
destructor
std::string checkScorePriorCompatibility() const
checks whether the current score and prior are compatible
GreedyHillClimbing extendedGreedyHillClimbing_
the extended greedy hill climbing
AlgoType
an enumeration to select easily the learning algorithm to use
@ EXTENDED_GREEDY_HILL_CLIMBING
@ LOCAL_SEARCH_WITH_TABU_LIST
bool allowArcTriangleDeletions_
whether we allow or not arc deletions during learning
virtual void createPrior_()=0
create the prior used for learning
K2 algoK2_
the K2 algorithm
IndepTestType indepTestTypeFCI_
independence test type for FCI (reuses IndepTestType defined above)
AlgoType selectedAlgo_
the learning algorithm ; it is initialized from the configuration, see preferredAlgo()
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges() const
returns the current database rows' ranges used for learning
bool allowArcAdditions_
whether we allow or not arc additions during learning
double logLikelihood(const std::vector< NodeId > &vars, const std::vector< NodeId > &knowing={})
Return the loglikelihood of vars in the base, conditioned by knowing for the BNLearner.
Database scoreDatabase_
the database to be used by the scores and parameter estimators
ScoreType
an enumeration enabling to select easily the score we wish to use
bool useEM_
a Boolean indicating whether we should use EM for parameter learning or not
DAG2BNLearner dag2BN_
the parametric EM
Prior * prior_
the prior used
void useDatabaseRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
use a new set of database rows' ranges to perform learning
std::pair< double, double > chi2(NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
Return the <statistic,pvalue> pair for chi2 test in the database.
CorrectedMutualInformation * mutualInfo_
the selected correction for miic
static AlgoType preferredAlgo()
the algorithm used by the learners when none is selected explicitly
@ DIRICHLET_FROM_DATABASE
Size nbDecreasingChanges_
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
the constraint on no children nodes
static void isCSVFileName_(std::string_view filename)
checks whether the extension of a CSV filename is correct
gum::learning::FCI algoFCI_
the FCI algorithm
ParamEstimatorType paramEstimatorType_
the type of the parameter estimator
ScoreType scoreType_
the score selected for learning
std::pair< double, double > G2(NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
Return the <statistic,pvalue> pair for for G2 test in the database.
const ApproximationScheme * currentAlgorithm_
IndependenceTest * indepTestPC_
owned independence test object for PC (rebuilt before each learn call)
DAG learnDag_()
returns the DAG learnt
Database * priorDatabase_
the database used by the Dirichlet a priori
double mutualInformation(NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
Return the mutual information of id1 and id2 in the base, conditioned by knowing for the BNLearner.
void createScore_()
create the score used for learning
PriorType getPriorType_() const
returns the type (as a string) of a given prior
double alphaFci_
FCI parameters the threshold of the tests ; it is initialized from the key learning....
double alphaPc_
PC parameters the threshold of the tests ; it is initialized from the key learning....
StructuralConstraintIndegree constraintIndegree_
the constraint for indegrees
bool allowArcDeletions_
whether we allow or not arc deletions during learning
PDAG learnPDAG()
learn a partial structure from a file (must have read the db before and must have selected miic)
static DatabaseTable readFile_(std::string_view filename, const std::vector< std::string > &missing_symbols)
reads a file and returns a databaseVectInRam
std::string filename_
the filename database
bool exhaustiveSepSetFci_
bool hasMissingValues() const
returns true if the learner's database has missing values
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name
Score * score_
the score used
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
Miic algoMiic_
the Constraint MIIC algorithm
void createCorrectedMutualInformation_()
create the Corrected Mutual Information instance for Miic
IndepTestType indepTestTypePC_
StructuralConstraintForbiddenArcs constraintForbiddenArcs_
the constraint on forbidden arcs
StructuralConstraintTotalOrder constraintTotalOrder_
the total order ing constraint
GreedyHillClimbing greedyHillClimbing_
the greedy hill climbing algorithm
DAG learnDAG()
learn a structure from a file (must have read the db before)
double score(NodeId vars, const std::vector< NodeId > &knowing={})
Return the value of the score currently in use by the BNLearner of a variable given a set of other va...
StructuralConstraintTabuList constraintTabuList_
the constraint for tabu lists
DAG initialDag_
an initial DAG given to learners
GreedyThickThinning greedyThickThinning_
the greedy thick-thinning algorithm
MixedGraph prepareFCI_()
prepares the initial graph and independence test for FCI
IBNLearner & operator=(const IBNLearner &)
copy operator
gum::learning::PC algoPC_
the PC algorithm
bool allowArcReversals_
whether we allow or not arc reversals during learning
MixedGraph prepareMiic_()
prepares the initial graph for miic
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
LocalSearchWithTabuList localSearchWithTabuList_
the local search with tabu list algorithm
IndependenceTest * indepTestFCI_
owned independence test object for FCI (rebuilt before each learn call)
std::pair< std::size_t, std::size_t > useCrossValidationFold(const std::size_t learning_fold, const std::size_t k_fold)
sets the ranges of rows to be used for cross-validation learning
ParamEstimator * createParamEstimator_(const DBRowGeneratorParser &parser, bool take_into_account_score=true)
create the parameter estimator used for learning
StructuralConstraintSliceOrder constraintSliceOrder_
the constraint for 2TBNs
const DatabaseTable & database() const
returns the database used by the BNLearner
std::vector< double > rawPseudoCount(const std::vector< NodeId > &vars)
Return the pseudo-counts of NodeIds vars in the base in a raw array.
bool inducedTypes_
the policy for typing variables
CorrectedMutualInformation::KModeTypes kmodeMiic_
the penalty used in MIIC
double correctedMutualInformation(NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
Return the mutual information of id1 and id2 in the base, conditioned by knowing for the BNLearner.
bool isConstraintBased() const
indicate if the selected algorithm is constraint-based
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
std::size_t nbRows() const noexcept
returns the number of records (rows) in the database
const DBVector< std::string > & variableNames() const noexcept
returns the variable names for all the columns of the database
iterator handler() const
returns a new unsafe handler pointing to the 1st record of the database
bool hasMissingValues() const
indicates whether the database contains some missing values
const std::string & variableName(const std::size_t k) const
returns the name of the kth column of the IDatabaseTable
std::size_t nbVariables() const noexcept
returns the number of variables (columns) of the database
IdCondSet()
default constructor
the class for computing Chi2 independence test scores
std::pair< double, double > statistics(NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids={}) override
get the pair <chi2 statistic,pvalue> for a test var1 indep var2 given rhs_ids
IndepTestChi2(const DBRowGeneratorParser &parser, const Prior &external_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
the class for computing G2 independence test scores
std::pair< double, double > statistics(NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids={}) override
get the pair <G2statistic,pvalue> for a test var1 indep var2 given rhs_ids
IndepTestG2(const DBRowGeneratorParser &parser, const Prior &external_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
const Sequence< NodeId > & order() const noexcept
returns the current order
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
void setMutualInformation(CorrectedMutualInformation &mi)
NoPrior(const DatabaseTable &database, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ParamEstimatorML(const DBRowGeneratorParser &parser, const Prior &external_prior, const Prior &_score_internal_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
The base class for estimating parameters of CPTs.
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts used by the parameter estimator
void setNumberOfThreads(Size nb) override
sets the number max of threads that can be used
The class for giving access to pseudo count : count in the database + prior.
std::vector< double > get(const std::vector< NodeId > &ids)
returns the pseudo-count of a pair of nodes given some other nodes
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreAIC(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreBD(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreBDeu(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreBIC(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreK2(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
the class for computing Log2-likelihood scores
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScoreLog2Likelihood(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
double score(const IdCondSet &idset)
returns the score for a given IdCondSet
The base class for all the scores used for learning (BIC, BDeu, etc).
const std::vector< std::pair< std::size_t, std::size_t > > & ranges() const
returns the current ranges
virtual const Prior & internalPrior() const =0
returns the internal prior of the score
double score(const NodeId var)
returns the score of a single node
void setRanges(const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
sets new ranges to perform the counts used by the score
void setNumberOfThreads(Size nb) override
sets the number max of threads that can be used
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
ScorefNML(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
The base class for structural constraints imposed by DAGs.
the structural constraint for forbidding the creation of some arcs during structure learning
const ArcSet & arcs() const
returns the set of mandatory arcs
the class for structural constraints limiting the number of parents of nodes in a directed graph
Size maxIndegree() const
sets the default max indegree for all the nodes in the property
the structural constraint indicating that some arcs shall never be removed or reversed
const ArcSet & arcs() const
returns the set of mandatory arcs
the structural constraint for forbidding children for some nodes
const NodeSet & nodes() const
returns the set of w nodes without children
the structural constraint for forbidding parents for some nodes
const NodeSet & nodes() const
returns the set of nodes without parent
the structural constraint for forbidding the creation of some arcs except those defined in the class ...
const EdgeSet & edges() const
returns the set of mandatory arcs
the "meta-programming" class for storing structural constraints
the structural constraint imposing a partial order over nodes
const NodeProperty< NodeId > & sliceOrder() const
returns the current slice order
The class imposing a N-sized tabu list as a structural constraints for learning algorithms.
the structural constraint imposing a total order over some nodes
const Sequence< NodeId > & totalOrder() const
returns the current Total order
Typed, documented, sectioned configuration singleton read from an .ini content.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
the class for computing Chi2 scores
the class for computing G2 scores
include the inlined functions if necessary
DatabaseTable readFile(const std::string &filename)
template class GUM_SHARED_PUBLIC Tensor< double >
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...
the base class for all the independence tests used for learning
the class for computing Log2-likelihood scores