aGrUM 3.3.2
a C++ library for (probabilistic) graphical models
IBNLearner.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
52#ifndef GUM_LEARNING_GENERIC_BN_LEARNER_H
53#define GUM_LEARNING_GENERIC_BN_LEARNER_H
54
55#include <cstdint>
56#include <memory>
57#include <sstream>
58
59#include <agrum/agrum.h>
60
94
95namespace gum::learning {
97
105 class GUM_PUBLIC_BN IBNLearner:
107 public ThreadNumberManager {
108 public:
110 enum class ScoreType { AIC, BD, BDeu, BIC, fNML, K2, LOG2LIKELIHOOD, MDL };
111
114 enum class ParamEstimatorType { ML };
115
118 NO_prior,
119 SMOOTHING,
120 DIRICHLET_FROM_DATABASE,
121 DIRICHLET_FROM_BAYESNET,
122 BDEU
123 };
124
126 enum class AlgoType {
128 GREEDY_HILL_CLIMBING,
129 LOCAL_SEARCH_WITH_TABU_LIST,
130 MIIC,
133 EXTENDED_GREEDY_HILL_CLIMBING,
134 GREEDY_THICK_THINNING
135 };
136
138 class GUM_PUBLIC_BN Database {
139 public:
140 // ########################################################################
142 // ########################################################################
144
146
156 explicit Database(std::string_view file,
157 const std::vector< std::string >& missing_symbols,
158 const bool induceTypes = false);
159
161
164 explicit Database(const DatabaseTable& db);
165
167
177 Database(std::string_view filename,
178 const Database& score_database,
179 const std::vector< std::string >& missing_symbols);
180
182
188 template < GUM_Numeric GUM_SCALAR >
189 Database(std::string_view filename,
191 const std::vector< std::string >& missing_symbols);
192
194 Database(const Database& from);
195
197 Database(Database&& from);
198
200 ~Database();
201
203
204 // ########################################################################
206 // ########################################################################
208
210 Database& operator=(const Database& from);
211
213 Database& operator=(Database&& from);
214
216
217 // ########################################################################
219 // ########################################################################
221
224
226 const std::vector< std::size_t >& domainSizes() const;
227
229 const std::vector< std::string >& names() const;
230
232 NodeId idFromName(std::string_view var_name) const;
233
235 const std::string& nameFromId(NodeId id) const;
236
238 const DatabaseTable& databaseTable() const;
239
242 void setDatabaseWeight(const double new_weight);
243
246
248 const std::vector< std::string >& missingSymbols() const;
249
251 std::size_t nbRows() const;
252
254 std::size_t size() const;
255
257
260 void setWeight(const std::size_t i, const double weight);
261
263
265 double weight(const std::size_t i) const;
266
268 double weight() const;
269
271
272 protected:
275
278
280 std::vector< std::size_t > _domain_sizes_;
281
284
287
290
291 private:
292 // returns the set of variables as a BN. This is convenient for
293 // the constructors of prior Databases
294 template < GUM_Numeric GUM_SCALAR >
295 BayesNet< GUM_SCALAR > _BNVars_() const;
296 };
297
298 // ##########################################################################
300 // ##########################################################################
302
315 IBNLearner(std::string_view filename,
316 const std::vector< std::string >& missingSymbols,
317 bool induceTypes = true);
318
319 explicit IBNLearner(const DatabaseTable& db);
320
338 template < GUM_Numeric GUM_SCALAR >
339 IBNLearner(std::string_view filename,
341 const std::vector< std::string >& missing_symbols);
342
344 IBNLearner(const IBNLearner&);
345
348
350 ~IBNLearner() override;
351
353
354 // ##########################################################################
356 // ##########################################################################
358
360 IBNLearner& operator=(const IBNLearner&);
361
363 IBNLearner& operator=(IBNLearner&&);
364
366
367 // ##########################################################################
369 // ##########################################################################
371
373 DAG learnDAG();
374
377 PDAG learnPDAG();
378
381 PAG learnPAG();
382
384 void setInitialDAG(const DAG&);
385
387 DAG initialDAG();
388
390 const std::vector< std::string >& names() const;
391
393 const std::vector< std::size_t >& domainSizes() const;
394 Size domainSize(NodeId var) const;
395 Size domainSize(std::string_view var) const;
396
398
402 NodeId idFromName(std::string_view var_name) const;
403
405 const DatabaseTable& database() const;
406
409 void setDatabaseWeight(const double new_weight);
410
412
415 void setRecordWeight(const std::size_t i, const double weight);
416
418
420 double recordWeight(const std::size_t i) const;
421
423 double databaseWeight() const;
424
426 const std::string& nameFromId(NodeId id) const;
427
429
435 void useDatabaseRanges(const std::vector< std::pair< std::size_t, std::size_t > >& new_ranges);
436
438 void clearDatabaseRanges();
439
441
444 const std::vector< std::pair< std::size_t, std::size_t > >& databaseRanges() const;
445
447
467 std::pair< std::size_t, std::size_t > useCrossValidationFold(const std::size_t learning_fold,
468 const std::size_t k_fold);
469
470
478 std::pair< double, double >
479 chi2(NodeId id1, NodeId id2, const std::vector< NodeId >& knowing = {});
487 std::pair< double, double > chi2(std::string_view name1,
488 std::string_view name2,
489 const std::vector< std::string >& knowing = {});
490
498 std::pair< double, double >
499 G2(NodeId id1, NodeId id2, const std::vector< NodeId >& knowing = {});
507 std::pair< double, double > G2(std::string_view name1,
508 std::string_view name2,
509 const std::vector< std::string >& knowing = {});
510
518 double logLikelihood(const std::vector< NodeId >& vars,
519 const std::vector< NodeId >& knowing = {});
520
528 double logLikelihood(const std::vector< std::string >& vars,
529 const std::vector< std::string >& knowing = {});
530
542 double mutualInformation(NodeId id1, NodeId id2, const std::vector< NodeId >& knowing = {});
543
555 double mutualInformation(std::string_view var1,
556 std::string_view var2,
557 const std::vector< std::string >& knowing = {});
558
559
572 double correctedMutualInformation(NodeId id1,
573 NodeId id2,
574 const std::vector< NodeId >& knowing = {});
575
590 double correctedMutualInformation(std::string_view var1,
591 std::string_view var2,
592 const std::vector< std::string >& knowing = {});
593
602 double score(NodeId vars, const std::vector< NodeId >& knowing = {});
603
613 double score(std::string_view vars, const std::vector< std::string >& knowing = {});
614
620 std::vector< double > rawPseudoCount(const std::vector< NodeId >& vars);
621
627 std::vector< double > rawPseudoCount(const std::vector< std::string >& vars);
632 Size nbCols() const;
633
638 Size nbRows() const;
639
657 void useEM(const double epsilon, const double noise);
658
665 void useEM(const double epsilon);
666
681 void useEMWithRateCriterion(const double epsilon, const double noise);
682
684 void useEMWithRateCriterion(const double epsilon);
685
699 void useEMWithDiffCriterion(const double epsilon, const double noise);
700
702 void useEMWithDiffCriterion(const double epsilon);
703
705 void forbidEM();
706
708 bool isUsingEM() const;
709
719 EMApproximationScheme& EM();
720
722 ApproximationSchemeSTATE EMState() const;
723
725 std::string EMStateMessage() const;
726
728 bool hasMissingValues() const;
729
731
732 // ##########################################################################
734 // ##########################################################################
736
738 void useScoreAIC();
739
741 void useScoreBD();
742
744 void useScoreBDeu();
745
747 void useScoreBIC();
748
750 void useScorefNML();
751
753 void useScoreK2();
754
756 void useScoreLog2Likelihood();
757
759 void useScoreMDL();
760
762
763 // ##########################################################################
765 // ##########################################################################
767
769 void useNoPrior();
770
772
775 void useBDeuPrior(double weight);
776
778 void useBDeuPrior();
779
781
782 void useSmoothingPrior(double weight);
783
786 void useSmoothingPrior();
787
789 void useDirichletPrior(std::string_view filename, double weight);
790
792 void useDirichletPrior(std::string_view filename);
793
795
797 std::string checkScorePriorCompatibility() const;
799
800 // ##########################################################################
802 // ##########################################################################
804
806 void useGreedyHillClimbing();
807
809
821 void useExtendedGreedyHillClimbing();
822
824
827 void useLocalSearchWithTabuList(Size tabu_size, Size nb_decrease);
828
830
833 void useLocalSearchWithTabuList(Size tabu_size);
834
836
839 void useLocalSearchWithTabuList();
840
842 void useK2(const Sequence< NodeId >& order);
843
845 void useK2(const std::vector< NodeId >& order);
846
848 void useMIIC();
849
851 void usePC();
852
854 void useFCI();
855
857 void useGreedyThickThinning();
858
860 void setGreedyThickThinningReversals(bool allow);
861
863 bool greedyThickThinningReversals() const;
864
866 bool isConstraintBased() const;
867
869 bool isScoreBased() const;
870
878 static AlgoType preferredAlgo();
879
880 // ##########################################################################
882 // ##########################################################################
884
889 void allowArcAdditions(bool allow = true);
890
899 void allowArcDeletions(bool allow = true);
900
907 void allowArcReversals(bool allow = true);
908
914 void allowArcTriangleDeletions(bool allow = true);
915
917
918 // ##########################################################################
920 // ##########################################################################
924 void useNMLCorrection();
927 void useMDLCorrection();
930 void useNoCorrection();
931
934 std::vector< Arc > latentVariables() const;
935
937
938 // ##########################################################################
940 // ##########################################################################
942
945 void useChi2Test();
946
949 void useG2Test();
950
954 void setPCAlpha(double alpha);
955
958 void setPCStable(bool stable);
959
962 void setPCMaxCondSetSize(Size max_k);
963
967 void setPCUnshieldedColliderSorted(bool sorted);
968
970
971 // ##########################################################################
973 // ##########################################################################
975
978 void useFCIChi2Test();
979
982 void useFCIG2Test();
983
987 void setFCIAlpha(double alpha);
988
991 void setFCIMaxPathLength(Size max_len);
992
995 void setFCIExhaustiveSepSet(bool exhaustive);
996
999 bool fciExhaustiveSepSet() const;
1000
1002
1003 // ##########################################################################
1005 // ##########################################################################
1007
1009 void setMaxIndegree(Size max_indegree);
1010
1016 void setSliceOrder(const NodeProperty< NodeId >& slice_order);
1017
1024 void setSliceOrder(const std::vector< std::vector< std::string > >& slices);
1025
1031 void unsetSliceOrder();
1032
1050 void setTotalOrder(const Sequence< NodeId >& order);
1051 void setTotalOrder(const std::vector< std::string >& order);
1053
1055 void unsetTotalOrder();
1056
1058
1060 void setForbiddenArcs(const ArcSet& set);
1061
1064 void addForbiddenArc(const Arc& arc);
1065 void addForbiddenArc(NodeId tail, NodeId head);
1066 void addForbiddenArc(std::string_view tail, std::string_view head);
1068
1071 void eraseForbiddenArc(const Arc& arc);
1072 void eraseForbiddenArc(NodeId tail, NodeId head);
1073 void eraseForbiddenArc(std::string_view tail, std::string_view head);
1075
1077 void setMandatoryArcs(const ArcSet& set);
1078
1081 void addMandatoryArc(const Arc& arc);
1082 void addMandatoryArc(NodeId tail, NodeId head);
1083 void addMandatoryArc(std::string_view tail, std::string_view head);
1085
1088 void eraseMandatoryArc(const Arc& arc);
1089 void eraseMandatoryArc(NodeId tail, NodeId head);
1090 void eraseMandatoryArc(std::string_view tail, std::string_view head);
1092
1095 void addNoParentNode(NodeId node);
1096 void addNoParentNode(std::string_view node);
1098
1101 void eraseNoParentNode(NodeId node);
1102 void eraseNoParentNode(std::string_view node);
1103
1106 void addNoChildrenNode(NodeId node);
1107 void addNoChildrenNode(std::string_view node);
1109
1112 void eraseNoChildrenNode(NodeId node);
1113 void eraseNoChildrenNode(std::string_view node);
1115
1120 void setPossibleEdges(const EdgeSet& set);
1121 void setPossibleSkeleton(const UndiGraph& skeleton);
1123
1128 void addPossibleEdge(const Edge& edge);
1129 void addPossibleEdge(NodeId tail, NodeId head);
1130 void addPossibleEdge(std::string_view tail, std::string_view head);
1132
1135 void erasePossibleEdge(const Edge& edge);
1136 void erasePossibleEdge(NodeId tail, NodeId head);
1137 void erasePossibleEdge(std::string_view tail, std::string_view head);
1139
1141
1142 // ##########################################################################
1144 // ##########################################################################
1146
1148
1152 void setNumberOfThreads(Size nb) override;
1153
1155
1156 protected:
1157 PAG learnPAG_();
1158 PDAG learnPDAG_();
1159
1161 void _setPriorWeight_(double weight);
1162
1164 bool inducedTypes_{false};
1165
1168
1170 Score* score_{nullptr};
1171
1174
1176 bool useEM_{false};
1177
1180
1183
1185 Prior* prior_{nullptr};
1186
1188
1191 double priorWeight_{1.0f};
1192
1195
1198
1201
1204
1207
1210
1213
1216
1219
1222
1225
1228
1231
1234
1237
1240
1244
1247
1249 enum class IndepTestType { Chi2, G2 };
1251
1254
1257 double alphaPc_{gum::config().typed< double >("learning", "alpha")};
1258 bool stablePc_{true};
1260 bool sortedUCPc_{false};
1261
1264
1267
1270
1273 double alphaFci_{gum::config().typed< double >("learning", "alpha")};
1276
1279
1282
1285
1288
1291
1294
1296 std::vector< std::pair< std::size_t, std::size_t > > ranges_;
1297
1300
1302 std::string priorDbname_;
1303
1306
1308 std::string filename_{"-"};
1309
1310 // size of the tabu list and number of consecutive decreasing changes tolerated by the local
1311 // search. They are always written by useLocalSearchWithTabuList(), which reads
1312 // `learning.tabuListSize` and `learning.tabuNbDecrease` when no value is given.
1315
1316 // the current algorithm as an approximationScheme
1318
1320 static DatabaseTable readFile_(std::string_view filename,
1321 const std::vector< std::string >& missing_symbols);
1322
1324 static void isCSVFileName_(std::string_view filename);
1325
1327 virtual void createPrior_() = 0;
1328
1330 void createScore_();
1331
1334 bool take_into_account_score = true);
1335
1337 DAG learnDag_();
1338
1341
1344
1347
1349 PriorType getPriorType_() const;
1350
1353
1354 public:
1355 // ##########################################################################
1358 // ##########################################################################
1359 // in order to not pollute the proper code of IBNLearner, we
1360 // directly
1361 // implement those
1362 // very simples methods here.
1364 void setCurrentApproximationScheme(const ApproximationScheme* approximationScheme);
1365
1366 void distributeProgress(const ApproximationScheme* approximationScheme,
1367 Size pourcent,
1368 double error,
1369 double time);
1370
1372 void distributeStop(const ApproximationScheme* approximationScheme, std::string_view message);
1373
1375
1380 void setEpsilon(double eps) override;
1381
1383 double epsilon() const override;
1384
1386 void disableEpsilon() override;
1387
1389 void enableEpsilon() override;
1390
1393 bool isEnabledEpsilon() const override;
1394
1396
1402 void setMinEpsilonRate(double rate) override;
1403
1405 double minEpsilonRate() const override;
1406
1408 void disableMinEpsilonRate() override;
1409
1411 void enableMinEpsilonRate() override;
1412
1415 bool isEnabledMinEpsilonRate() const override;
1416
1418
1424 void setMaxIter(Size max) override;
1425
1427 Size maxIter() const override;
1428
1430 void disableMaxIter() override;
1431
1433 void enableMaxIter() override;
1434
1437 bool isEnabledMaxIter() const override;
1438
1440
1445
1447 void setMaxTime(double timeout) override;
1448
1450 double maxTime() const override;
1451
1453 double currentTime() const override;
1454
1456 void disableMaxTime() override;
1457
1458 void enableMaxTime() override;
1459
1462 bool isEnabledMaxTime() const override;
1463
1465
1469 void setPeriodSize(Size p) override;
1470
1471 Size periodSize() const override;
1472
1474
1477 void setVerbosity(bool v) override;
1478
1479 bool verbosity() const override;
1480
1482
1485
1487
1489 Size nbrIterations() const override;
1490
1492 const std::vector< double >& history() const override;
1493
1495
1496
1499
1507 void EMsetEpsilon(double eps);
1508
1510
1515 double EMEpsilon() const;
1516
1518 void EMdisableEpsilon();
1519
1524 void EMenableEpsilon();
1525
1527 bool EMisEnabledEpsilon() const;
1528
1535 void EMsetMinEpsilonRate(double rate);
1536
1542 double EMMinEpsilonRate() const;
1543
1546
1552
1554 bool EMisEnabledMinEpsilonRate() const;
1555
1561 void EMsetMaxIter(Size max);
1562
1568 Size EMMaxIter() const;
1569
1571 void EMdisableMaxIter();
1572
1574 void EMenableMaxIter();
1575
1578 bool EMisEnabledMaxIter() const;
1579
1585 void EMsetMaxTime(double timeout);
1586
1592 double EMMaxTime() const;
1593
1595 double EMCurrentTime() const;
1596
1598 void EMdisableMaxTime();
1599
1600 void EMenableMaxTime();
1601
1603 bool EMisEnabledMaxTime() const;
1604
1609 void EMsetPeriodSize(Size p);
1610
1611 Size EMPeriodSize() const;
1612
1614 void EMsetVerbosity(bool v);
1615
1617 bool EMVerbosity() const;
1618
1621
1623 Size EMnbrIterations() const;
1624
1629 const std::vector< double >& EMHistory() const;
1630
1632 };
1633
1634 /* namespace learning */
1635} // namespace gum::learning
1636
1638#ifndef GUM_NO_INLINE
1640#endif /* GUM_NO_INLINE */
1641
1643
1644#endif /* GUM_LEARNING_GENERIC_BN_LEARNER_H */
A class that, given a structure and a parameter estimator returns a full Bayes net.
The class for initializing DatabaseTable and RawDatabaseTable instances from CSV files.
A DBRowGenerator class that returns the rows that are complete (fully observed) w....
A DBRowGenerator class that returns incomplete rows as EM would do.
A dirichlet priori: computes its N'_ijk from a database.
FCI (Fast Causal Inference) causal discovery algorithm.
A pack of learning algorithms that can easily be used.
The K2 algorithm.
The Miic algorithm.
PC (Peter-Clark) constraint-based structure learning algorithm.
Class representing a Bayesian network.
Definition BayesNet.h:99
Static math utilities for the chi2 distribution.
Definition chi2.h:71
T typed(std::string_view section, std::string_view key) const
Value of section.key converted according to its declared type.
Base class for dag.
Definition DAG.h:121
ApproximationSchemeSTATE
The different state of an approximation scheme.
Base class for mixed graphs.
Definition mixedGraph.h:150
Partial Ancestral Graph: undirected topology with endpoint marks.
Definition PAG.h:94
Base class for partially directed acyclic graphs.
Definition PDAG.h:134
ThreadNumberManager(Size nb_threads=0)
default constructor
A class that redirects gum_signal from algorithms to the listeners of BNLearn.
The class computing n times the corrected mutual information, as used in the MIIC algorithm.
KModeTypes
the description type for the complexity correction
A class that, given a structure and a parameter estimator returns a full Bayes net.
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
The class representing a tabular database as used by learning tasks.
Fast Causal Inference — PAG learning via constraint-based methods.
Definition FCI.h:79
The greedy hill climbing learning algorithm (for directed graphs).
The greedy thick-thinning learning algorithm (for directed graphs).
a helper to easily read databases
Definition IBNLearner.h:138
const std::vector< std::string > & missingSymbols() const
returns the set of missing symbols taken into account
const DatabaseTable & databaseTable() const
returns the internal database table
Size _min_nb_rows_per_thread_
the minimal number of rows to parse (on average) by thread
Definition IBNLearner.h:289
std::size_t size() const
returns the number of records in the database
std::vector< std::size_t > _domain_sizes_
the domain sizes of the variables (useful to speed-up computations)
Definition IBNLearner.h:280
Database(std::string_view filename, const gum::BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
constructor with a BN providing the variables of interest
DatabaseTable _database_
the database itself
Definition IBNLearner.h:274
const std::string & nameFromId(NodeId id) const
returns the variable name corresponding to a given node id
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
Definition IBNLearner.h:283
Database(std::string_view file, const std::vector< std::string > &missing_symbols, const bool induceTypes=false)
default constructor
const std::vector< std::string > & names() const
returns the names of the variables in the database
void setWeight(const std::size_t i, const double weight)
sets the weight of the ith record
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
Definition IBNLearner.h:277
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name
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_weig...
Size _max_threads_number_
the max number of threads authorized
Definition IBNLearner.h:286
std::size_t nbRows() const
returns the number of records in the database
const std::vector< std::size_t > & domainSizes() const
returns the domain sizes of the variables
A pack of learning algorithms that can easily be used.
Definition IBNLearner.h:107
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
Size periodSize() const override
how many samples between 2 stopping isEnableds
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
void EMenableEpsilon()
Enable the log-likelihood min diff stopping criterion in EM.
bool EMisEnabledEpsilon() const
return true if EM's stopping criterion is the log-likelihood min diff
void EMsetPeriodSize(Size p)
how many samples between 2 stoppings isEnabled
Size nbrIterations() const override
void setMinEpsilonRate(double rate) override
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|) If the criterion was disabl...
Size EMnbrIterations() const
returns the number of iterations performed by the last EM execution
void enableMaxTime() override
stopping criterion on timeout If the criterion was disabled it will be enabled
std::string priorDbname_
the filename for the Dirichlet a priori, if any
IndepTestType
independence test type for PC
double priorWeight_
the weight of the prior. It is always written by the useXxxPrior() methods, which read learning....
void enableEpsilon() override
Enable stopping criterion on epsilon.
double maxTime() const override
returns the timeout (in seconds)
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done
GreedyHillClimbing extendedGreedyHillClimbing_
the extended greedy hill climbing
ParamEstimatorType
an enumeration to select the type of parameter estimation we shall apply
Definition IBNLearner.h:114
AlgoType
an enumeration to select easily the learning algorithm to use
Definition IBNLearner.h:126
void distributeStop(const ApproximationScheme *approximationScheme, std::string_view message)
distribute signals
bool allowArcTriangleDeletions_
whether we allow or not arc deletions during learning
void EMdisableMinEpsilonRate()
Disable the log-likelihood evolution rate stopping criterion.
double EMMaxTime() const
@brief returns EM's timeout (in milliseconds)
virtual void createPrior_()=0
create the prior used for learning
ApproximationSchemeSTATE EMStateApproximationScheme() const
get the current state of EM
const std::vector< double > & history() const override
void setMaxIter(Size max) override
stopping criterion on number of iterationsIf the criterion was disabled it will be enabled
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()
void EMenableMaxIter()
Enable stopping criterion on max iterations.
void enableMinEpsilonRate() override
Enable stopping criterion on epsilon rate.
bool allowArcAdditions_
whether we allow or not arc additions during learning
void setEpsilon(double eps) override
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)| If the criterion was disabled it ...
void EMdisableEpsilon()
Disable the min log-likelihood diff stopping criterion for EM.
bool isEnabledMaxIter() const override
void EMsetMaxIter(Size max)
add a max iteration stopping criterion
Database scoreDatabase_
the database to be used by the scores and parameter estimators
void setMaxTime(double timeout) override
stopping criterion on timeout If the criterion was disabled it will be enabled
double epsilon() const override
Get the value of epsilon.
ScoreType
an enumeration enabling to select easily the score we wish to use
Definition IBNLearner.h:110
double EMEpsilon() const
Get the value of EM's min diff epsilon.
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 EMsetMinEpsilonRate(double rate)
sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate
bool isEnabledMaxTime() const override
double EMMinEpsilonRate() const
Get the value of the minimal log-likelihood evolution rate of EM.
void distributeProgress(const ApproximationScheme *approximationScheme, Size pourcent, double error, double time)
{@ /// distribute signals
void setPeriodSize(Size p) override
how many samples between 2 stopping isEnableds
Size EMMaxIter() const
return the max number of iterations criterion
CorrectedMutualInformation * mutualInfo_
the selected correction for miic
void disableMinEpsilonRate() override
Disable stopping criterion on epsilon rate.
void EMdisableMaxIter()
Disable stopping criterion on max iterations.
static AlgoType preferredAlgo()
the algorithm used by the learners when none is selected explicitly
BNLearnerPriorType
an enumeration to select the prior
Definition IBNLearner.h:117
bool isEnabledMinEpsilonRate() const override
const std::vector< double > & EMHistory() const
returns the history of the last EM execution
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
the constraint on no children nodes
gum::learning::FCI algoFCI_
the FCI algorithm
void EMsetVerbosity(bool v)
sets or unsets EM's verbosity
Size maxIter() const override
ParamEstimatorType paramEstimatorType_
the type of the parameter estimator
ScoreType scoreType_
the score selected for learning
bool EMVerbosity() const
returns the EM's verbosity status
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)
bool isEnabledEpsilon() const override
DAG learnDag_()
returns the DAG learnt
Database * priorDatabase_
the database used by the Dirichlet a priori
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
bool verbosity() const override
verbosity
void disableMaxTime() override
Disable stopping criterion on timeout.
double currentTime() const override
get the current running time in second (double)
void disableEpsilon() override
Disable stopping criterion on epsilon.
std::string filename_
the filename database
void disableMaxIter() override
Disable stopping criterion on max iterations.
Score * score_
the score used
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
Miic algoMiic_
the Constraint MIIC algorithm
void EMenableMaxTime()
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
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
void setVerbosity(bool v) override
verbosity
StructuralConstraintTabuList constraintTabuList_
the constraint for tabu lists
DAG initialDag_
an initial DAG given to learners
GreedyThickThinning greedyThickThinning_
the greedy thick-thinning algorithm
void EMsetMaxTime(double timeout)
add a stopping criterion on timeout
MixedGraph prepareFCI_()
prepares the initial graph and independence test for FCI
ApproximationSchemeSTATE stateApproximationScheme() const override
history
gum::learning::PC algoPC_
the PC algorithm
void EMenableMinEpsilonRate()
Enable the log-likelihood evolution rate stopping criterion.
bool allowArcReversals_
whether we allow or not arc reversals during learning
Size EMPeriodSize() const
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
double EMCurrentTime() const
get the current running time in second (double)
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)
void setCurrentApproximationScheme(const ApproximationScheme *approximationScheme)
{@ /// distribute signals
ParamEstimator * createParamEstimator_(const DBRowGeneratorParser &parser, bool take_into_account_score=true)
create the parameter estimator used for learning
StructuralConstraintSliceOrder constraintSliceOrder_
the constraint for 2TBNs
bool EMisEnabledMinEpsilonRate() const
void EMdisableMaxTime()
Disable EM's timeout stopping criterion.
void EMsetEpsilon(double eps)
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
void enableMaxIter() override
Enable stopping criterion on max iterations.
bool inducedTypes_
the policy for typing variables
CorrectedMutualInformation::KModeTypes kmodeMiic_
the penalty used in MIIC
double minEpsilonRate() const override
Get the value of the minimal epsilon rate.
The base class for all the independence tests used for learning.
The K2 algorithm.
Definition K2.h:63
The local search with tabu list learning algorithm (for directed graphs).
The MIIC learning algorithm.
Definition Miic.h:100
the no a priorclass: corresponds to 0 weight-sample
Definition noPrior.h:65
PC (Peter-Clark) constraint-based structure learning algorithm.
Definition PC.h:74
The base class for estimating parameters of CPTs.
the base class for all a priori
Definition prior.h:84
The base class for all the scores used for learning (BIC, BDeu, etc).
Definition score.h:68
the structural constraint for forbidding the creation of some arcs during structure learning
the class for structural constraints limiting the number of parents of nodes in a directed graph
the structural constraint indicating that some arcs shall never be removed or reversed
the structural constraint for forbidding children for some nodes
the structural constraint for forbidding parents for some nodes
the structural constraint for forbidding the creation of some arcs except those defined in the class ...
the structural constraint imposing a partial order over nodes
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
Class building the essential Graph from a DAGmodel.
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
The mecanism to compute the next available graph changes for directed structure learning search algor...
The greedy thick-thinning learning algorithm (for directed graphs).
void setNumberOfThreads(unsigned int number)
Set the max number of threads to be used when entering the next parallel region.
Definition threads.cpp:55
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
the class for computing Chi2 scores
the class for computing G2 scores
The local search learning with tabu list algorithm (for directed graphs).
include the inlined functions if necessary
Definition CSVParser.h:55
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...
unsigned int getNumberOfThreads()
returns the max number of threads used by default when entering the next parallel region
the class for estimating parameters of CPTs using Maximum Likelihood
the class for computing AIC scores
the class for computing Bayesian Dirichlet (BD) log2 scores
the class for computing BDeu scores
the class for computing K2 scores (actually their log2 value)
the class for computing fNML scores
the base class for structural constraints imposed by DAGs
the structural constraint for forbidding the creation of some arcs during structure learning
the class for structural constraints limiting the number of parents of nodes in a directed graph
the structural constraint indicating that some arcs shall never be removed or reversed
the structural constraint for forbidding children for some nodes during structure learning
the structural constraint for forbidding parents for some nodes during structure learning
the structural constraint for forbidding the creation of some arcs during structure learning
the structural constraint imposing a partial order over nodes
the class imposing a N-sized tabu list as a structural constraints for learning algorithms
the structural constraint imposing a total ordering over some nodes