aGrUM  0.14.2
genericBNLearner.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it wil be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
30 #ifndef GUM_LEARNING_GENERIC_BN_LEARNER_H
31 #define GUM_LEARNING_GENERIC_BN_LEARNER_H
32 
33 #include <sstream>
34 #include <memory>
35 
36 #include <agrum/BN/BayesNet.h>
37 #include <agrum/agrum.h>
38 #include <agrum/core/bijection.h>
39 #include <agrum/core/sequence.h>
40 #include <agrum/graphs/DAG.h>
41 
50 
57 
62 
71 
76 
79 
82 
83 #include <agrum/learning/K2.h>
84 #include <agrum/learning/Miic.h>
87 
89 
90 namespace gum {
91 
92  namespace learning {
93 
94  class BNLearnerListener;
95 
104  // private:
105  public:
107  enum class ScoreType { AIC, BD, BDeu, BIC, K2, LOG2LIKELIHOOD };
108 
111  enum class ParamEstimatorType { ML };
112 
114  enum class AprioriType {
115  NO_APRIORI,
116  SMOOTHING,
117  DIRICHLET_FROM_DATABASE,
118  BDEU
119  };
120 
122  enum class AlgoType {
123  K2,
124  GREEDY_HILL_CLIMBING,
125  LOCAL_SEARCH_WITH_TABU_LIST,
126  MIIC_THREE_OFF_TWO
127  };
128 
129 
131  class Database {
132  public:
133  // ########################################################################
135  // ########################################################################
137 
139 
142  explicit Database(const std::string& file,
143  const std::vector< std::string >& missing_symbols);
144 
146 
148  explicit Database(const DatabaseTable<>& db);
149 
151 
161  Database(const std::string& filename,
162  Database& score_database,
163  const std::vector< std::string >& missing_symbols);
164 
166 
172  template < typename GUM_SCALAR >
173  Database(const std::string& filename,
174  const gum::BayesNet< GUM_SCALAR >& bn,
175  const std::vector< std::string >& missing_symbols);
176 
178  Database(const Database& from);
179 
181  Database(Database&& from);
182 
184  ~Database();
185 
187 
188  // ########################################################################
190  // ########################################################################
192 
194  Database& operator=(const Database& from);
195 
197  Database& operator=(Database&& from);
198 
200 
201  // ########################################################################
203  // ########################################################################
205 
207  DBRowGeneratorParser<>& parser();
208 
210  const std::vector< std::size_t >& domainSizes() const;
211 
213  const std::vector< std::string >& names() const;
214 
216  NodeId idFromName(const std::string& var_name) const;
217 
219  const std::string& nameFromId(NodeId id) const;
220 
222  const DatabaseTable<>& databaseTable() const;
223 
226  void setDatabaseWeight(const double new_weight);
227 
229  const Bijection< NodeId, std::size_t >& nodeId2Columns() const;
230 
232  const std::vector< std::string >& missingSymbols() const;
234 
235  protected:
238 
240  DBRowGeneratorParser<>* __parser{nullptr};
241 
243  std::vector< std::size_t > __domain_sizes;
244 
247 
249 #if defined(_OPENMP) && !defined(GUM_DEBUG_MODE)
250  Size __max_threads_number{getMaxNumberOfThreads()};
251 #else
252  Size __max_threads_number{1};
253 #endif /* GUM_DEBUG_MODE */
254 
256  Size __min_nb_rows_per_thread{100};
257 
258  private:
259  // returns the set of variables as a BN. This is convenient for
260  // the constructors of apriori Databases
261  template < typename GUM_SCALAR >
262  BayesNet< GUM_SCALAR > __BNVars() const;
263  };
264 
266  void __setAprioriWeight(double weight);
267 
268  public:
269  // ##########################################################################
271  // ##########################################################################
273 
275 
279  genericBNLearner(const std::string& filename,
280  const std::vector< std::string >& missing_symbols);
282 
302  template < typename GUM_SCALAR >
303  genericBNLearner(const std::string& filename,
304  const gum::BayesNet< GUM_SCALAR >& src,
305  const std::vector< std::string >& missing_symbols);
306 
309 
312 
314  virtual ~genericBNLearner();
315 
317 
318  // ##########################################################################
320  // ##########################################################################
322 
325 
328 
330 
331  // ##########################################################################
333  // ##########################################################################
335 
337  DAG learnDAG();
338 
342 
344  void setInitialDAG(const DAG&);
345 
347  const std::vector< std::string >& names() const;
348 
350  const std::vector< std::size_t >& domainSizes() const;
351 
353 
357  NodeId idFromName(const std::string& var_name) const;
358 
360  const DatabaseTable<>& database() const;
361 
364  void setDatabaseWeight(const double new_weight);
365 
367  const std::string& nameFromId(NodeId id) const;
368 
370 
376  template < template < typename > class XALLOC >
377  void useDatabaseRanges(
378  const std::vector< std::pair< std::size_t, std::size_t >,
379  XALLOC< std::pair< std::size_t, std::size_t > > >&
380  new_ranges);
381 
383  void clearDatabaseRanges();
384 
386 
389  const std::vector< std::pair< std::size_t, std::size_t > >&
390  databaseRanges() const;
391 
393 
413  std::pair< std::size_t, std::size_t >
414  useCrossValidationFold(const std::size_t learning_fold,
415  const std::size_t k_fold);
416 
417 
425  std::pair< double, double > chi2(const NodeId id1,
426  const NodeId id2,
427  const std::vector< NodeId >& knowing = {});
435  std::pair< double, double >
436  chi2(const std::string& name1,
437  const std::string& name2,
438  const std::vector< std::string >& knowing = {});
439 
447  double logLikelihood(const std::vector< NodeId >& vars,
448  const std::vector< NodeId >& knowing = {});
449 
457  double logLikelihood(const std::vector< std::string >& vars,
458  const std::vector< std::string >& knowing = {});
459 
460 
465  Size nbCols() const;
466 
471  Size nbRows() const;
472 
477  void useEM(const double epsilon);
478 
480  bool hasMissingValues() const;
481 
483 
484  // ##########################################################################
486  // ##########################################################################
488 
490  void useScoreAIC();
491 
493  void useScoreBD();
494 
496  void useScoreBDeu();
497 
499  void useScoreBIC();
500 
502  void useScoreK2();
503 
505  void useScoreLog2Likelihood();
506 
508 
509  // ##########################################################################
511  // ##########################################################################
513 
515  void useNoApriori();
516 
518 
521  void useAprioriBDeu(double weight = 1);
522 
524 
527  void useAprioriSmoothing(double weight = 1);
528 
530  void useAprioriDirichlet(const std::string& filename, double weight = 1);
531 
532 
534 
536  std::string checkScoreAprioriCompatibility();
538 
539  // ##########################################################################
541  // ##########################################################################
543 
545  void useGreedyHillClimbing();
546 
548 
551  void useLocalSearchWithTabuList(Size tabu_size = 100, Size nb_decrease = 2);
552 
554  void useK2(const Sequence< NodeId >& order);
555 
557  void useK2(const std::vector< NodeId >& order);
558 
560  void use3off2();
561 
563  void useMIIC();
564 
566 
567  // ##########################################################################
569  // ##########################################################################
573  void useNML();
576  void useMDL();
579  void useNoCorr();
580 
583  const std::vector< Arc > latentVariables() const;
584 
586  // ##########################################################################
588  // ##########################################################################
590 
592  void setMaxIndegree(Size max_indegree);
593 
599  void setSliceOrder(const NodeProperty< NodeId >& slice_order);
600 
605  void setSliceOrder(const std::vector< std::vector< std::string > >& slices);
606 
608  void setForbiddenArcs(const ArcSet& set);
609 
612  void addForbiddenArc(const Arc& arc);
613  void addForbiddenArc(const NodeId tail, const NodeId head);
614  void addForbiddenArc(const std::string& tail, const std::string& head);
616 
619  void eraseForbiddenArc(const Arc& arc);
620  void eraseForbiddenArc(const NodeId tail, const NodeId head);
621  void eraseForbiddenArc(const std::string& tail, const std::string& head);
623 
625  void setMandatoryArcs(const ArcSet& set);
626 
629  void addMandatoryArc(const Arc& arc);
630  void addMandatoryArc(const NodeId tail, const NodeId head);
631  void addMandatoryArc(const std::string& tail, const std::string& head);
633 
636  void eraseMandatoryArc(const Arc& arc);
637  void eraseMandatoryArc(const NodeId tail, const NodeId head);
638  void eraseMandatoryArc(const std::string& tail, const std::string& head);
640 
642 
643  protected:
646 
648  Score<>* __score{nullptr};
649 
652 
654  double __EMepsilon{0.0};
655 
658 
661 
663  Apriori<>* __apriori{nullptr};
664 
666 
668  double __apriori_weight{1.0f};
669 
672 
675 
678 
681 
684 
687 
690 
693 
697 
700 
703 
706 
709 
711  std::vector< std::pair< std::size_t, std::size_t > > __ranges;
712 
715 
717  std::string __apriori_dbname;
718 
721 
722  // the current algorithm as an approximationScheme
724 
726  static DatabaseTable<>
727  __readFile(const std::string& filename,
728  const std::vector< std::string >& missing_symbols);
729 
731  static void __checkFileName(const std::string& filename);
732 
734  void __createApriori();
735 
737  void __createScore();
738 
742  bool take_into_account_score = true);
743 
745  DAG __learnDAG();
746 
749 
751  const std::string& __getAprioriType() const;
752 
755 
756 
757  public:
758  // ##########################################################################
761  // ##########################################################################
762  // in order to not pollute the proper code of genericBNLearner, we
763  // directly
764  // implement those
765  // very simples methods here.
768  const ApproximationScheme* approximationScheme) {
769  __current_algorithm = approximationScheme;
770  }
771 
772  INLINE void
773  distributeProgress(const ApproximationScheme* approximationScheme,
774  Size pourcent,
775  double error,
776  double time) {
777  setCurrentApproximationScheme(approximationScheme);
778 
779  if (onProgress.hasListener()) GUM_EMIT3(onProgress, pourcent, error, time);
780  };
781 
783  INLINE void distributeStop(const ApproximationScheme* approximationScheme,
784  std::string message) {
785  setCurrentApproximationScheme(approximationScheme);
786 
787  if (onStop.hasListener()) GUM_EMIT1(onStop, message);
788  };
790 
795  void setEpsilon(double eps) {
796  __K2.approximationScheme().setEpsilon(eps);
797  __greedy_hill_climbing.setEpsilon(eps);
798  __local_search_with_tabu_list.setEpsilon(eps);
799  __Dag2BN.setEpsilon(eps);
800  };
801 
803  double epsilon() const {
804  if (__current_algorithm != nullptr)
805  return __current_algorithm->epsilon();
806  else
807  GUM_ERROR(FatalError, "No chosen algorithm for learning");
808  };
809 
811  void disableEpsilon() {
813  __greedy_hill_climbing.disableEpsilon();
814  __local_search_with_tabu_list.disableEpsilon();
815  __Dag2BN.disableEpsilon();
816  };
817 
819  void enableEpsilon() {
821  __greedy_hill_climbing.enableEpsilon();
822  __local_search_with_tabu_list.enableEpsilon();
823  __Dag2BN.enableEpsilon();
824  };
825 
828  bool isEnabledEpsilon() const {
829  if (__current_algorithm != nullptr)
831  else
832  GUM_ERROR(FatalError, "No chosen algorithm for learning");
833  };
835 
841  void setMinEpsilonRate(double rate) {
843  __greedy_hill_climbing.setMinEpsilonRate(rate);
844  __local_search_with_tabu_list.setMinEpsilonRate(rate);
845  __Dag2BN.setMinEpsilonRate(rate);
846  };
847 
849  double minEpsilonRate() const {
850  if (__current_algorithm != nullptr)
852  else
853  GUM_ERROR(FatalError, "No chosen algorithm for learning");
854  };
855 
859  __greedy_hill_climbing.disableMinEpsilonRate();
860  __local_search_with_tabu_list.disableMinEpsilonRate();
861  __Dag2BN.disableMinEpsilonRate();
862  };
866  __greedy_hill_climbing.enableMinEpsilonRate();
867  __local_search_with_tabu_list.enableMinEpsilonRate();
868  __Dag2BN.enableMinEpsilonRate();
869  };
872  bool isEnabledMinEpsilonRate() const {
873  if (__current_algorithm != nullptr)
875  else
876  GUM_ERROR(FatalError, "No chosen algorithm for learning");
877  };
879 
885  void setMaxIter(Size max) {
886  __K2.approximationScheme().setMaxIter(max);
887  __greedy_hill_climbing.setMaxIter(max);
888  __local_search_with_tabu_list.setMaxIter(max);
889  __Dag2BN.setMaxIter(max);
890  };
891 
893  Size maxIter() const {
894  if (__current_algorithm != nullptr)
895  return __current_algorithm->maxIter();
896  else
897  GUM_ERROR(FatalError, "No chosen algorithm for learning");
898  };
899 
901  void disableMaxIter() {
903  __greedy_hill_climbing.disableMaxIter();
904  __local_search_with_tabu_list.disableMaxIter();
905  __Dag2BN.disableMaxIter();
906  };
908  void enableMaxIter() {
910  __greedy_hill_climbing.enableMaxIter();
911  __local_search_with_tabu_list.enableMaxIter();
912  __Dag2BN.enableMaxIter();
913  };
916  bool isEnabledMaxIter() const {
917  if (__current_algorithm != nullptr)
919  else
920  GUM_ERROR(FatalError, "No chosen algorithm for learning");
921  };
923 
928 
930  void setMaxTime(double timeout) {
931  __K2.approximationScheme().setMaxTime(timeout);
932  __greedy_hill_climbing.setMaxTime(timeout);
933  __local_search_with_tabu_list.setMaxTime(timeout);
934  __Dag2BN.setMaxTime(timeout);
935  }
936 
938  double maxTime() const {
939  if (__current_algorithm != nullptr)
940  return __current_algorithm->maxTime();
941  else
942  GUM_ERROR(FatalError, "No chosen algorithm for learning");
943  };
944 
946  double currentTime() const {
947  if (__current_algorithm != nullptr)
949  else
950  GUM_ERROR(FatalError, "No chosen algorithm for learning");
951  };
952 
954  void disableMaxTime() {
956  __greedy_hill_climbing.disableMaxTime();
957  __local_search_with_tabu_list.disableMaxTime();
958  __Dag2BN.disableMaxTime();
959  };
960  void enableMaxTime() {
962  __greedy_hill_climbing.enableMaxTime();
963  __local_search_with_tabu_list.enableMaxTime();
964  __Dag2BN.enableMaxTime();
965  };
968  bool isEnabledMaxTime() const {
969  if (__current_algorithm != nullptr)
971  else
972  GUM_ERROR(FatalError, "No chosen algorithm for learning");
973  };
975 
979  void setPeriodSize(Size p) {
981  __greedy_hill_climbing.setPeriodSize(p);
982  __local_search_with_tabu_list.setPeriodSize(p);
983  __Dag2BN.setPeriodSize(p);
984  };
985 
986  Size periodSize() const {
987  if (__current_algorithm != nullptr)
989  else
990  GUM_ERROR(FatalError, "No chosen algorithm for learning");
991  };
993 
996  void setVerbosity(bool v) {
998  __greedy_hill_climbing.setVerbosity(v);
999  __local_search_with_tabu_list.setVerbosity(v);
1000  __Dag2BN.setVerbosity(v);
1001  };
1002 
1003  bool verbosity() const {
1004  if (__current_algorithm != nullptr)
1005  return __current_algorithm->verbosity();
1006  else
1007  GUM_ERROR(FatalError, "No chosen algorithm for learning");
1008  };
1010 
1013 
1015  if (__current_algorithm != nullptr)
1017  else
1018  GUM_ERROR(FatalError, "No chosen algorithm for learning");
1019  };
1020 
1023  if (__current_algorithm != nullptr)
1025  else
1026  GUM_ERROR(FatalError, "No chosen algorithm for learning");
1027  };
1028 
1030  const std::vector< double >& history() const {
1031  if (__current_algorithm != nullptr)
1032  return __current_algorithm->history();
1033  else
1034  GUM_ERROR(FatalError, "No chosen algorithm for learning");
1035  };
1037  };
1038 
1039  } /* namespace learning */
1040 
1041 } /* namespace gum */
1042 
1044 #ifndef GUM_NO_INLINE
1046 #endif /* GUM_NO_INLINE */
1047 
1049 
1050 #endif /* GUM_LEARNING_GENERIC_BN_LEARNER_H */
AlgoType __selected_algo
the selected learning algorithm
the class for structural constraints limiting the number of parents of nodes in a directed graph ...
INLINE void setCurrentApproximationScheme(const ApproximationScheme *approximationScheme)
{@ /// distribute signals
A class that, given a structure and a parameter estimator returns a full Bayes net.
void setMaxIndegree(Size max_indegree)
sets the max indegree
void useScoreBIC()
indicate that we wish to use a BIC score
Class representing a Bayesian Network.
Definition: BayesNet.h:76
double minEpsilonRate() const
Returns the value of the minimal epsilon rate.
void enableMaxTime()
stopping criterion on timeout If the criterion was disabled it will be enabled
KModeTypes
the description type for the complexity correction
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
Score * __score
the score used
A DBRowGenerator class that returns incomplete rows as EM would do.
bool hasMissingValues() const
returns true if the learner&#39;s database has missing values
Database __score_database
the database to be used by the scores and parameter estimators
the base class for structural constraints imposed by DAGs
ApproximationSchemeSTATE stateApproximationScheme() const
history
void setMaxTime(double timeout)
stopping criterion on timeout If the criterion was disabled it will be enabled
CorrectedMutualInformation ::KModeTypes __3off2_kmode
the penalty used in 3off2
the structural constraint for forbidding the creation of some arcs during structure learning ...
Signaler3< Size, double, double > onProgress
Progression, error and time.
void setVerbosity(bool v)
verbosity
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
AprioriType
an enumeration to select the apriori
The class representing a tabular database stored in RAM.
const std::string & __getAprioriType() const
returns the type (as a string) of a given apriori
double __EMepsilon
epsilon for EM. if espilon=0.0 : no EM
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
double maxTime() const
Returns the timeout (in seconds).
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
The class computing n times the corrected mutual information, as used in the 3off2 algorithm...
the class imposing a N-sized tabu list as a structural constraints for learning algorithms ...
static void __checkFileName(const std::string &filename)
checks whether the extension of a CSV filename is correct
gum::ApproximationSchemeListener header file.
The base class for all the scores used for learning (BIC, BDeu, etc)
Definition: score.h:49
void setDatabaseWeight(const double new_weight)
assign a weight to all the rows of the learning database so that the sum of their weights is equal to...
void clearDatabaseRanges()
reset the ranges to the one range corresponding to the whole database
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:40
Approximation Scheme.
the classes to account for structure changes in a graph
the class for computing Log2-likelihood scores
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|) If the criterion was disabl...
the class for computing BIC scores
ScoreType
an enumeration enabling to select easily the score we wish to use
the no a priori class: corresponds to 0 weight-sample
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
void __createScore()
create the score used for learning
INLINE void distributeStop(const ApproximationScheme *approximationScheme, std::string message)
distribute signals
StructuralConstraintSliceOrder __constraint_SliceOrder
the constraint for 2TBNs
the structural constraint indicating that some arcs shall never be removed or reversed ...
Miic __miic_3off2
the 3off2 algorithm
ParamEstimatorType
an enumeration to select the type of parameter estimation we shall apply
void setInitialDAG(const DAG &)
sets an initial DAG structure
INLINE void distributeProgress(const ApproximationScheme *approximationScheme, Size pourcent, double error, double time)
{@ /// distribute signals
const std::string & nameFromId(NodeId id) const
returns the variable name corresponding to a given node id
ParamEstimatorType __param_estimator_type
the type of the parameter estimator
the class for computing BDeu scores
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
the base class for all a priori
Definition: apriori.h:47
unsigned int getMaxNumberOfThreads()
Returns the maximum number of threads at any time.
void setPeriodSize(Size p)
How many samples between two stopping is enable.
DatabaseTable __database
the database itself
the structural constraint imposing a partial order over nodes
MixedGraph __prepare_miic_3off2()
prepares the initial graph for 3off2 or miic
Class representing Bayesian networks.
the class for computing K2 scores (actually their log2 value)
void use3off2()
indicate that we wish to use 3off2
std::pair< double, double > chi2(const NodeId id1, const NodeId id2, const std::vector< NodeId > &knowing={})
Return the <statistic,pvalue> pair for the BNLearner.
double epsilon() const
Get the value of epsilon.
the "meta-programming" class for storing several structural constraints
This file contains getters and setters defintion for ApproximationSchem settings. ...
void useScoreK2()
indicate that we wish to use a K2 score
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void setMinEpsilonRate(double rate)
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).
the class for structural constraints limiting the number of parents of nodes in a directed graph ...
void enableMinEpsilonRate()
Enable stopping criterion on epsilon rate.
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.
const std::vector< std::string > & names() const
returns the names of the variables in the database
double minEpsilonRate() const
Get the value of the minimal epsilon rate.
AprioriType __apriori_type
the a priori selected for the score and parameters
void setVerbosity(bool v)
Set the verbosity on (true) or off (false).
NodeId idFromName(const std::string &var_name) const
returns the node id corresponding to a variable name
the structural constraint for forbidding the creation of some arcs during structure learning ...
The class for generic Hash Tables.
Definition: hashTable.h:676
Size periodSize() const
Returns the period size.
void useScoreLog2Likelihood()
indicate that we wish to use a Log2Likelihood score
CorrectedMutualInformation * __mutual_info
the selected correction for 3off2 and miic
The 3off2 algorithm.
void setMaxTime(double timeout)
Stopping criterion on timeout.
Classes of signaler.
AlgoType
an enumeration to select easily the learning algorithm to use
const std::vector< Arc > latentVariables() const
get the list of arcs hiding latent variables
void disableEpsilon()
Disable stopping criterion on epsilon.
DAG __initial_dag
an initial DAG given to learners
void useNML()
indicate that we wish to use the NML correction for 3off2
Size nbrIterations() const
Returns the number of iterations.
void enableMaxIter()
Enable stopping criterion on max iterations.
the smooth a priori: adds a weight w to all the countings
StructuralConstraintMandatoryArcs __constraint_MandatoryArcs
the constraint on forbidden arcs
A dirichlet priori: computes its N&#39;_ijk from a database.
genericBNLearner(const std::string &filename, const std::vector< std::string > &missing_symbols)
default constructor
void disableMaxTime()
Disable stopping criterion on timeout.
The class for initializing DatabaseTable and RawDatabaseTable instances from CSV files.
void setMandatoryArcs(const ArcSet &set)
assign a set of forbidden arcs
void disableEpsilon()
Disable stopping criterion on epsilon.
Database * __apriori_database
the database used by the Dirichlet a priori
LocalSearchWithTabuList __local_search_with_tabu_list
the local search with tabu list algorithm
const ApproximationScheme * __current_algorithm
the base class for structural constraints used by learning algorithms that learn a directed graph str...
The mecanism to compute the next available graph changes for directed structure learning search algor...
void setPeriodSize(Size p)
how many samples between 2 stopping isEnableds
void enableEpsilon()
Enable stopping criterion on epsilon.
bool isEnabledMinEpsilonRate() const
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.
ParamEstimator * __createParamEstimator(DBRowGeneratorParser<> &parser, bool take_into_account_score=true)
create the parameter estimator used for learning
Signaler1< std::string > onStop
Criteria messageApproximationScheme.
void __createCorrectedMutualInformation()
create the Corrected Mutual Information instance for Miic/3off2
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
double currentTime() const
get the current running time in second (double)
Apriori * __apriori
the apriori used
void useNoCorr()
indicate that we wish to use the NoCorr correction for 3off2
void disableMaxTime()
Disable stopping criterion on timeout.
StructuralConstraintTabuList __constraint_TabuList
the constraint for tabu lists
std::string __apriori_dbname
the filename for the Dirichlet a priori, if any
void enableMaxIter()
Enable stopping criterion on max iterations.
DAG __learnDAG()
returns the DAG learnt
Size maxIter() const
Returns the criterion on number of iterations.
GreedyHillClimbing __greedy_hill_climbing
the greedy hill climbing algorithm
void useLocalSearchWithTabuList(Size tabu_size=100, Size nb_decrease=2)
indicate that we wish to use a local search with tabu list
genericBNLearner & operator=(const genericBNLearner &)
copy operator
void __setAprioriWeight(double weight)
sets the apriori weight
std::string checkScoreAprioriCompatibility()
checks whether the current score and apriori are compatible
DAG2BNLearner __Dag2BN
the parametric EM
void useGreedyHillClimbing()
indicate that we wish to use a greedy hill climbing algorithm
DAG learnDAG()
learn a structure from a file (must have read the db before)
the structural constraint indicating that some arcs shall never be removed or reversed ...
std::vector< std::pair< std::size_t, std::size_t > > __ranges
the set of rows&#39; ranges within the database in which learning is done
void useAprioriSmoothing(double weight=1)
use the apriori smoothing
The greedy hill climbing learning algorithm (for directed graphs)
const std::vector< double > & history() const
Returns the scheme history.
The class representing a tabular database as used by learning tasks.
double maxTime() const
returns the timeout (in seconds)
void useScoreAIC()
indicate that we wish to use an AIC score
MixedGraph learnMixedStructure()
learn a partial structure from a file (must have read the db before and must have selected miic or 3o...
void useK2(const Sequence< NodeId > &order)
indicate that we wish to use K2
The K2 algorithm.
StructuralConstraintIndegree __constraint_Indegree
the constraint for indegrees
ScoreType __score_type
the score selected for learning
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges() const
returns the current database rows&#39; ranges used for learning
ApproximationSchemeSTATE stateApproximationScheme() const
Returns the approximation scheme state.
void setMaxIter(Size max)
Stopping criterion on number of iterations.
virtual ~genericBNLearner()
destructor
void disableMinEpsilonRate()
Disable stopping criterion on epsilon rate.
The local search with tabu list learning algorithm (for directed graphs)
bool isEnabledMaxIter() const
Returns true if stopping criterion on max iterations is enabled, false otherwise. ...
const std::vector< double > & history() const
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
the class for computing Bayesian Dirichlet (BD) log2 scores
A pack of learning algorithms that can easily be used.
class for packing sets of generators
void disableMaxIter()
Disable stopping criterion on max iterations.
static DatabaseTable __readFile(const std::string &filename, const std::vector< std::string > &missing_symbols)
reads a file and returns a databaseVectInRam
void useEM(const double epsilon)
use The EM algorithm to learn paramters
bool verbosity() const
Returns true if verbosity is enabled.
void useAprioriDirichlet(const std::string &filename, double weight=1)
use the Dirichlet apriori
void useDatabaseRanges(const std::vector< std::pair< std::size_t, std::size_t >, XALLOC< std::pair< std::size_t, std::size_t > > > &new_ranges)
use a new set of database rows&#39; ranges to perform learning
double __apriori_weight
the weight of the apriori
double epsilon() const
Returns the value of epsilon.
const std::vector< std::size_t > & domainSizes() const
returns the domain sizes of the variables in the database
Size periodSize() const
how many samples between 2 stopping isEnableds
bool isEnabledEpsilon() const
Returns true if stopping criterion on epsilon is enabled, false otherwise.
void __createApriori()
create the apriori used for learning
bool isEnabledMaxTime() const
Returns true if stopping criterion on timeout is enabled, false otherwise.
The class imposing a N-sized tabu list as a structural constraints for learning algorithms.
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.
double currentTime() const
Returns the current running time in second.
The K2 algorithm.
Definition: K2.h:44
The miic learning algorithm.
Definition: Miic.h:103
void disableMaxIter()
Disable stopping criterion on max iterations.
A pack of learning algorithms that can easily be used.
the class for computing AIC scores
std::vector< std::size_t > __domain_sizes
the domain sizes of the variables (useful to speed-up computations)
void setForbiddenArcs(const ArcSet &set)
assign a set of forbidden arcs
A class that, given a structure and a parameter estimator returns a full Bayes net.
Definition: DAG2BNLearner.h:49
The class for parsing DatabaseTable rows and generating output rows.
Bijection< NodeId, std::size_t > __nodeId2cols
a bijection assigning to each variable name its NodeId
bool verbosity() const
verbosity
void useAprioriBDeu(double weight=1)
use the BDeu apriori
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
const DatabaseTable & database() const
returns the database used by the BNLearner
StructuralConstraintForbiddenArcs __constraint_ForbiddenArcs
the constraint on forbidden arcs
void setSliceOrder(const NodeProperty< NodeId > &slice_order)
sets a partial order on the nodes
ApproximationSchemeSTATE
The different state of an approximation scheme.
The databases&#39; cell translators for labelized variables.
a helper to easily read databases
The base class for estimating parameters of CPTs.
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition: signaler3.h:40
void useMIIC()
indicate that we wish to use MIIC
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
void useScoreBD()
indicate that we wish to use a BD score
void useMDL()
indicate that we wish to use the MDL correction for 3off2
void useScoreBDeu()
indicate that we wish to use a BDeu score
The greedy hill learning algorithm (for directed graphs)
Base class for dag.
Definition: DAG.h:99
void setEpsilon(double eps)
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)| If the criterion was disabled it ...
The local search learning with tabu list algorithm (for directed graphs)
A DBRowGenerator class that returns the rows that are complete (fully observed) w.r.t.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Set of pairs of elements with fast search for both elements.
void setMaxIter(Size max)
stopping criterion on number of iterationsIf the criterion was disabled it will be enabled ...
the no a priori class: corresponds to 0 weight-sample
Base classes for directed acyclic graphs.
void enableMaxTime()
Enable stopping criterion on timeout.
the class for estimating parameters of CPTs using Maximum Likelihood
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
the internal apriori for the BDeu score (N&#39; / (r_i * q_i)
Base class for mixed graphs.
Definition: mixedGraph.h:124
the structural constraint imposing a partial order over nodes
void enableEpsilon()
Enable stopping criterion on epsilon.