aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::learning::IBNLearner Class Referenceabstract

A pack of learning algorithms that can easily be used. More...

#include <IBNLearner.h>

Inheritance diagram for gum::learning::IBNLearner:
Collaboration diagram for gum::learning::IBNLearner:

Classes

class  Database
 a helper to easily read databases More...

Public Types

enum class  ScoreType {
  AIC , BD , BDeu , BIC ,
  K2 , LOG2LIKELIHOOD
}
 an enumeration enabling to select easily the score we wish to use More...
enum class  ParamEstimatorType { ML }
 an enumeration to select the type of parameter estimation we shall apply More...
enum class  BNLearnerPriorType {
  NO_prior , SMOOTHING , DIRICHLET_FROM_DATABASE , DIRICHLET_FROM_BAYESNET ,
  BDEU
}
 an enumeration to select the prior More...
enum class  AlgoType { K2 , GREEDY_HILL_CLIMBING , LOCAL_SEARCH_WITH_TABU_LIST , MIIC }
 an enumeration to select easily the learning algorithm to use More...
enum class  ApproximationSchemeSTATE : char {
  Undefined , Continue , Epsilon , Rate ,
  Limit , TimeLimit , Stopped
}
 The different state of an approximation scheme. More...

Public Member Functions

void setMandatoryArcs (const ArcSet &set)
 assign a set of mandatory arcs
Constructors / Destructors
 IBNLearner (const std::string &filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
 read the database file for the score / parameter estimation and var names
 IBNLearner (const DatabaseTable &db)
 read the database file for the score / parameter estimation and var names
template<typename GUM_SCALAR>
 IBNLearner (const std::string &filename, const gum::BayesNet< GUM_SCALAR > &src, const std::vector< std::string > &missing_symbols)
 read the database file for the score / parameter estimation and var names
 IBNLearner (const IBNLearner &)
 copy constructor
 IBNLearner (IBNLearner &&)
 move constructor
virtual ~IBNLearner ()
 destructor
Operators
IBNLearneroperator= (const IBNLearner &)
 copy operator
IBNLearneroperator= (IBNLearner &&)
 move operator
Accessors / Modifiers
DAG learnDAG ()
 learn a structure from a file (must have read the db before)
PDAG learnPDAG ()
 learn a partial structure from a file (must have read the db before and must have selected miic)
void setInitialDAG (const DAG &)
 sets an initial DAG structure
DAG initialDAG ()
 returns the initial DAG structure
const std::vector< std::string > & names () const
 returns the names of the variables in the database
const std::vector< std::size_t > & domainSizes () const
 returns the domain sizes of the variables in the database
Size domainSize (NodeId var) const
 learn a structure from a file (must have read the db before)
Size domainSize (const std::string &var) const
 learn a structure from a file (must have read the db before)
NodeId idFromName (const std::string &var_name) const
 returns the node id corresponding to a variable name
const DatabaseTabledatabase () const
 returns the database used by the BNLearner
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 new_weight
void setRecordWeight (const std::size_t i, const double weight)
 sets the weight of the ith record of the database
double recordWeight (const std::size_t i) const
 returns the weight of the ith record
double databaseWeight () const
 returns the weight of the whole database
const std::string & nameFromId (NodeId id) const
 returns the variable name corresponding to a given node id
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
void clearDatabaseRanges ()
 reset the ranges to the one range corresponding to the whole database
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges () const
 returns the current database rows' ranges used for learning
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
std::pair< double, doublechi2 (NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
 Return the <statistic,pvalue> pair for chi2 test in the database.
std::pair< double, doublechi2 (const std::string &name1, const std::string &name2, const std::vector< std::string > &knowing={})
 Return the <statistic,pvalue> pair for the BNLearner.
std::pair< double, doubleG2 (NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
 Return the <statistic,pvalue> pair for for G2 test in the database.
std::pair< double, doubleG2 (const std::string &name1, const std::string &name2, const std::vector< std::string > &knowing={})
 Return the <statistic,pvalue> pair for for G2 test in the database.
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.
double logLikelihood (const std::vector< std::string > &vars, const std::vector< std::string > &knowing={})
 Return the loglikelihood of vars in the base, conditioned by knowing for the BNLearner.
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.
double mutualInformation (const std::string &var1, const std::string &var2, const std::vector< std::string > &knowing={})
 Return the mutual information of var1 and var2 in the base, conditioned by knowing for the BNLearner.
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.
double correctedMutualInformation (const std::string &var1, const std::string &var2, const std::vector< std::string > &knowing={})
 Return the mutual information of var1 and var2 in the base, conditioned by knowing for the BNLearner.
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 variables.
double score (const std::string &vars, const std::vector< std::string > &knowing={})
 Return the value of the score currently in use by the BNLearner of a variable given a set of other variables The score used is the one currently selected in the BNLearner.
std::vector< doublerawPseudoCount (const std::vector< NodeId > &vars)
 Return the pseudo-counts of NodeIds vars in the base in a raw array.
std::vector< doublerawPseudoCount (const std::vector< std::string > &vars)
 Return the pseudoconts of vars in the base in a raw array.
Size nbCols () const
Size nbRows () const
void useEM (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters
void useEMWithRateCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the rate stopping criterion
void useEMWithDiffCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the diff stopping criterion
void forbidEM ()
 prevent using the EM algorithm for parameter learning
bool isUsingEM () const
 indicates whether we use EM for parameter learning
EMApproximationSchemeEM ()
 returns the EM parameter learning approximation scheme if EM is enabled
ApproximationSchemeSTATE EMState () const
 returns the state of the last EM algorithm executed
std::string EMStateMessage () const
 returns the state of the EM algorithm
bool hasMissingValues () const
 returns true if the learner's database has missing values
Score selection
void useScoreAIC ()
 indicate that we wish to use an AIC score
void useScoreBD ()
 indicate that we wish to use a BD score
void useScoreBDeu ()
 indicate that we wish to use a BDeu score
void useScoreBIC ()
 indicate that we wish to use a BIC score
void useScoreK2 ()
 indicate that we wish to use a K2 score
void useScoreLog2Likelihood ()
 indicate that we wish to use a Log2Likelihood score
a prior selection / parameterization
void useNoPrior ()
 use no prior
void useBDeuPrior (double weight=1.0)
 use the BDeu prior
void useSmoothingPrior (double weight=1)
 use the prior smoothing
void useDirichletPrior (const std::string &filename, double weight=1)
 use the Dirichlet prior from a database
std::string checkScorePriorCompatibility () const
 checks whether the current score and prior are compatible
Learning algorithm selection
void useGreedyHillClimbing ()
 indicate that we wish to use a 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
void useK2 (const Sequence< NodeId > &order)
 indicate that we wish to use K2
void useK2 (const std::vector< NodeId > &order)
 indicate that we wish to use K2
void useMIIC ()
 indicate that we wish to use MIIC
bool isConstraintBased () const
 indicate if the selected algorithm is constraint-based
bool isScoreBased () const
 indicate if the selected algorithm is score-based
MIIC parameterization and specific results
void useNMLCorrection ()
 indicate that we wish to use the NML correction for and MIIC
void useMDLCorrection ()
 indicate that we wish to use the MDL correction for MIIC
void useNoCorrection ()
 indicate that we wish to use the NoCorr correction for MIIC
std::vector< ArclatentVariables () const
 get the list of arcs hiding latent variables
Accessors / Modifiers for adding constraints on learning
void setMaxIndegree (Size max_indegree)
 sets the max indegree
void setSliceOrder (const NodeProperty< NodeId > &slice_order)
 sets a partial order on the nodes
void setSliceOrder (const std::vector< std::vector< std::string > > &slices)
 sets a partial order on the nodes
void setForbiddenArcs (const ArcSet &set)
 assign a set of forbidden arcs
assign a new forbidden arc
void addForbiddenArc (const Arc &arc)
void addForbiddenArc (NodeId tail, NodeId head)
void addForbiddenArc (const std::string &tail, const std::string &head)
remove a forbidden arc
void eraseForbiddenArc (const Arc &arc)
void eraseForbiddenArc (NodeId tail, NodeId head)
void eraseForbiddenArc (const std::string &tail, const std::string &head)
assign a new mandatory arc
void addMandatoryArc (const Arc &arc)
void addMandatoryArc (NodeId tail, NodeId head)
void addMandatoryArc (const std::string &tail, const std::string &head)
remove a mandatory arc
void eraseMandatoryArc (const Arc &arc)
void eraseMandatoryArc (NodeId tail, NodeId head)
void eraseMandatoryArc (const std::string &tail, const std::string &head)
add a node with no parent
void addNoParentNode (NodeId node)
void addNoParentNode (const std::string &node)
remove a node with no parent
void eraseNoParentNode (NodeId node)
void eraseNoParentNode (const std::string &node)
add a node with no children
void addNoChildrenNode (NodeId node)
void addNoChildrenNode (const std::string &node)
remove a node with no children
void eraseNoChildrenNode (NodeId node)
void eraseNoChildrenNode (const std::string &node)
void setPossibleEdges (const EdgeSet &set)
 assign a set of possible edges
void setPossibleSkeleton (const UndiGraph &skeleton)
 assign a set of possible edges
assign a new possible edge
Warning
By default, all edge is possible. However, once at least one possible edge is defined, all other edges not declared possible
void addPossibleEdge (const Edge &edge)
void addPossibleEdge (NodeId tail, NodeId head)
void addPossibleEdge (const std::string &tail, const std::string &head)
remove a possible edge
void erasePossibleEdge (const Edge &edge)
void erasePossibleEdge (NodeId tail, NodeId head)
void erasePossibleEdge (const std::string &tail, const std::string &head)
Multithreading
void setNumberOfThreads (Size nb) override
 sets the number max of threads that can be used
redistribute signals AND implementation of interface
INLINE void setCurrentApproximationScheme (const ApproximationScheme *approximationScheme)
 {@ /// distribute signals
INLINE void distributeProgress (const ApproximationScheme *approximationScheme, Size pourcent, double error, double time)
 {@ /// distribute signals
INLINE void distributeStop (const ApproximationScheme *approximationScheme, const std::string &message)
 distribute signals
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 will be enabled.
double epsilon () const override
 Get the value of epsilon.
void disableEpsilon () override
 Disable stopping criterion on epsilon.
void enableEpsilon () override
 Enable stopping criterion on epsilon.
bool isEnabledEpsilon () 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 disabled it will be enabled.
double minEpsilonRate () const override
 Get the value of the minimal epsilon rate.
void disableMinEpsilonRate () override
 Disable stopping criterion on epsilon rate.
void enableMinEpsilonRate () override
 Enable stopping criterion on epsilon rate.
bool isEnabledMinEpsilonRate () const override
void setMaxIter (Size max) override
 stopping criterion on number of iterationsIf the criterion was disabled it will be enabled
Size maxIter () const override
void disableMaxIter () override
 Disable stopping criterion on max iterations.
void enableMaxIter () override
 Enable stopping criterion on max iterations.
bool isEnabledMaxIter () const override
void setMaxTime (double timeout) override
 stopping criterion on timeout If the criterion was disabled it will be enabled
double maxTime () const override
 returns the timeout (in seconds)
double currentTime () const override
 get the current running time in second (double)
void disableMaxTime () override
 Disable stopping criterion on timeout.
void enableMaxTime () override
 stopping criterion on timeout If the criterion was disabled it will be enabled
bool isEnabledMaxTime () const override
void setPeriodSize (Size p) override
 how many samples between 2 stopping isEnableds
Size periodSize () const override
 how many samples between 2 stopping isEnableds
void setVerbosity (bool v) override
 verbosity
bool verbosity () const override
 verbosity
ApproximationSchemeSTATE stateApproximationScheme () const override
 history
Size nbrIterations () const override
const std::vector< double > & history () const override
EM approximation scheme for parameter learning
void EMsetEpsilon (double eps)
 sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods
double EMEpsilon () const
 Get the value of EM's min diff epsilon.
void EMdisableEpsilon ()
 Disable the min log-likelihood diff stopping criterion for EM.
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 EMsetMinEpsilonRate (double rate)
 sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate
double EMMinEpsilonRate () const
 Get the value of the minimal log-likelihood evolution rate of EM.
void EMdisableMinEpsilonRate ()
 Disable the log-likelihood evolution rate stopping criterion.
void EMenableMinEpsilonRate ()
 Enable the log-likelihood evolution rate stopping criterion.
bool EMisEnabledMinEpsilonRate () const
void EMsetMaxIter (Size max)
 add a max iteration stopping criterion
Size EMMaxIter () const
 return the max number of iterations criterion
void EMdisableMaxIter ()
 Disable stopping criterion on max iterations.
void EMenableMaxIter ()
 Enable stopping criterion on max iterations.
bool EMisEnabledMaxIter () const
void EMsetMaxTime (double timeout)
 add a stopping criterion on timeout
double EMMaxTime () const
 @brief returns EM's timeout (in milliseconds)
double EMCurrentTime () const
 get the current running time in second (double)
void EMdisableMaxTime ()
 Disable EM's timeout stopping criterion.
void EMenableMaxTime ()
 sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods
bool EMisEnabledMaxTime () const
void EMsetPeriodSize (Size p)
 how many samples between 2 stoppings isEnabled
Size EMPeriodSize () const
 sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods
void EMsetVerbosity (bool v)
 sets or unsets EM's verbosity
bool EMVerbosity () const
 returns the EM's verbosity status
ApproximationSchemeSTATE EMStateApproximationScheme () const
 get the current state of EM
Size EMnbrIterations () const
 returns the number of iterations performed by the last EM execution
const std::vector< double > & EMHistory () const
 returns the history of the last EM execution
Getters and setters
std::string messageApproximationScheme () const
 Returns the approximation scheme message.
Accessors/Modifiers
virtual Size getNumberOfThreads () const
 returns the current max number of threads used by the class containing this ThreadNumberManager
bool isGumNumberOfThreadsOverriden () const
 indicates whether the class containing this ThreadNumberManager set its own number of threads

Public Attributes

Signaler3< Size, double, doubleonProgress
 Progression, error and time.
Signaler1< const std::string & > onStop
 Criteria messageApproximationScheme.

Static Public Attributes

static constexpr double default_EM_noise {0.1}
 the default noise amount added to CPTs during EM's initialization (see method useEM())

Protected Member Functions

void _setPriorWeight_ (double weight)
 sets the prior weight
virtual void createPrior_ ()=0
 create the prior used for learning
void createScore_ ()
 create the score used for learning
ParamEstimatorcreateParamEstimator_ (const DBRowGeneratorParser &parser, bool take_into_account_score=true)
 create the parameter estimator used for learning
DAG learnDag_ ()
 returns the DAG learnt
MixedGraph prepareSimpleMiic_ ()
 prepares the initial graph for Simple Miic
MixedGraph prepareMiic_ ()
 prepares the initial graph for miic
PriorType getPriorType_ () const
 returns the type (as a string) of a given prior
void createCorrectedMutualInformation_ ()
 create the Corrected Mutual Information instance for Miic

Static Protected Member Functions

static DatabaseTable readFile_ (const std::string &filename, const std::vector< std::string > &missing_symbols)
 reads a file and returns a databaseVectInRam
static void isCSVFileName_ (const std::string &filename)
 checks whether the extension of a CSV filename is correct

Protected Attributes

bool inducedTypes_ {false}
 the policy for typing variables
ScoreType scoreType_ {ScoreType::BDeu}
 the score selected for learning
Scorescore_ {nullptr}
 the score used
ParamEstimatorType paramEstimatorType_ {ParamEstimatorType::ML}
 the type of the parameter estimator
bool useEM_ {false}
 a Boolean indicating whether we should use EM for parameter learning or not
double noiseEM_ {0.1}
 the noise factor (in (0,1)) used by EM for perturbing the CPT during init
CorrectedMutualInformationmutualInfo_ {nullptr}
 the selected correction for miic
BNLearnerPriorType priorType_ {BNLearnerPriorType::NO_prior}
 the a priorselected for the score and parameters
Priorprior_ {nullptr}
 the prior used
NoPriornoPrior_ {nullptr}
double priorWeight_ {1.0f}
 the weight of the prior
StructuralConstraintSliceOrder constraintSliceOrder_
 the constraint for 2TBNs
StructuralConstraintIndegree constraintIndegree_
 the constraint for indegrees
StructuralConstraintTabuList constraintTabuList_
 the constraint for tabu lists
StructuralConstraintForbiddenArcs constraintForbiddenArcs_
 the constraint on forbidden arcs
StructuralConstraintPossibleEdges constraintPossibleEdges_
 the constraint on possible Edges
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
 the constraint on mandatory arcs
StructuralConstraintNoParentNodes constraintNoParentNodes_
 the constraint on no parent nodes
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
 the constraint on no children nodes
AlgoType selectedAlgo_ {AlgoType::MIIC}
 the selected learning algorithm
K2 algoK2_
 the K2 algorithm
SimpleMiic algoSimpleMiic_
 the MIIC algorithm
Miic algoMiic_
 the Constraint MIIC algorithm
CorrectedMutualInformation::KModeTypes kmodeMiic_
 the penalty used in MIIC
DAG2BNLearner dag2BN_
 the parametric EM
GreedyHillClimbing greedyHillClimbing_
 the greedy hill climbing algorithm
LocalSearchWithTabuList localSearchWithTabuList_
 the local search with tabu list algorithm
Database scoreDatabase_
 the database to be used by the scores and parameter estimators
std::vector< std::pair< std::size_t, std::size_t > > ranges_
 the set of rows' ranges within the database in which learning is done
DatabasepriorDatabase_ {nullptr}
 the database used by the Dirichlet a priori
std::string priorDbname_
 the filename for the Dirichlet a priori, if any
DAG initialDag_
 an initial DAG given to learners
std::string filename_ {"-"}
 the filename database
Size nbDecreasingChanges_ {2}
const ApproximationSchemecurrentAlgorithm_ {nullptr}

Private Attributes

Size _nb_threads_ {0}
 the max number of threads used by the class

Detailed Description

A pack of learning algorithms that can easily be used.

The pack currently contains K2, GreedyHillClimbing and LocalSearchWithTabuList also miic

Definition at line 98 of file IBNLearner.h.

Member Enumeration Documentation

◆ AlgoType

an enumeration to select easily the learning algorithm to use

Enumerator
K2 
GREEDY_HILL_CLIMBING 
LOCAL_SEARCH_WITH_TABU_LIST 
MIIC 

Definition at line 117 of file IBNLearner.h.

117{ K2, GREEDY_HILL_CLIMBING, LOCAL_SEARCH_WITH_TABU_LIST, MIIC };

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 86 of file IApproximationSchemeConfiguration.h.

86 : char {
87 Undefined,
88 Continue,
89 Epsilon,
90 Rate,
91 Limit,
92 TimeLimit,
93 Stopped
94 };

◆ BNLearnerPriorType

an enumeration to select the prior

Enumerator
NO_prior 
SMOOTHING 
DIRICHLET_FROM_DATABASE 
DIRICHLET_FROM_BAYESNET 
BDEU 

Definition at line 108 of file IBNLearner.h.

108 {
109 NO_prior,
110 SMOOTHING,
111 DIRICHLET_FROM_DATABASE,
112 DIRICHLET_FROM_BAYESNET,
113 BDEU
114 };

◆ ParamEstimatorType

an enumeration to select the type of parameter estimation we shall apply

Enumerator
ML 

Definition at line 105 of file IBNLearner.h.

105{ ML };

◆ ScoreType

an enumeration enabling to select easily the score we wish to use

Enumerator
AIC 
BD 
BDeu 
BIC 
K2 
LOG2LIKELIHOOD 

Definition at line 101 of file IBNLearner.h.

101{ AIC, BD, BDeu, BIC, K2, LOG2LIKELIHOOD };

Constructor & Destructor Documentation

◆ IBNLearner() [1/5]

gum::learning::IBNLearner::IBNLearner ( const std::string & filename,
const std::vector< std::string > & missingSymbols,
bool induceTypes = true )

read the database file for the score / parameter estimation and var names

Parameters
filenamethe name of a CSV file containing the dataset
missing_symbolsthe set of symbols in the CSV that should be interpreted as missing values
induceTypeswhen some columns of the dataset have only numerical values, it is certainly be better to tag them as corresponding to integer, range or continuous variables. By setting induceTypes to true (default), this is precisely what the BNLearner will do. If inducedTypes is false, all the values in the dataset are interpreted as "labels", i.e., as categorical values.

Definition at line 201 of file IBNLearner.cpp.

203 :
204 inducedTypes_(induceTypes), scoreDatabase_(filename, missing_symbols, induceTypes),
205 filename_(filename) {
206 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
207
208 GUM_CONSTRUCTOR(IBNLearner)
209 }
IBNLearner(const std::string &filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
read the database file for the score / parameter estimation and var names
Database scoreDatabase_
the database to be used by the scores and parameter estimators
std::string filename_
the filename database
bool inducedTypes_
the policy for typing variables
Definition IBNLearner.h:935

References IBNLearner(), filename_, inducedTypes_, noPrior_, and scoreDatabase_.

Referenced by gum::learning::IBNLearner::Database::Database(), IBNLearner(), IBNLearner(), IBNLearner(), IBNLearner(), IBNLearner(), ~IBNLearner(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IBNLearner() [2/5]

gum::learning::IBNLearner::IBNLearner ( const DatabaseTable & db)
explicit

read the database file for the score / parameter estimation and var names

Parameters
filenamethe name of a CSV file containing the dataset
missing_symbolsthe set of symbols in the CSV that should be interpreted as missing values
induceTypeswhen some columns of the dataset have only numerical values, it is certainly be better to tag them as corresponding to integer, range or continuous variables. By setting induceTypes to true (default), this is precisely what the BNLearner will do. If inducedTypes is false, all the values in the dataset are interpreted as "labels", i.e., as categorical values.

Definition at line 211 of file IBNLearner.cpp.

211 : scoreDatabase_(db) {
212 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
213 GUM_CONSTRUCTOR(IBNLearner)
214 }

References IBNLearner(), noPrior_, and scoreDatabase_.

Here is the call graph for this function:

◆ IBNLearner() [3/5]

template<typename GUM_SCALAR>
gum::learning::IBNLearner::IBNLearner ( const std::string & filename,
const gum::BayesNet< GUM_SCALAR > & src,
const std::vector< std::string > & missing_symbols )

read the database file for the score / parameter estimation and var names

Parameters
filenameThe file to learn from.
srcindicate for some nodes (not necessarily all the nodes of the BN) which modalities they should have and in which order these modalities should be stored into the nodes. For instance, if modalities = { 1 -> {True, False, Big} }, then the node of id 1 in the BN will have 3 modalities, the first one being True, the second one being False, and the third bein Big. The modalities specified by the user will be considered as being exactly those of the variables of the BN (as a consequence, if we find other values in the database, an exception will be raised during learning).
missing_symbolsthe set of symbols in the CSV that should be interpreted as missing values

Definition at line 102 of file IBNLearner_tpl.h.

104 :
105 scoreDatabase_(filename, bn, missing_symbols) {
106 filename_ = filename;
107 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
108 inducedTypes_ = false;
109 GUM_CONSTRUCTOR(IBNLearner);
110 }

References IBNLearner(), filename_, inducedTypes_, noPrior_, and scoreDatabase_.

Here is the call graph for this function:

◆ IBNLearner() [4/5]

gum::learning::IBNLearner::IBNLearner ( const IBNLearner & from)

copy constructor

Definition at line 216 of file IBNLearner.cpp.

216 :
218 inducedTypes_(from.inducedTypes_), scoreType_(from.scoreType_),
219 paramEstimatorType_(from.paramEstimatorType_), useEM_(from.useEM_), noiseEM_(from.noiseEM_),
220 priorType_(from.priorType_), priorWeight_(from.priorWeight_),
221 constraintSliceOrder_(from.constraintSliceOrder_),
222 constraintIndegree_(from.constraintIndegree_), constraintTabuList_(from.constraintTabuList_),
223 constraintForbiddenArcs_(from.constraintForbiddenArcs_),
224 constraintMandatoryArcs_(from.constraintMandatoryArcs_),
225 constraintNoParentNodes_(from.constraintNoParentNodes_),
226 constraintNoChildrenNodes_(from.constraintNoChildrenNodes_),
227 selectedAlgo_(from.selectedAlgo_), algoK2_(from.algoK2_),
228 algoSimpleMiic_(from.algoSimpleMiic_), algoMiic_(from.algoMiic_), kmodeMiic_(from.kmodeMiic_),
229 dag2BN_(from.dag2BN_), greedyHillClimbing_(from.greedyHillClimbing_),
230 localSearchWithTabuList_(from.localSearchWithTabuList_), scoreDatabase_(from.scoreDatabase_),
231 ranges_(from.ranges_), priorDbname_(from.priorDbname_), initialDag_(from.initialDag_),
232 filename_(from.filename_), nbDecreasingChanges_(from.nbDecreasingChanges_) {
233 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
234
235 GUM_CONS_CPY(IBNLearner)
236 }
ThreadNumberManager(Size nb_threads=0)
default constructor
StructuralConstraintNoParentNodes constraintNoParentNodes_
the constraint on no parent nodes
Definition IBNLearner.h:985
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
Definition IBNLearner.h:956
std::string priorDbname_
the filename for the Dirichlet a priori, if any
double priorWeight_
the weight of the prior
Definition IBNLearner.h:964
double noiseEM_
the noise factor (in (0,1)) used by EM for perturbing the CPT during init
Definition IBNLearner.h:950
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done
K2 algoK2_
the K2 algorithm
Definition IBNLearner.h:995
AlgoType selectedAlgo_
the selected learning algorithm
Definition IBNLearner.h:992
bool useEM_
a Boolean indicating whether we should use EM for parameter learning or not
Definition IBNLearner.h:947
DAG2BNLearner dag2BN_
the parametric EM
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
the constraint on no children nodes
Definition IBNLearner.h:988
ParamEstimatorType paramEstimatorType_
the type of the parameter estimator
Definition IBNLearner.h:944
ScoreType scoreType_
the score selected for learning
Definition IBNLearner.h:938
StructuralConstraintIndegree constraintIndegree_
the constraint for indegrees
Definition IBNLearner.h:970
SimpleMiic algoSimpleMiic_
the MIIC algorithm
Definition IBNLearner.h:998
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
Definition IBNLearner.h:982
Miic algoMiic_
the Constraint MIIC algorithm
StructuralConstraintForbiddenArcs constraintForbiddenArcs_
the constraint on forbidden arcs
Definition IBNLearner.h:976
GreedyHillClimbing greedyHillClimbing_
the greedy hill climbing algorithm
StructuralConstraintTabuList constraintTabuList_
the constraint for tabu lists
Definition IBNLearner.h:973
DAG initialDag_
an initial DAG given to learners
LocalSearchWithTabuList localSearchWithTabuList_
the local search with tabu list algorithm
StructuralConstraintSliceOrder constraintSliceOrder_
the constraint for 2TBNs
Definition IBNLearner.h:967
CorrectedMutualInformation::KModeTypes kmodeMiic_
the penalty used in MIIC

References gum::IApproximationSchemeConfiguration::IApproximationSchemeConfiguration(), IBNLearner(), gum::ThreadNumberManager::ThreadNumberManager(), algoK2_, algoMiic_, algoSimpleMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, dag2BN_, filename_, greedyHillClimbing_, inducedTypes_, initialDag_, kmodeMiic_, localSearchWithTabuList_, nbDecreasingChanges_, noiseEM_, noPrior_, paramEstimatorType_, priorDbname_, priorType_, priorWeight_, ranges_, scoreDatabase_, scoreType_, selectedAlgo_, and useEM_.

Here is the call graph for this function:

◆ IBNLearner() [5/5]

gum::learning::IBNLearner::IBNLearner ( IBNLearner && from)

move constructor

Definition at line 238 of file IBNLearner.cpp.

238 :
239 ThreadNumberManager(std::move(from)), inducedTypes_(from.inducedTypes_),
240 scoreType_(from.scoreType_), paramEstimatorType_(from.paramEstimatorType_),
241 useEM_(from.useEM_), noiseEM_(from.noiseEM_), priorType_(from.priorType_),
242 priorWeight_(from.priorWeight_), constraintSliceOrder_(std::move(from.constraintSliceOrder_)),
243 constraintIndegree_(std::move(from.constraintIndegree_)),
244 constraintTabuList_(std::move(from.constraintTabuList_)),
245 constraintForbiddenArcs_(std::move(from.constraintForbiddenArcs_)),
246 constraintMandatoryArcs_(std::move(from.constraintMandatoryArcs_)),
247 constraintNoParentNodes_(std::move(from.constraintNoParentNodes_)),
248 constraintNoChildrenNodes_(std::move(from.constraintNoChildrenNodes_)),
249 selectedAlgo_(from.selectedAlgo_), algoK2_(std::move(from.algoK2_)),
250 algoSimpleMiic_(std::move(from.algoSimpleMiic_)), algoMiic_(std::move(from.algoMiic_)),
251 kmodeMiic_(from.kmodeMiic_), dag2BN_(std::move(from.dag2BN_)),
252 greedyHillClimbing_(std::move(from.greedyHillClimbing_)),
253 localSearchWithTabuList_(std::move(from.localSearchWithTabuList_)),
254 scoreDatabase_(std::move(from.scoreDatabase_)), ranges_(std::move(from.ranges_)),
255 priorDbname_(std::move(from.priorDbname_)), initialDag_(std::move(from.initialDag_)),
256 filename_(std::move(from.filename_)),
257 nbDecreasingChanges_(std::move(from.nbDecreasingChanges_)) {
258 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
259
260 GUM_CONS_MOV(IBNLearner)
261 }

References IBNLearner(), gum::ThreadNumberManager::ThreadNumberManager(), algoK2_, algoMiic_, algoSimpleMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, dag2BN_, filename_, greedyHillClimbing_, inducedTypes_, initialDag_, kmodeMiic_, localSearchWithTabuList_, nbDecreasingChanges_, noiseEM_, noPrior_, paramEstimatorType_, priorDbname_, priorType_, priorWeight_, ranges_, scoreDatabase_, scoreType_, selectedAlgo_, and useEM_.

Here is the call graph for this function:

◆ ~IBNLearner()

gum::learning::IBNLearner::~IBNLearner ( )
virtual

destructor

Definition at line 263 of file IBNLearner.cpp.

263 {
264 if (score_) delete score_;
265
266 if (prior_) delete prior_;
267
268 if (noPrior_) delete noPrior_;
269
270 if (priorDatabase_) delete priorDatabase_;
271
272 if (mutualInfo_) delete mutualInfo_;
273
274 GUM_DESTRUCTOR(IBNLearner)
275 }
Prior * prior_
the prior used
Definition IBNLearner.h:959
CorrectedMutualInformation * mutualInfo_
the selected correction for miic
Definition IBNLearner.h:953
Database * priorDatabase_
the database used by the Dirichlet a priori
Score * score_
the score used
Definition IBNLearner.h:941

References IBNLearner(), mutualInfo_, noPrior_, prior_, priorDatabase_, and score_.

Here is the call graph for this function:

Member Function Documentation

◆ _setPriorWeight_()

INLINE void gum::learning::IBNLearner::_setPriorWeight_ ( double weight)
protected

sets the prior weight

Definition at line 473 of file IBNLearner_inl.h.

473 {
474 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
475
476 priorWeight_ = weight;
478 }
std::string checkScorePriorCompatibility() const
checks whether the current score and prior are compatible
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References checkScorePriorCompatibility(), GUM_ERROR, and priorWeight_.

Referenced by useBDeuPrior(), gum::learning::BNLearner< GUM_SCALAR >::useDirichletPrior(), useDirichletPrior(), and useSmoothingPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addForbiddenArc() [1/3]

INLINE void gum::learning::IBNLearner::addForbiddenArc ( const Arc & arc)

Definition at line 365 of file IBNLearner_inl.h.

365{ constraintForbiddenArcs_.addArc(arc); }

References constraintForbiddenArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc(), addForbiddenArc(), and addForbiddenArc().

Here is the caller graph for this function:

◆ addForbiddenArc() [2/3]

INLINE void gum::learning::IBNLearner::addForbiddenArc ( const std::string & tail,
const std::string & head )

Definition at line 383 of file IBNLearner_inl.h.

383 {
384 addForbiddenArc(Arc(idFromName(tail), idFromName(head)));
385 }
NodeId idFromName(const std::string &var_name) const
returns the node id corresponding to a variable name
void addForbiddenArc(const Arc &arc)

References addForbiddenArc(), and idFromName().

Here is the call graph for this function:

◆ addForbiddenArc() [3/3]

INLINE void gum::learning::IBNLearner::addForbiddenArc ( NodeId tail,
NodeId head )

Definition at line 373 of file IBNLearner_inl.h.

373 {
374 addForbiddenArc(Arc(tail, head));
375 }

References addForbiddenArc().

Here is the call graph for this function:

◆ addMandatoryArc() [1/3]

INLINE void gum::learning::IBNLearner::addMandatoryArc ( const Arc & arc)

Definition at line 398 of file IBNLearner_inl.h.

398{ constraintMandatoryArcs_.addArc(arc); }

References constraintMandatoryArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc(), addMandatoryArc(), and addMandatoryArc().

Here is the caller graph for this function:

◆ addMandatoryArc() [2/3]

INLINE void gum::learning::IBNLearner::addMandatoryArc ( const std::string & tail,
const std::string & head )

Definition at line 436 of file IBNLearner_inl.h.

436 {
437 addMandatoryArc(Arc(idFromName(tail), idFromName(head)));
438 }
void addMandatoryArc(const Arc &arc)

References addMandatoryArc(), and idFromName().

Here is the call graph for this function:

◆ addMandatoryArc() [3/3]

INLINE void gum::learning::IBNLearner::addMandatoryArc ( NodeId tail,
NodeId head )

Definition at line 446 of file IBNLearner_inl.h.

446 {
447 addMandatoryArc(Arc(tail, head));
448 }

References addMandatoryArc().

Here is the call graph for this function:

◆ addNoChildrenNode() [1/2]

INLINE void gum::learning::IBNLearner::addNoChildrenNode ( const std::string & node)

Definition at line 423 of file IBNLearner_inl.h.

423 {
425 }
void addNoChildrenNode(NodeId node)

References addNoChildrenNode(), and idFromName().

Here is the call graph for this function:

◆ addNoChildrenNode() [2/2]

INLINE void gum::learning::IBNLearner::addNoChildrenNode ( NodeId node)

Definition at line 419 of file IBNLearner_inl.h.

419 {
420 constraintNoChildrenNodes_.addNode(node);
421 }

References constraintNoChildrenNodes_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::BNLearner< GUM_SCALAR >::addNoChildrenNode(), and addNoChildrenNode().

Here is the caller graph for this function:

◆ addNoParentNode() [1/2]

INLINE void gum::learning::IBNLearner::addNoParentNode ( const std::string & node)

Definition at line 407 of file IBNLearner_inl.h.

407 {
409 }
void addNoParentNode(NodeId node)

References addNoParentNode(), and idFromName().

Here is the call graph for this function:

◆ addNoParentNode() [2/2]

INLINE void gum::learning::IBNLearner::addNoParentNode ( NodeId node)

Definition at line 405 of file IBNLearner_inl.h.

405{ constraintNoParentNodes_.addNode(node); }

References constraintNoParentNodes_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::BNLearner< GUM_SCALAR >::addNoParentNode(), and addNoParentNode().

Here is the caller graph for this function:

◆ addPossibleEdge() [1/3]

INLINE void gum::learning::IBNLearner::addPossibleEdge ( const Edge & edge)

Definition at line 330 of file IBNLearner_inl.h.

330 {
331 constraintPossibleEdges_.addEdge(edge);
332 }
StructuralConstraintPossibleEdges constraintPossibleEdges_
the constraint on possible Edges
Definition IBNLearner.h:979

References constraintPossibleEdges_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge(), addPossibleEdge(), and addPossibleEdge().

Here is the caller graph for this function:

◆ addPossibleEdge() [2/3]

INLINE void gum::learning::IBNLearner::addPossibleEdge ( const std::string & tail,
const std::string & head )

Definition at line 350 of file IBNLearner_inl.h.

350 {
351 addPossibleEdge(Edge(idFromName(tail), idFromName(head)));
352 }
void addPossibleEdge(const Edge &edge)

References addPossibleEdge(), and idFromName().

Here is the call graph for this function:

◆ addPossibleEdge() [3/3]

INLINE void gum::learning::IBNLearner::addPossibleEdge ( NodeId tail,
NodeId head )

Definition at line 340 of file IBNLearner_inl.h.

340 {
341 addPossibleEdge(Edge(tail, head));
342 }

References addPossibleEdge().

Here is the call graph for this function:

◆ checkScorePriorCompatibility()

std::string gum::learning::IBNLearner::checkScorePriorCompatibility ( ) const

checks whether the current score and prior are compatible

Returns
a non empty string if the prior is somehow compatible with the score.

Definition at line 899 of file IBNLearner.cpp.

899 {
900 if (this->isConstraintBased()) return "";
901
902 const auto prior = getPriorType_();
903
904 switch (scoreType_) {
906 case AIC : return ScoreAIC::isPriorCompatible(prior, priorWeight_);
907
908 case BD : return ScoreBD::isPriorCompatible(prior, priorWeight_);
909
910 case BDeu : return ScoreBDeu::isPriorCompatible(prior, priorWeight_);
911
912 case BIC : return ScoreBIC::isPriorCompatible(prior, priorWeight_);
913
914 case K2 : return ScoreK2::isPriorCompatible(prior, priorWeight_);
915
917
918 default : return "IBNLearner does not support yet this score";
919 }
920 }
ScoreType
an enumeration enabling to select easily the score we wish to use
Definition IBNLearner.h:101
bool isConstraintBased() const
indicate if the selected algorithm is constraint-based
Definition IBNLearner.h:777
PriorType getPriorType_() const
returns the type (as a string) of a given prior
virtual std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
virtual 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
virtual std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
virtual std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score
virtual std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score

References AIC, BD, BDeu, BIC, getPriorType_(), isConstraintBased(), gum::learning::ScoreAIC::isPriorCompatible(), gum::learning::ScoreBD::isPriorCompatible(), gum::learning::ScoreBDeu::isPriorCompatible(), gum::learning::ScoreBIC::isPriorCompatible(), gum::learning::ScoreK2::isPriorCompatible(), gum::learning::ScoreLog2Likelihood::isPriorCompatible(), LOG2LIKELIHOOD, priorWeight_, and scoreType_.

Referenced by _setPriorWeight_(), useBDeuPrior(), gum::learning::BNLearner< GUM_SCALAR >::useDirichletPrior(), useDirichletPrior(), useNoPrior(), useScoreAIC(), useScoreBD(), useScoreBDeu(), useScoreBIC(), useScoreK2(), useScoreLog2Likelihood(), and useSmoothingPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chi2() [1/2]

std::pair< double, double > gum::learning::IBNLearner::chi2 ( const std::string & name1,
const std::string & name2,
const std::vector< std::string > & knowing = {} )

Return the <statistic,pvalue> pair for the BNLearner.

Parameters
id1first variable
id2second variable
knowinglist of observed variables
Returns
a std::pair<double,double>

Definition at line 970 of file IBNLearner.cpp.

972 {
973 std::vector< NodeId > knowingIds;
974 std::transform(knowing.begin(),
975 knowing.end(),
976 std::back_inserter(knowingIds),
977 [this](const std::string& c) { return this->idFromName(c); });
978 return chi2(idFromName(name1), idFromName(name2), knowingIds);
979 }
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.

References chi2(), and idFromName().

Here is the call graph for this function:

◆ chi2() [2/2]

std::pair< double, double > gum::learning::IBNLearner::chi2 ( NodeId id1,
NodeId id2,
const std::vector< NodeId > & knowing = {} )

Return the <statistic,pvalue> pair for chi2 test in the database.

Parameters
id1first variable
id2second variable
knowinglist of observed variables
Returns
a std::pair<double,double>

Definition at line 963 of file IBNLearner.cpp.

963 {
964 createPrior_();
965 gum::learning::IndepTestChi2 chi2score(scoreDatabase_.parser(), *prior_, databaseRanges());
966
967 return chi2score.statistics(id1, id2, knowing);
968 }
virtual void createPrior_()=0
create the prior used for learning
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges() const
returns the current database rows' ranges used for learning

References createPrior_(), databaseRanges(), prior_, scoreDatabase_, and gum::learning::IndepTestChi2::statistics().

Referenced by chi2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearDatabaseRanges()

INLINE void gum::learning::IBNLearner::clearDatabaseRanges ( )

reset the ranges to the one range corresponding to the whole database

Definition at line 558 of file IBNLearner_inl.h.

558{ ranges_.clear(); }

References ranges_.

◆ correctedMutualInformation() [1/2]

double gum::learning::IBNLearner::correctedMutualInformation ( const std::string & var1,
const std::string & var2,
const std::vector< std::string > & knowing = {} )

Return the mutual information of var1 and var2 in the base, conditioned by knowing for the BNLearner.

Warning
This function returns the mutual information corrected using defined correction (useNML, useMDL) and prior
This function returns the bare mutual information (without prior or correction)
Parameters
var1name of a row
var2name of a row
knowingan optional vector of conditioning rows
Returns
a double

Definition at line 1053 of file IBNLearner.cpp.

1055 {
1056 std::vector< NodeId > knowingIds;
1057
1058 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1059
1060 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1061
1062 return correctedMutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1063 }
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.

References correctedMutualInformation(), and idFromName().

Here is the call graph for this function:

◆ correctedMutualInformation() [2/2]

double gum::learning::IBNLearner::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.

Warning
This function returns the mutual information corrected using defined correction (useNML, useMDL) and prior
Parameters
id1nodeId
id2nodeId
knowingan optional vector of conditioning NodeIds
Returns
a double

Definition at line 1028 of file IBNLearner.cpp.

1030 {
1031 createPrior_();
1032 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(),
1033 *prior_,
1034 databaseRanges());
1035
1036 switch (kmodeMiic_) {
1038 case MDL : cmi.useMDL(); break;
1039
1040 case NML : cmi.useNML(); break;
1041
1042 case NoCorr : cmi.useNoCorr(); break;
1043
1044 default :
1045 GUM_ERROR(NotImplementedYet,
1046 "The BNLearner's corrected mutual information class does "
1047 << "not implement yet this correction : " << int(kmodeMiic_))
1048 }
1049 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1050 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1051 }
KModeTypes
the description type for the complexity correction
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References createPrior_(), databaseRanges(), GUM_ERROR, kmodeMiic_, prior_, gum::learning::CorrectedMutualInformation::score(), scoreDatabase_, gum::learning::CorrectedMutualInformation::useMDL(), gum::learning::CorrectedMutualInformation::useNML(), and gum::learning::CorrectedMutualInformation::useNoCorr().

Referenced by correctedMutualInformation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createCorrectedMutualInformation_()

void gum::learning::IBNLearner::createCorrectedMutualInformation_ ( )
protected

create the Corrected Mutual Information instance for Miic

Definition at line 710 of file IBNLearner.cpp.

710 {
711 if (mutualInfo_ != nullptr) delete mutualInfo_;
712
713 mutualInfo_ = new CorrectedMutualInformation(scoreDatabase_.parser(),
714 *noPrior_,
715 ranges_,
716 scoreDatabase_.nodeId2Columns());
717 switch (kmodeMiic_) {
719 case MDL : mutualInfo_->useMDL(); break;
720 case NML : mutualInfo_->useNML(); break;
721 case NoCorr : mutualInfo_->useNoCorr(); break;
722 default :
723 GUM_ERROR(NotImplementedYet,
724 "The BNLearner's corrected mutual information class does "
725 << "not implement yet this correction : " << int(kmodeMiic_))
726 }
727 }

References GUM_ERROR, kmodeMiic_, mutualInfo_, noPrior_, ranges_, and scoreDatabase_.

Referenced by prepareMiic_().

Here is the caller graph for this function:

◆ createParamEstimator_()

ParamEstimator * gum::learning::IBNLearner::createParamEstimator_ ( const DBRowGeneratorParser & parser,
bool take_into_account_score = true )
protected

create the parameter estimator used for learning

Definition at line 527 of file IBNLearner.cpp.

528 {
529 ParamEstimator* param_estimator = nullptr;
530
531 // create the new estimator
532 switch (paramEstimatorType_) {
534 if (take_into_account_score && (score_ != nullptr)) {
535 param_estimator = new ParamEstimatorML(parser,
536 *prior_,
537 score_->internalPrior(),
538 ranges_,
539 scoreDatabase_.nodeId2Columns());
540 } else {
541 param_estimator = new ParamEstimatorML(parser,
542 *prior_,
543 *noPrior_,
544 ranges_,
545 scoreDatabase_.nodeId2Columns());
546 }
547
548 break;
549
550 default :
551 GUM_ERROR(OperationNotAllowed,
552 "IBNLearner does not support " << "yet this parameter estimator")
553 }
554
555 // assign the number of threads
556 param_estimator->setNumberOfThreads(
558
559 // assign the set of ranges
560 param_estimator->setRanges(ranges_);
561
562 return param_estimator;
563 }
bool isGumNumberOfThreadsOverriden() const
indicates whether the class containing this ThreadNumberManager set its own number of threads
virtual Size getNumberOfThreads() const
returns the current max number of threads used by the class containing this ThreadNumberManager

References gum::ThreadNumberManager::getNumberOfThreads(), GUM_ERROR, gum::ThreadNumberManager::isGumNumberOfThreadsOverriden(), ML, noPrior_, paramEstimatorType_, prior_, ranges_, score_, scoreDatabase_, gum::learning::ParamEstimator::setNumberOfThreads(), and gum::learning::ParamEstimator::setRanges().

Here is the call graph for this function:

◆ createPrior_()

virtual void gum::learning::IBNLearner::createPrior_ ( )
protectedpure virtual

create the prior used for learning

Implemented in gum::learning::BNLearner< GUM_SCALAR >.

Referenced by chi2(), correctedMutualInformation(), G2(), learnDAG(), logLikelihood(), rawPseudoCount(), and score().

Here is the caller graph for this function:

◆ createScore_()

void gum::learning::IBNLearner::createScore_ ( )
protected

create the score used for learning

Definition at line 468 of file IBNLearner.cpp.

468 {
469 // first, save the old score, to be delete if everything is ok
470 Score* old_score = score_;
471
472 // create the new scoring function
473 switch (scoreType_) {
474 case ScoreType::AIC :
475 score_ = new ScoreAIC(scoreDatabase_.parser(),
476 *prior_,
477 ranges_,
478 scoreDatabase_.nodeId2Columns());
479 break;
480
481 case ScoreType::BD :
482 score_ = new ScoreBD(scoreDatabase_.parser(),
483 *prior_,
484 ranges_,
485 scoreDatabase_.nodeId2Columns());
486 break;
487
488 case ScoreType::BDeu :
489 score_ = new ScoreBDeu(scoreDatabase_.parser(),
490 *prior_,
491 ranges_,
492 scoreDatabase_.nodeId2Columns());
493 break;
494
495 case ScoreType::BIC :
496 score_ = new ScoreBIC(scoreDatabase_.parser(),
497 *prior_,
498 ranges_,
499 scoreDatabase_.nodeId2Columns());
500 break;
501
502 case ScoreType::K2 :
503 score_ = new ScoreK2(scoreDatabase_.parser(),
504 *prior_,
505 ranges_,
506 scoreDatabase_.nodeId2Columns());
507 break;
508
510 score_ = new ScoreLog2Likelihood(scoreDatabase_.parser(),
511 *prior_,
512 ranges_,
513 scoreDatabase_.nodeId2Columns());
514 break;
515
516 default : GUM_ERROR(OperationNotAllowed, "IBNLearner does not support yet this score")
517 }
518
519 // remove the old score, if any
520 if (old_score != nullptr) delete old_score;
521
522 // assign the number of threads
523 score_->setNumberOfThreads(this->isGumNumberOfThreadsOverriden() ? this->getNumberOfThreads()
524 : 0);
525 }

References AIC, BD, BDeu, BIC, gum::ThreadNumberManager::getNumberOfThreads(), GUM_ERROR, gum::ThreadNumberManager::isGumNumberOfThreadsOverriden(), K2, LOG2LIKELIHOOD, prior_, ranges_, score_, scoreDatabase_, and scoreType_.

Referenced by learnDAG(), and score().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ currentTime()

double gum::learning::IBNLearner::currentTime ( ) const
inlineoverridevirtual

get the current running time in second (double)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1243 of file IBNLearner.h.

1243 {
1244 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->currentTime();
1245 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1246 }
const ApproximationScheme * currentAlgorithm_

References currentAlgorithm_, and GUM_ERROR.

◆ database()

INLINE const DatabaseTable & gum::learning::IBNLearner::database ( ) const

returns the database used by the BNLearner

Definition at line 561 of file IBNLearner_inl.h.

561 {
562 return scoreDatabase_.databaseTable();
563 }

References scoreDatabase_.

Referenced by readFile_().

Here is the caller graph for this function:

◆ databaseRanges()

INLINE const std::vector< std::pair< std::size_t, std::size_t > > & gum::learning::IBNLearner::databaseRanges ( ) const

returns the current database rows' ranges used for learning

Returns
The method returns a vector of pairs [Xi,Yi) of indices of rows in the database. The learning is performed on these set of rows.
Warning
an empty set of ranges means the whole database.

Definition at line 553 of file IBNLearner_inl.h.

553 {
554 return ranges_;
555 }

References ranges_.

Referenced by chi2(), correctedMutualInformation(), G2(), logLikelihood(), mutualInformation(), and rawPseudoCount().

Here is the caller graph for this function:

◆ databaseWeight()

INLINE double gum::learning::IBNLearner::databaseWeight ( ) const

returns the weight of the whole database

Definition at line 160 of file IBNLearner_inl.h.

160{ return scoreDatabase_.weight(); }

References scoreDatabase_.

◆ disableEpsilon()

void gum::learning::IBNLearner::disableEpsilon ( )
inlineoverridevirtual

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1122 of file IBNLearner.h.

1122 {
1123 algoK2_.approximationScheme().disableEpsilon();
1124 greedyHillClimbing_.disableEpsilon();
1125 localSearchWithTabuList_.disableEpsilon();
1126 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMaxIter()

void gum::learning::IBNLearner::disableMaxIter ( )
inlineoverridevirtual

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1202 of file IBNLearner.h.

1202 {
1203 algoK2_.approximationScheme().disableMaxIter();
1204 greedyHillClimbing_.disableMaxIter();
1205 localSearchWithTabuList_.disableMaxIter();
1206 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMaxTime()

void gum::learning::IBNLearner::disableMaxTime ( )
inlineoverridevirtual

Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1249 of file IBNLearner.h.

1249 {
1250 algoK2_.approximationScheme().disableMaxTime();
1251 greedyHillClimbing_.disableMaxTime();
1252 localSearchWithTabuList_.disableMaxTime();
1253 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMinEpsilonRate()

void gum::learning::IBNLearner::disableMinEpsilonRate ( )
inlineoverridevirtual

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1162 of file IBNLearner.h.

1162 {
1163 algoK2_.approximationScheme().disableMinEpsilonRate();
1164 greedyHillClimbing_.disableMinEpsilonRate();
1165 localSearchWithTabuList_.disableMinEpsilonRate();
1166 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ distributeProgress()

INLINE void gum::learning::IBNLearner::distributeProgress ( const ApproximationScheme * approximationScheme,
Size pourcent,
double error,
double time )
inline

{@ /// distribute signals

Definition at line 1086 of file IBNLearner.h.

1089 {
1090 setCurrentApproximationScheme(approximationScheme);
1091
1092 if (onProgress.hasListener()) GUM_EMIT3(onProgress, pourcent, error, time);
1093 };
Signaler3< Size, double, double > onProgress
Progression, error and time.
INLINE void setCurrentApproximationScheme(const ApproximationScheme *approximationScheme)
{@ /// distribute signals
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition signaler3.h:61

References GUM_EMIT3, gum::IApproximationSchemeConfiguration::onProgress, and setCurrentApproximationScheme().

Here is the call graph for this function:

◆ distributeStop()

INLINE void gum::learning::IBNLearner::distributeStop ( const ApproximationScheme * approximationScheme,
const std::string & message )
inline

distribute signals

Definition at line 1096 of file IBNLearner.h.

1097 {
1098 setCurrentApproximationScheme(approximationScheme);
1099
1100 if (onStop.hasListener()) GUM_EMIT1(onStop, message);
1101 };
Signaler1< const std::string & > onStop
Criteria messageApproximationScheme.
#define GUM_EMIT1(signal, arg1)
Definition signaler1.h:61

References GUM_EMIT1, gum::IApproximationSchemeConfiguration::onStop, and setCurrentApproximationScheme().

Here is the call graph for this function:

◆ domainSize() [1/2]

INLINE Size gum::learning::IBNLearner::domainSize ( const std::string & var) const

learn a structure from a file (must have read the db before)

Definition at line 547 of file IBNLearner_inl.h.

547 {
548 return scoreDatabase_.domainSizes()[idFromName(var)];
549 }

References idFromName(), and scoreDatabase_.

Here is the call graph for this function:

◆ domainSize() [2/2]

INLINE Size gum::learning::IBNLearner::domainSize ( NodeId var) const

learn a structure from a file (must have read the db before)

Definition at line 544 of file IBNLearner_inl.h.

544{ return scoreDatabase_.domainSizes()[var]; }

References scoreDatabase_.

◆ domainSizes()

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

returns the domain sizes of the variables in the database

Definition at line 539 of file IBNLearner_inl.h.

539 {
540 return scoreDatabase_.domainSizes();
541 }

References scoreDatabase_.

◆ EM()

INLINE EMApproximationScheme & gum::learning::IBNLearner::EM ( )

returns the EM parameter learning approximation scheme if EM is enabled

returns the EM parameter learning approximation scheme

Returns
returns the EM parameter learning approximation scheme if EM is enabled, else if raises a NotFound exception. The scheme can then be subsequently used to fine-tune the EM algorithm, e.g., by setting its max time or max number of iterations.
Exceptions
NotFoundis raised if EM() is called while the EM algorithm has not been enabled by useEM(), useEMWithDiffCriterion() or useEMWithRateCriterion().

Definition at line 298 of file IBNLearner_inl.h.

298 {
299 if (useEM_) return dag2BN_;
300 else GUM_ERROR(NotFound, "EM is currently forbidden. Please enable it with useEM()")
301 }

References dag2BN_, GUM_ERROR, and useEM_.

◆ EMCurrentTime()

double gum::learning::IBNLearner::EMCurrentTime ( ) const
inline

get the current running time in second (double)

Definition at line 1422 of file IBNLearner.h.

1422{ return dag2BN_.currentTime(); }

References dag2BN_.

◆ EMdisableEpsilon()

void gum::learning::IBNLearner::EMdisableEpsilon ( )
inline

Disable the min log-likelihood diff stopping criterion for EM.

Definition at line 1345 of file IBNLearner.h.

1345{ dag2BN_.disableEpsilon(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMdisableEpsilon().

Here is the caller graph for this function:

◆ EMdisableMaxIter()

void gum::learning::IBNLearner::EMdisableMaxIter ( )
inline

Disable stopping criterion on max iterations.

Definition at line 1398 of file IBNLearner.h.

1398{ dag2BN_.disableMaxIter(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMdisableMaxIter().

Here is the caller graph for this function:

◆ EMdisableMaxTime()

void gum::learning::IBNLearner::EMdisableMaxTime ( )
inline

Disable EM's timeout stopping criterion.

Definition at line 1425 of file IBNLearner.h.

1425{ dag2BN_.disableMaxTime(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMdisableMaxTime().

Here is the caller graph for this function:

◆ EMdisableMinEpsilonRate()

void gum::learning::IBNLearner::EMdisableMinEpsilonRate ( )
inline

Disable the log-likelihood evolution rate stopping criterion.

Definition at line 1372 of file IBNLearner.h.

1372{ dag2BN_.disableMinEpsilonRate(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMdisableMinEpsilonRate().

Here is the caller graph for this function:

◆ EMenableEpsilon()

void gum::learning::IBNLearner::EMenableEpsilon ( )
inline

Enable the log-likelihood min diff stopping criterion in EM.

Warning
setting this stopping criterion disables the min rate criterion (if it was enabled)

Definition at line 1351 of file IBNLearner.h.

1351{ dag2BN_.enableEpsilon(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMenableEpsilon().

Here is the caller graph for this function:

◆ EMenableMaxIter()

void gum::learning::IBNLearner::EMenableMaxIter ( )
inline

Enable stopping criterion on max iterations.

Definition at line 1401 of file IBNLearner.h.

1401{ dag2BN_.enableMaxIter(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMenableMaxIter().

Here is the caller graph for this function:

◆ EMenableMaxTime()

void gum::learning::IBNLearner::EMenableMaxTime ( )
inline

sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods

Parameters
epsthe log-likelihood difference below which EM stops its iterations
Warning
setting this stopping criterion disables the min rate criterion (if it was enabled)
Exceptions
OutOfBoundsif eps <= 0

Definition at line 1427 of file IBNLearner.h.

1427{ dag2BN_.enableMaxTime(); };

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMenableMaxTime().

Here is the caller graph for this function:

◆ EMenableMinEpsilonRate()

void gum::learning::IBNLearner::EMenableMinEpsilonRate ( )
inline

Enable the log-likelihood evolution rate stopping criterion.

Warning
setting this stopping criterion disables the min diff criterion (if it was enabled)

Definition at line 1378 of file IBNLearner.h.

1378{ dag2BN_.enableMinEpsilonRate(); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMenableMinEpsilonRate().

Here is the caller graph for this function:

◆ EMEpsilon()

double gum::learning::IBNLearner::EMEpsilon ( ) const
inline

Get the value of EM's min diff epsilon.

Get the value of EM's min diff epsilon

Warning
Note that this value is not taken into account unless the min diff criterion is enabled

Definition at line 1342 of file IBNLearner.h.

1342{ return dag2BN_.epsilon(); }

References dag2BN_.

◆ EMHistory()

const std::vector< double > & gum::learning::IBNLearner::EMHistory ( ) const
inline

returns the history of the last EM execution

Warning
to activate the history recording, EM's verbosity must be set to true

Definition at line 1458 of file IBNLearner.h.

1458{ return dag2BN_.history(); }

References dag2BN_.

◆ EMisEnabledEpsilon()

bool gum::learning::IBNLearner::EMisEnabledEpsilon ( ) const
inline

return true if EM's stopping criterion is the log-likelihood min diff

Definition at line 1354 of file IBNLearner.h.

1354{ return dag2BN_.isEnabledEpsilon(); }

References dag2BN_.

◆ EMisEnabledMaxIter()

bool gum::learning::IBNLearner::EMisEnabledMaxIter ( ) const
inline
Returns
true if stopping criterion on max iterations is enabled, false otherwise

Definition at line 1405 of file IBNLearner.h.

1405{ return dag2BN_.isEnabledMaxIter(); }

References dag2BN_.

◆ EMisEnabledMaxTime()

bool gum::learning::IBNLearner::EMisEnabledMaxTime ( ) const
inline
Returns
true if stopping criterion on timeout is enabled, false otherwise

Definition at line 1430 of file IBNLearner.h.

1430{ return dag2BN_.isEnabledMaxTime(); }

References dag2BN_.

◆ EMisEnabledMinEpsilonRate()

bool gum::learning::IBNLearner::EMisEnabledMinEpsilonRate ( ) const
inline
Returns
true if EM's stopping criterion is the log-likelihood evolution rate

Definition at line 1381 of file IBNLearner.h.

1381{ return dag2BN_.isEnabledMinEpsilonRate(); }

References dag2BN_.

◆ EMMaxIter()

Size gum::learning::IBNLearner::EMMaxIter ( ) const
inline

return the max number of iterations criterion

Warning
Note that this value is not taken into account unless the max iter criterion is enabled

Definition at line 1395 of file IBNLearner.h.

1395{ return dag2BN_.maxIter(); }

References dag2BN_.

◆ EMMaxTime()

double gum::learning::IBNLearner::EMMaxTime ( ) const
inline

@brief returns EM's timeout (in milliseconds)

Warning
Note that this value is not taken into account unless the max time criterion is enabled

Definition at line 1419 of file IBNLearner.h.

1419{ return dag2BN_.maxTime(); }

References dag2BN_.

◆ EMMinEpsilonRate()

double gum::learning::IBNLearner::EMMinEpsilonRate ( ) const
inline

Get the value of the minimal log-likelihood evolution rate of EM.

Warning
Note that this value is not taken into account unless the min rate criterion is enabled

Definition at line 1369 of file IBNLearner.h.

1369{ return dag2BN_.minEpsilonRate(); }

References dag2BN_.

◆ EMnbrIterations()

Size gum::learning::IBNLearner::EMnbrIterations ( ) const
inline

returns the number of iterations performed by the last EM execution

Definition at line 1452 of file IBNLearner.h.

1452{ return dag2BN_.nbrIterations(); }

References dag2BN_.

◆ EMPeriodSize()

Size gum::learning::IBNLearner::EMPeriodSize ( ) const
inline

sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods

Parameters
epsthe log-likelihood difference below which EM stops its iterations
Warning
setting this stopping criterion disables the min rate criterion (if it was enabled)
Exceptions
OutOfBoundsif eps <= 0

Definition at line 1438 of file IBNLearner.h.

1438{ return dag2BN_.periodSize(); }

References dag2BN_.

◆ EMsetEpsilon()

void gum::learning::IBNLearner::EMsetEpsilon ( double eps)
inline

sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods

Parameters
epsthe log-likelihood difference below which EM stops its iterations
Warning
setting this stopping criterion disables the min rate criterion (if it was enabled)
Exceptions
OutOfBoundsif eps <= 0

Definition at line 1334 of file IBNLearner.h.

1334{ dag2BN_.setEpsilon(eps); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetEpsilon().

Here is the caller graph for this function:

◆ EMsetMaxIter()

void gum::learning::IBNLearner::EMsetMaxIter ( Size max)
inline

add a max iteration stopping criterion

Parameters
maxthe max number of iterations that EM is allowed to perform
Exceptions
OutOfBoundsif max<=1

Definition at line 1388 of file IBNLearner.h.

1388{ dag2BN_.setMaxIter(max); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetMaxIter().

Here is the caller graph for this function:

◆ EMsetMaxTime()

void gum::learning::IBNLearner::EMsetMaxTime ( double timeout)
inline

add a stopping criterion on timeout

Parameters
timeoutthe timeout in milliseconds
Exceptions
OutOfBoundsif timeout<=0.0

Definition at line 1412 of file IBNLearner.h.

1412{ dag2BN_.setMaxTime(timeout); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetMaxTime().

Here is the caller graph for this function:

◆ EMsetMinEpsilonRate()

void gum::learning::IBNLearner::EMsetMinEpsilonRate ( double rate)
inline

sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate

Parameters
ratethe log-likelihood evolution rate below which EM stops its iterations
Warning
setting this stopping criterion disables the min diff criterion (if it was enabled)
Exceptions
OutOfBoundsif rate<=0

Definition at line 1362 of file IBNLearner.h.

1362{ dag2BN_.setMinEpsilonRate(rate); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetMinEpsilonRate().

Here is the caller graph for this function:

◆ EMsetPeriodSize()

void gum::learning::IBNLearner::EMsetPeriodSize ( Size p)
inline

how many samples between 2 stoppings isEnabled

Exceptions
OutOfBoundsif p<1

Definition at line 1436 of file IBNLearner.h.

1436{ dag2BN_.setPeriodSize(p); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetPeriodSize().

Here is the caller graph for this function:

◆ EMsetVerbosity()

void gum::learning::IBNLearner::EMsetVerbosity ( bool v)
inline

sets or unsets EM's verbosity

Definition at line 1441 of file IBNLearner.h.

1441{ dag2BN_.setVerbosity(v); }

References dag2BN_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::EMsetVerbosity().

Here is the caller graph for this function:

◆ EMState()

INLINE IApproximationSchemeConfiguration::ApproximationSchemeSTATE gum::learning::IBNLearner::EMState ( ) const

returns the state of the last EM algorithm executed

Definition at line 304 of file IBNLearner_inl.h.

References dag2BN_, gum::IApproximationSchemeConfiguration::Undefined, and useEM_.

◆ EMStateApproximationScheme()

ApproximationSchemeSTATE gum::learning::IBNLearner::EMStateApproximationScheme ( ) const
inline

get the current state of EM

Definition at line 1447 of file IBNLearner.h.

1447 {
1448 return dag2BN_.stateApproximationScheme();
1449 }

References dag2BN_.

◆ EMStateMessage()

INLINE std::string gum::learning::IBNLearner::EMStateMessage ( ) const

returns the state of the EM algorithm

Definition at line 310 of file IBNLearner_inl.h.

310 {
311 if (useEM_) return dag2BN_.messageApproximationScheme();
312 else return "EM is currently forbidden. Please enable it with useEM()";
313 }

References dag2BN_, and useEM_.

◆ EMVerbosity()

bool gum::learning::IBNLearner::EMVerbosity ( ) const
inline

returns the EM's verbosity status

Definition at line 1444 of file IBNLearner.h.

1444{ return dag2BN_.verbosity(); }

References dag2BN_.

◆ enableEpsilon()

void gum::learning::IBNLearner::enableEpsilon ( )
inlineoverridevirtual

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1129 of file IBNLearner.h.

1129 {
1130 algoK2_.approximationScheme().enableEpsilon();
1131 greedyHillClimbing_.enableEpsilon();
1132 localSearchWithTabuList_.enableEpsilon();
1133 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ enableMaxIter()

void gum::learning::IBNLearner::enableMaxIter ( )
inlineoverridevirtual

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1209 of file IBNLearner.h.

1209 {
1210 algoK2_.approximationScheme().enableMaxIter();
1211 greedyHillClimbing_.enableMaxIter();
1212 localSearchWithTabuList_.enableMaxIter();
1213 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ enableMaxTime()

void gum::learning::IBNLearner::enableMaxTime ( )
inlineoverridevirtual

stopping criterion on timeout If the criterion was disabled it will be enabled

Exceptions
OutOfBoundsif timeout<=0.0 timeout is time in second (double).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1255 of file IBNLearner.h.

1255 {
1256 algoK2_.approximationScheme().enableMaxTime();
1257 greedyHillClimbing_.enableMaxTime();
1258 localSearchWithTabuList_.enableMaxTime();
1259 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ enableMinEpsilonRate()

void gum::learning::IBNLearner::enableMinEpsilonRate ( )
inlineoverridevirtual

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1169 of file IBNLearner.h.

1169 {
1170 algoK2_.approximationScheme().enableMinEpsilonRate();
1171 greedyHillClimbing_.enableMinEpsilonRate();
1172 localSearchWithTabuList_.enableMinEpsilonRate();
1173 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ epsilon()

double gum::learning::IBNLearner::epsilon ( ) const
inlineoverridevirtual

Get the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1116 of file IBNLearner.h.

1116 {
1117 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->epsilon();
1118 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1119 }

References currentAlgorithm_, and GUM_ERROR.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useEM(), useEM(), gum::learning::BNLearner< GUM_SCALAR >::useEMWithDiffCriterion(), useEMWithDiffCriterion(), gum::learning::BNLearner< GUM_SCALAR >::useEMWithRateCriterion(), and useEMWithRateCriterion().

Here is the caller graph for this function:

◆ eraseForbiddenArc() [1/3]

INLINE void gum::learning::IBNLearner::eraseForbiddenArc ( const Arc & arc)

Definition at line 368 of file IBNLearner_inl.h.

368 {
369 constraintForbiddenArcs_.eraseArc(arc);
370 }

References constraintForbiddenArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc(), gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc(), gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc(), eraseForbiddenArc(), and eraseForbiddenArc().

Here is the caller graph for this function:

◆ eraseForbiddenArc() [2/3]

INLINE void gum::learning::IBNLearner::eraseForbiddenArc ( const std::string & tail,
const std::string & head )

Definition at line 388 of file IBNLearner_inl.h.

388 {
389 eraseForbiddenArc(Arc(idFromName(tail), idFromName(head)));
390 }
void eraseForbiddenArc(const Arc &arc)

References eraseForbiddenArc(), and idFromName().

Here is the call graph for this function:

◆ eraseForbiddenArc() [3/3]

INLINE void gum::learning::IBNLearner::eraseForbiddenArc ( NodeId tail,
NodeId head )

Definition at line 378 of file IBNLearner_inl.h.

378 {
379 eraseForbiddenArc(Arc(tail, head));
380 }

References eraseForbiddenArc().

Here is the call graph for this function:

◆ eraseMandatoryArc() [1/3]

INLINE void gum::learning::IBNLearner::eraseMandatoryArc ( const Arc & arc)

Definition at line 401 of file IBNLearner_inl.h.

401 {
402 constraintMandatoryArcs_.eraseArc(arc);
403 }

References constraintMandatoryArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc(), gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc(), gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc(), eraseMandatoryArc(), and eraseMandatoryArc().

Here is the caller graph for this function:

◆ eraseMandatoryArc() [2/3]

INLINE void gum::learning::IBNLearner::eraseMandatoryArc ( const std::string & tail,
const std::string & head )

Definition at line 441 of file IBNLearner_inl.h.

441 {
442 eraseMandatoryArc(Arc(idFromName(tail), idFromName(head)));
443 }
void eraseMandatoryArc(const Arc &arc)

References eraseMandatoryArc(), and idFromName().

Here is the call graph for this function:

◆ eraseMandatoryArc() [3/3]

INLINE void gum::learning::IBNLearner::eraseMandatoryArc ( NodeId tail,
NodeId head )

Definition at line 451 of file IBNLearner_inl.h.

451 {
452 eraseMandatoryArc(Arc(tail, head));
453 }

References eraseMandatoryArc().

Here is the call graph for this function:

◆ eraseNoChildrenNode() [1/2]

INLINE void gum::learning::IBNLearner::eraseNoChildrenNode ( const std::string & node)

Definition at line 431 of file IBNLearner_inl.h.

431 {
433 }
void eraseNoChildrenNode(NodeId node)

References eraseNoChildrenNode(), and idFromName().

Here is the call graph for this function:

◆ eraseNoChildrenNode() [2/2]

INLINE void gum::learning::IBNLearner::eraseNoChildrenNode ( NodeId node)

Definition at line 427 of file IBNLearner_inl.h.

427 {
428 constraintNoChildrenNodes_.eraseNode(node);
429 }

References constraintNoChildrenNodes_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::eraseNoChildrenNode(), gum::learning::BNLearner< GUM_SCALAR >::eraseNoChildrenNode(), and eraseNoChildrenNode().

Here is the caller graph for this function:

◆ eraseNoParentNode() [1/2]

INLINE void gum::learning::IBNLearner::eraseNoParentNode ( const std::string & node)

Definition at line 415 of file IBNLearner_inl.h.

415 {
417 }
void eraseNoParentNode(NodeId node)

References eraseNoParentNode(), and idFromName().

Here is the call graph for this function:

◆ eraseNoParentNode() [2/2]

INLINE void gum::learning::IBNLearner::eraseNoParentNode ( NodeId node)

Definition at line 411 of file IBNLearner_inl.h.

411 {
412 constraintNoParentNodes_.eraseNode(node);
413 }

References constraintNoParentNodes_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::eraseNoParentNode(), gum::learning::BNLearner< GUM_SCALAR >::eraseNoParentNode(), and eraseNoParentNode().

Here is the caller graph for this function:

◆ erasePossibleEdge() [1/3]

INLINE void gum::learning::IBNLearner::erasePossibleEdge ( const Edge & edge)

Definition at line 335 of file IBNLearner_inl.h.

335 {
336 constraintPossibleEdges_.eraseEdge(edge);
337 }

References constraintPossibleEdges_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge(), gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge(), gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge(), erasePossibleEdge(), and erasePossibleEdge().

Here is the caller graph for this function:

◆ erasePossibleEdge() [2/3]

INLINE void gum::learning::IBNLearner::erasePossibleEdge ( const std::string & tail,
const std::string & head )

Definition at line 355 of file IBNLearner_inl.h.

355 {
356 erasePossibleEdge(Edge(idFromName(tail), idFromName(head)));
357 }
void erasePossibleEdge(const Edge &edge)

References erasePossibleEdge(), and idFromName().

Here is the call graph for this function:

◆ erasePossibleEdge() [3/3]

INLINE void gum::learning::IBNLearner::erasePossibleEdge ( NodeId tail,
NodeId head )

Definition at line 345 of file IBNLearner_inl.h.

345 {
346 erasePossibleEdge(Edge(tail, head));
347 }

References erasePossibleEdge().

Here is the call graph for this function:

◆ forbidEM()

INLINE void gum::learning::IBNLearner::forbidEM ( )

prevent using the EM algorithm for parameter learning

forbid to use EM

Definition at line 292 of file IBNLearner_inl.h.

292{ useEM_ = false; }

References useEM_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::forbidEM().

Here is the caller graph for this function:

◆ G2() [1/2]

std::pair< double, double > gum::learning::IBNLearner::G2 ( const std::string & name1,
const std::string & name2,
const std::vector< std::string > & knowing = {} )

Return the <statistic,pvalue> pair for for G2 test in the database.

Parameters
id1first variable
id2second variable
knowinglist of observed variables
Returns
a std::pair<double,double>

Definition at line 988 of file IBNLearner.cpp.

990 {
991 std::vector< NodeId > knowingIds;
992 std::transform(knowing.begin(),
993 knowing.end(),
994 std::back_inserter(knowingIds),
995 [this](const std::string& c) { return this->idFromName(c); });
996 return G2(idFromName(name1), idFromName(name2), knowingIds);
997 }
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.

References G2(), and idFromName().

Here is the call graph for this function:

◆ G2() [2/2]

std::pair< double, double > gum::learning::IBNLearner::G2 ( NodeId id1,
NodeId id2,
const std::vector< NodeId > & knowing = {} )

Return the <statistic,pvalue> pair for for G2 test in the database.

Parameters
id1first variable
id2second variable
knowinglist of observed variables
Returns
a std::pair<double,double>

Definition at line 982 of file IBNLearner.cpp.

982 {
983 createPrior_();
984 gum::learning::IndepTestG2 g2score(scoreDatabase_.parser(), *prior_, databaseRanges());
985 return g2score.statistics(id1, id2, knowing);
986 }

References createPrior_(), databaseRanges(), prior_, scoreDatabase_, and gum::learning::IndepTestG2::statistics().

Referenced by G2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNumberOfThreads()

virtual Size gum::ThreadNumberManager::getNumberOfThreads ( ) const
virtualinherited

◆ getPriorType_()

INLINE PriorType gum::learning::IBNLearner::getPriorType_ ( ) const
protected

returns the type (as a string) of a given prior

Definition at line 518 of file IBNLearner_inl.h.

References BDEU, gum::learning::BDeuPriorType, DIRICHLET_FROM_BAYESNET, DIRICHLET_FROM_DATABASE, gum::learning::DirichletPriorType, GUM_ERROR, NO_prior, gum::learning::NoPriorType, priorType_, SMOOTHING, and gum::learning::SmoothingPriorType.

Referenced by checkScorePriorCompatibility().

Here is the caller graph for this function:

◆ hasMissingValues()

INLINE bool gum::learning::IBNLearner::hasMissingValues ( ) const

returns true if the learner's database has missing values

Definition at line 315 of file IBNLearner_inl.h.

315 {
316 return scoreDatabase_.databaseTable().hasMissingValues();
317 }

References scoreDatabase_.

Referenced by rawPseudoCount().

Here is the caller graph for this function:

◆ history()

const std::vector< double > & gum::learning::IBNLearner::history ( ) const
inlineoverridevirtual
Exceptions
OperationNotAllowedif scheme not performed or verbosity=false

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1316 of file IBNLearner.h.

1316 {
1317 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->history();
1318 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1319 }

References currentAlgorithm_, and GUM_ERROR.

◆ idFromName()

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

returns the node id corresponding to a variable name

Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.

Definition at line 135 of file IBNLearner_inl.h.

135 {
136 return scoreDatabase_.idFromName(var_name);
137 }

References scoreDatabase_.

Referenced by addForbiddenArc(), addMandatoryArc(), addNoChildrenNode(), addNoParentNode(), addPossibleEdge(), chi2(), correctedMutualInformation(), domainSize(), eraseForbiddenArc(), eraseMandatoryArc(), eraseNoChildrenNode(), eraseNoParentNode(), erasePossibleEdge(), G2(), logLikelihood(), mutualInformation(), rawPseudoCount(), score(), and setSliceOrder().

Here is the caller graph for this function:

◆ initialDAG()

INLINE DAG gum::learning::IBNLearner::initialDAG ( )

returns the initial DAG structure

Definition at line 165 of file IBNLearner_inl.h.

165{ return initialDag_; }

References initialDag_.

◆ isConstraintBased()

bool gum::learning::IBNLearner::isConstraintBased ( ) const
inline

indicate if the selected algorithm is constraint-based

Definition at line 777 of file IBNLearner.h.

777 {
778 switch (selectedAlgo_) {
779 case AlgoType::K2 :
781 case AlgoType::LOCAL_SEARCH_WITH_TABU_LIST : return false;
782 case AlgoType::MIIC : return true;
783 default : throw OperationNotAllowed("Unknown algorithm");
784 }
785 }

References GREEDY_HILL_CLIMBING, K2, LOCAL_SEARCH_WITH_TABU_LIST, MIIC, and selectedAlgo_.

Referenced by checkScorePriorCompatibility(), gum::learning::BNLearner< GUM_SCALAR >::isConstraintBased(), and isScoreBased().

Here is the caller graph for this function:

◆ isCSVFileName_()

void gum::learning::IBNLearner::isCSVFileName_ ( const std::string & filename)
staticprotected

checks whether the extension of a CSV filename is correct

Definition at line 426 of file IBNLearner.cpp.

426 {
427 // get the extension of the file
428
429 if (auto filename_size = Size(filename.size()); filename_size < 4) {
430 GUM_ERROR(FormatNotFound,
431 "IBNLearner could not determine the "
432 "file type of the database")
433 }
434
435 auto extension = filename.substr(filename.size() - 4);
436 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
437
438 if (extension != ".csv") {
439 GUM_ERROR(OperationNotAllowed, "IBNLearner does not support yet this type of database file")
440 }
441 }

References GUM_ERROR.

Referenced by gum::learning::IBNLearner::Database::Database(), gum::learning::IBNLearner::Database::Database(), and readFile_().

Here is the caller graph for this function:

◆ isEnabledEpsilon()

bool gum::learning::IBNLearner::isEnabledEpsilon ( ) const
inlineoverridevirtual
Returns
true if stopping criterion on epsilon is enabled, false otherwise

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1137 of file IBNLearner.h.

1137 {
1138 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledEpsilon();
1139 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1140 }

References currentAlgorithm_, and GUM_ERROR.

◆ isEnabledMaxIter()

bool gum::learning::IBNLearner::isEnabledMaxIter ( ) const
inlineoverridevirtual
Returns
true if stopping criterion on max iterations is enabled, false otherwise

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1217 of file IBNLearner.h.

1217 {
1218 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxIter();
1219 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1220 }

References currentAlgorithm_, and GUM_ERROR.

◆ isEnabledMaxTime()

bool gum::learning::IBNLearner::isEnabledMaxTime ( ) const
inlineoverridevirtual
Returns
true if stopping criterion on timeout is enabled, false otherwise

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1263 of file IBNLearner.h.

1263 {
1264 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxTime();
1265 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1266 }

References currentAlgorithm_, and GUM_ERROR.

◆ isEnabledMinEpsilonRate()

bool gum::learning::IBNLearner::isEnabledMinEpsilonRate ( ) const
inlineoverridevirtual
Returns
true if stopping criterion on epsilon rate is enabled, false otherwise

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1177 of file IBNLearner.h.

1177 {
1178 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMinEpsilonRate();
1179 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1180 }

References currentAlgorithm_, and GUM_ERROR.

◆ isGumNumberOfThreadsOverriden()

bool gum::ThreadNumberManager::isGumNumberOfThreadsOverriden ( ) const
virtualinherited

indicates whether the class containing this ThreadNumberManager set its own number of threads

Implements gum::IThreadNumberManager.

Referenced by gum::learning::IBNLearner::createParamEstimator_(), and gum::learning::IBNLearner::createScore_().

Here is the caller graph for this function:

◆ isScoreBased()

bool gum::learning::IBNLearner::isScoreBased ( ) const
inline

indicate if the selected algorithm is score-based

Definition at line 788 of file IBNLearner.h.

788{ return !isConstraintBased(); }

References isConstraintBased().

Referenced by gum::learning::BNLearner< GUM_SCALAR >::isScoreBased().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isUsingEM()

INLINE bool gum::learning::IBNLearner::isUsingEM ( ) const

indicates whether we use EM for parameter learning

Definition at line 295 of file IBNLearner_inl.h.

295{ return useEM_; }

References useEM_.

◆ latentVariables()

INLINE std::vector< Arc > gum::learning::IBNLearner::latentVariables ( ) const

get the list of arcs hiding latent variables

Exceptions
OperationNotAllowedwhen MIIC is not the selected algorithm

Definition at line 227 of file IBNLearner_inl.h.

227 {
228 return algoMiic_.latentVariables();
229 }

References algoMiic_.

◆ learnDAG()

DAG gum::learning::IBNLearner::learnDAG ( )

learn a structure from a file (must have read the db before)

Definition at line 702 of file IBNLearner.cpp.

702 {
703 // create the score and the prior
704 createPrior_();
705 createScore_();
706
707 return learnDag_();
708 }
DAG learnDag_()
returns the DAG learnt
void createScore_()
create the score used for learning

References createPrior_(), createScore_(), and learnDag_().

Here is the call graph for this function:

◆ learnDag_()

DAG gum::learning::IBNLearner::learnDag_ ( )
protected

returns the DAG learnt

Definition at line 729 of file IBNLearner.cpp.

729 {
730 // check that the database does not contain any missing value
731 if (scoreDatabase_.databaseTable().hasMissingValues()
732 || ((priorDatabase_ != nullptr)
734 && priorDatabase_->databaseTable().hasMissingValues())) {
735 GUM_ERROR(MissingValueInDatabase,
736 "For the moment, the BNLearner is unable to cope "
737 "with missing values in databases")
738 }
739 // add the mandatory arcs to the initial dag and remove the forbidden ones
740 // from the initial graph
741 DAG init_graph = initialDag_;
742
743 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
744 if (!init_graph.exists(arc.tail())) init_graph.addNodeWithId(arc.tail());
745
746 if (!init_graph.exists(arc.head())) init_graph.addNodeWithId(arc.head());
747
748 init_graph.addArc(arc.tail(), arc.head());
749 }
750
751 for (const auto& arc: constraintForbiddenArcs_.arcs())
752 init_graph.eraseArc(arc);
753
754
755 switch (selectedAlgo_) {
756 // ========================================================================
757 case AlgoType::MIIC : {
758 BNLearnerListener listener(this, algoMiic_);
759 // create the mixedGraph and the corrected mutual information
760 MixedGraph mgraph = this->prepareMiic_();
761
762 return algoMiic_.learnStructure(*mutualInfo_, mgraph);
763 }
764
765 // ========================================================================
767 BNLearnerListener listener(this, greedyHillClimbing_);
768 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
769 StructuralConstraintForbiddenArcs,
770 StructuralConstraintPossibleEdges,
771 StructuralConstraintSliceOrder,
772 StructuralConstraintNoParentNodes,
773 StructuralConstraintNoChildrenNodes >
774 gen_constraint;
775 static_cast< StructuralConstraintMandatoryArcs& >(gen_constraint)
777 static_cast< StructuralConstraintForbiddenArcs& >(gen_constraint)
779 static_cast< StructuralConstraintPossibleEdges& >(gen_constraint)
781 static_cast< StructuralConstraintSliceOrder& >(gen_constraint) = constraintSliceOrder_;
782 static_cast< StructuralConstraintNoParentNodes& >(gen_constraint)
784 static_cast< StructuralConstraintNoChildrenNodes& >(gen_constraint)
786
787 GraphChangesGenerator4DiGraph op_set(gen_constraint);
788
789 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
790 sel_constraint;
791 static_cast< StructuralConstraintIndegree& >(sel_constraint) = constraintIndegree_;
792
793 GraphChangesSelector4DiGraph selector(*score_, sel_constraint, op_set);
794
795 return greedyHillClimbing_.learnStructure(selector, init_graph);
796 }
797
798 // ========================================================================
800 BNLearnerListener listener(this, localSearchWithTabuList_);
801 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
802 StructuralConstraintForbiddenArcs,
803 StructuralConstraintPossibleEdges,
804 StructuralConstraintSliceOrder,
805 StructuralConstraintNoParentNodes,
806 StructuralConstraintNoChildrenNodes >
807 gen_constraint;
808 static_cast< StructuralConstraintMandatoryArcs& >(gen_constraint)
810 static_cast< StructuralConstraintForbiddenArcs& >(gen_constraint)
812 static_cast< StructuralConstraintPossibleEdges& >(gen_constraint)
814 static_cast< StructuralConstraintSliceOrder& >(gen_constraint) = constraintSliceOrder_;
815 static_cast< StructuralConstraintNoParentNodes& >(gen_constraint)
817 static_cast< StructuralConstraintNoChildrenNodes& >(gen_constraint)
819
820 GraphChangesGenerator4DiGraph op_set(gen_constraint);
821
822 StructuralConstraintSetStatic< StructuralConstraintTabuList,
823 StructuralConstraintIndegree,
824 StructuralConstraintDAG >
825 sel_constraint;
826 static_cast< StructuralConstraintTabuList& >(sel_constraint) = constraintTabuList_;
827 static_cast< StructuralConstraintIndegree& >(sel_constraint) = constraintIndegree_;
828
829 GraphChangesSelector4DiGraph selector(*score_, sel_constraint, op_set);
830
831 return localSearchWithTabuList_.learnStructure(selector, init_graph);
832 }
833
834 // ========================================================================
835 case AlgoType::K2 : {
836 BNLearnerListener listener(this, algoK2_.approximationScheme());
837 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
838 StructuralConstraintForbiddenArcs,
839 StructuralConstraintPossibleEdges,
840 StructuralConstraintNoParentNodes,
841 StructuralConstraintNoChildrenNodes >
842 gen_constraint;
843 static_cast< StructuralConstraintMandatoryArcs& >(gen_constraint)
845 static_cast< StructuralConstraintForbiddenArcs& >(gen_constraint)
847 static_cast< StructuralConstraintPossibleEdges& >(gen_constraint)
849 ;
850 static_cast< StructuralConstraintNoParentNodes& >(gen_constraint)
852 ;
853 static_cast< StructuralConstraintNoChildrenNodes& >(gen_constraint)
855
856 GraphChangesGenerator4K2 op_set(gen_constraint);
857
858 // if some mandatory arcs are incompatible with the order, use a DAG
859 // constraint instead of a DiGraph constraint to avoid cycles
860 const ArcSet& mandatory_arcs
861 = static_cast< StructuralConstraintMandatoryArcs& >(gen_constraint).arcs();
862 const Sequence< NodeId >& order = algoK2_.order();
863 bool order_compatible = true;
864
865 for (const auto& arc: mandatory_arcs) {
866 if (order.pos(arc.tail()) >= order.pos(arc.head())) {
867 order_compatible = false;
868 break;
869 }
870 }
871
872 if (order_compatible) {
873 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDiGraph >
874 sel_constraint;
875 static_cast< StructuralConstraintIndegree& >(sel_constraint) = constraintIndegree_;
876
877 GraphChangesSelector4DiGraph selector(*score_, sel_constraint, op_set);
878
879 return algoK2_.learnStructure(selector, init_graph);
880 } else {
881 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
882 sel_constraint;
883 static_cast< StructuralConstraintIndegree& >(sel_constraint) = constraintIndegree_;
884
885 GraphChangesSelector4DiGraph selector(*score_, sel_constraint, op_set);
886
887 return algoK2_.learnStructure(selector, init_graph);
888 }
889 }
890
891 // ========================================================================
892 default :
893 GUM_ERROR(OperationNotAllowed,
894 "the learnDAG method has not been implemented for this "
895 "learning algorithm")
896 }
897 }
MixedGraph prepareMiic_()
prepares the initial graph for miic
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...

References gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), algoK2_, algoMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTabuList_, DIRICHLET_FROM_DATABASE, gum::ArcGraphPart::eraseArc(), gum::NodeGraphPart::exists(), GREEDY_HILL_CLIMBING, greedyHillClimbing_, GUM_ERROR, initialDag_, K2, LOCAL_SEARCH_WITH_TABU_LIST, localSearchWithTabuList_, MIIC, mutualInfo_, gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::pos(), prepareMiic_(), priorDatabase_, priorType_, score_, scoreDatabase_, and selectedAlgo_.

Referenced by learnDAG().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ learnPDAG()

PDAG gum::learning::IBNLearner::learnPDAG ( )

learn a partial structure from a file (must have read the db before and must have selected miic)

Definition at line 683 of file IBNLearner.cpp.

683 {
685 GUM_ERROR(OperationNotAllowed,
686 "Score-based algorithms do not build PDAG. Please use a constraint-based "
687 "algorithm instead")
688 }
689 // check that the database does not contain any missing value
690 if (scoreDatabase_.databaseTable().hasMissingValues()) {
691 GUM_ERROR(MissingValueInDatabase,
692 "For the moment, the BNLearner is unable to learn "
693 << "structures with missing values in databases")
694 }
695
696 BNLearnerListener listener(this, algoMiic_);
697 // create the mixedGraph_constraint_MandatoryArcs.arcs
698 MixedGraph mgraph = this->prepareMiic_();
699 return algoMiic_.learnPDAG(*mutualInfo_, mgraph);
700 }

References algoMiic_, GUM_ERROR, MIIC, mutualInfo_, prepareMiic_(), scoreDatabase_, and selectedAlgo_.

Here is the call graph for this function:

◆ logLikelihood() [1/2]

double gum::learning::IBNLearner::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.

Parameters
varsa vector of NodeIds
knowingan optional vector of conditioning NodeIds
Returns
a double

Definition at line 999 of file IBNLearner.cpp.

1000 {
1001 createPrior_();
1002 gum::learning::ScoreLog2Likelihood ll2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1003
1004 std::vector< NodeId > total(vars);
1005 total.insert(total.end(), knowing.begin(), knowing.end());
1006 double LLtotal = ll2score.score(IdCondSet(total, false, true));
1007 if (knowing.size() == (Size)0) {
1008 return LLtotal;
1009 } else {
1010 double LLknw = ll2score.score(IdCondSet(knowing, false, true));
1011 return LLtotal - LLknw;
1012 }
1013 }

References createPrior_(), databaseRanges(), prior_, gum::learning::ScoreLog2Likelihood::score(), and scoreDatabase_.

Referenced by logLikelihood().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ logLikelihood() [2/2]

double gum::learning::IBNLearner::logLikelihood ( const std::vector< std::string > & vars,
const std::vector< std::string > & knowing = {} )

Return the loglikelihood of vars in the base, conditioned by knowing for the BNLearner.

Parameters
varsa vector of name of rows
knowingan optional vector of conditioning rows
Returns
a double

Definition at line 1015 of file IBNLearner.cpp.

1016 {
1017 std::vector< NodeId > ids;
1018 std::vector< NodeId > knowingIds;
1019
1020 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1021
1022 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1023 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1024
1025 return logLikelihood(ids, knowingIds);
1026 }
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.

References idFromName(), and logLikelihood().

Here is the call graph for this function:

◆ maxIter()

Size gum::learning::IBNLearner::maxIter ( ) const
inlineoverridevirtual
Returns
the criterion on number of iterations

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1196 of file IBNLearner.h.

1196 {
1197 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxIter();
1198 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1199 }

References currentAlgorithm_, and GUM_ERROR.

◆ maxTime()

double gum::learning::IBNLearner::maxTime ( ) const
inlineoverridevirtual

returns the timeout (in seconds)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1237 of file IBNLearner.h.

1237 {
1238 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxTime();
1239 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1240 }

References currentAlgorithm_, and GUM_ERROR.

◆ messageApproximationScheme()

INLINE std::string gum::IApproximationSchemeConfiguration::messageApproximationScheme ( ) const
inherited

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 59 of file IApproximationSchemeConfiguration_inl.h.

59 {
60 std::stringstream s;
61
62 switch (stateApproximationScheme()) {
63 case ApproximationSchemeSTATE::Continue : s << "in progress"; break;
64
65 case ApproximationSchemeSTATE::Epsilon : s << "stopped with epsilon=" << epsilon(); break;
66
67 case ApproximationSchemeSTATE::Rate : s << "stopped with rate=" << minEpsilonRate(); break;
68
69 case ApproximationSchemeSTATE::Limit : s << "stopped with max iteration=" << maxIter(); break;
70
71 case ApproximationSchemeSTATE::TimeLimit : s << "stopped with timeout=" << maxTime(); break;
72
73 case ApproximationSchemeSTATE::Stopped : s << "stopped on request"; break;
74
75 case ApproximationSchemeSTATE::Undefined : s << "undefined state"; break;
76 };
77
78 return s.str();
79 }
virtual double epsilon() const =0
Returns the value of epsilon.
virtual ApproximationSchemeSTATE stateApproximationScheme() const =0
Returns the approximation scheme state.
virtual double minEpsilonRate() const =0
Returns the value of the minimal epsilon rate.
virtual Size maxIter() const =0
Returns the criterion on number of iterations.
virtual double maxTime() const =0
Returns the timeout (in seconds).

References Continue, Epsilon, epsilon(), Limit, maxIter(), maxTime(), minEpsilonRate(), Rate, stateApproximationScheme(), Stopped, TimeLimit, and Undefined.

Referenced by gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::stateApproximationScheme().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ minEpsilonRate()

double gum::learning::IBNLearner::minEpsilonRate ( ) const
inlineoverridevirtual

Get the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1156 of file IBNLearner.h.

1156 {
1157 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->minEpsilonRate();
1158 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1159 }

References currentAlgorithm_, and GUM_ERROR.

◆ mutualInformation() [1/2]

double gum::learning::IBNLearner::mutualInformation ( const std::string & var1,
const std::string & var2,
const std::vector< std::string > & knowing = {} )

Return the mutual information of var1 and var2 in the base, conditioned by knowing for the BNLearner.

Warning
This function returns the bare mutual information (without prior or correction)
Parameters
var1name of a row
var2name of a row
knowingan optional vector of conditioning rows
Returns
a double

Definition at line 1076 of file IBNLearner.cpp.

1078 {
1079 std::vector< NodeId > knowingIds;
1080
1081 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1082
1083 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1084
1085 return mutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1086 }
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.

References idFromName(), and mutualInformation().

Here is the call graph for this function:

◆ mutualInformation() [2/2]

double gum::learning::IBNLearner::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.

Warning
This function returns the bare mutual information (without prior or correction)
Parameters
id1nodeId
id2nodeId
knowingan optional vector of conditioning NodeIds
Returns
a double

Definition at line 1065 of file IBNLearner.cpp.

1067 {
1068 const auto prior = NoPrior(scoreDatabase_.databaseTable(), scoreDatabase_.nodeId2Columns());
1069 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(), prior, databaseRanges());
1070 cmi.useNoCorr();
1071
1072 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1073 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1074 }

References databaseRanges(), gum::learning::CorrectedMutualInformation::score(), scoreDatabase_, and gum::learning::CorrectedMutualInformation::useNoCorr().

Referenced by mutualInformation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nameFromId()

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

returns the variable name corresponding to a given node id

Definition at line 140 of file IBNLearner_inl.h.

140 {
141 return scoreDatabase_.nameFromId(id);
142 }

References scoreDatabase_.

◆ names()

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

returns the names of the variables in the database

Definition at line 534 of file IBNLearner_inl.h.

534 {
535 return scoreDatabase_.names();
536 }

References scoreDatabase_.

◆ nbCols()

INLINE Size gum::learning::IBNLearner::nbCols ( ) const
Returns
the number of cols in the database

Definition at line 565 of file IBNLearner_inl.h.

565{ return scoreDatabase_.domainSizes().size(); }

References scoreDatabase_.

◆ nbrIterations()

Size gum::learning::IBNLearner::nbrIterations ( ) const
inlineoverridevirtual
Exceptions
OperationNotAllowedif scheme not performed

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1310 of file IBNLearner.h.

1310 {
1311 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->nbrIterations();
1312 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1313 }

References currentAlgorithm_, and GUM_ERROR.

◆ nbRows()

INLINE Size gum::learning::IBNLearner::nbRows ( ) const
Returns
the number of rows in the database

Definition at line 567 of file IBNLearner_inl.h.

567{ return scoreDatabase_.databaseTable().size(); }

References scoreDatabase_.

◆ operator=() [1/2]

IBNLearner & gum::learning::IBNLearner::operator= ( const IBNLearner & from)

copy operator

Definition at line 277 of file IBNLearner.cpp.

277 {
278 if (this != &from) {
279 if (score_) {
280 delete score_;
281 score_ = nullptr;
282 }
283
284 if (prior_) {
285 delete prior_;
286 prior_ = nullptr;
287 }
288
289 if (priorDatabase_) {
290 delete priorDatabase_;
291 priorDatabase_ = nullptr;
292 }
293
294 if (mutualInfo_) {
295 delete mutualInfo_;
296 mutualInfo_ = nullptr;
297 }
298
300 scoreType_ = from.scoreType_;
301 paramEstimatorType_ = from.paramEstimatorType_;
302 useEM_ = from.useEM_;
303 noiseEM_ = from.noiseEM_;
304 priorType_ = from.priorType_;
305 priorWeight_ = from.priorWeight_;
306 constraintSliceOrder_ = from.constraintSliceOrder_;
307 constraintIndegree_ = from.constraintIndegree_;
308 constraintTabuList_ = from.constraintTabuList_;
309 constraintForbiddenArcs_ = from.constraintForbiddenArcs_;
310 constraintNoParentNodes_ = from.constraintNoParentNodes_;
311 constraintNoChildrenNodes_ = from.constraintNoChildrenNodes_;
312 constraintMandatoryArcs_ = from.constraintMandatoryArcs_;
313 selectedAlgo_ = from.selectedAlgo_;
314 algoK2_ = from.algoK2_;
315 algoSimpleMiic_ = from.algoSimpleMiic_;
316 algoMiic_ = from.algoMiic_;
317 kmodeMiic_ = from.kmodeMiic_;
318 dag2BN_ = from.dag2BN_;
319 greedyHillClimbing_ = from.greedyHillClimbing_;
320 localSearchWithTabuList_ = from.localSearchWithTabuList_;
321 scoreDatabase_ = from.scoreDatabase_;
322 ranges_ = from.ranges_;
323 priorDbname_ = from.priorDbname_;
324 initialDag_ = from.initialDag_;
325 filename_ = from.filename_;
326 nbDecreasingChanges_ = from.nbDecreasingChanges_;
327 currentAlgorithm_ = nullptr;
328 }
329
330 return *this;
331 }
ThreadNumberManager & operator=(const ThreadNumberManager &from)
copy operator

References IBNLearner(), algoK2_, algoMiic_, algoSimpleMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, currentAlgorithm_, dag2BN_, filename_, greedyHillClimbing_, initialDag_, kmodeMiic_, localSearchWithTabuList_, mutualInfo_, nbDecreasingChanges_, noiseEM_, gum::ThreadNumberManager::operator=(), paramEstimatorType_, prior_, priorDatabase_, priorDbname_, priorType_, priorWeight_, ranges_, score_, scoreDatabase_, scoreType_, selectedAlgo_, and useEM_.

Here is the call graph for this function:

◆ operator=() [2/2]

IBNLearner & gum::learning::IBNLearner::operator= ( IBNLearner && from)

move operator

Definition at line 333 of file IBNLearner.cpp.

333 {
334 if (this != &from) {
335 if (score_) {
336 delete score_;
337 score_ = nullptr;
338 }
339
340 if (prior_) {
341 delete prior_;
342 prior_ = nullptr;
343 }
344
345 if (priorDatabase_) {
346 delete priorDatabase_;
347 priorDatabase_ = nullptr;
348 }
349
350 if (mutualInfo_) {
351 delete mutualInfo_;
352 mutualInfo_ = nullptr;
353 }
354
355 ThreadNumberManager::operator=(std::move(from));
356 scoreType_ = from.scoreType_;
357 paramEstimatorType_ = from.paramEstimatorType_;
358 useEM_ = from.useEM_;
359 noiseEM_ = from.noiseEM_;
360 priorType_ = from.priorType_;
361 priorWeight_ = from.priorWeight_;
362 constraintSliceOrder_ = std::move(from.constraintSliceOrder_);
363 constraintIndegree_ = std::move(from.constraintIndegree_);
364 constraintTabuList_ = std::move(from.constraintTabuList_);
365 constraintForbiddenArcs_ = std::move(from.constraintForbiddenArcs_);
366 constraintNoParentNodes_ = std::move(from.constraintNoParentNodes_);
367 constraintNoChildrenNodes_ = std::move(from.constraintNoChildrenNodes_);
368 constraintMandatoryArcs_ = std::move(from.constraintMandatoryArcs_);
369 selectedAlgo_ = from.selectedAlgo_;
370 algoK2_ = from.algoK2_;
371 algoSimpleMiic_ = std::move(from.algoSimpleMiic_);
372 algoMiic_ = std::move(from.algoMiic_);
373 kmodeMiic_ = from.kmodeMiic_;
374 dag2BN_ = std::move(from.dag2BN_);
375 greedyHillClimbing_ = std::move(from.greedyHillClimbing_);
376 localSearchWithTabuList_ = std::move(from.localSearchWithTabuList_);
377 scoreDatabase_ = std::move(from.scoreDatabase_);
378 ranges_ = std::move(from.ranges_);
379 priorDbname_ = std::move(from.priorDbname_);
380 filename_ = std::move(from.filename_);
381 initialDag_ = std::move(from.initialDag_);
382 nbDecreasingChanges_ = std::move(from.nbDecreasingChanges_);
383 currentAlgorithm_ = nullptr;
384 }
385
386 return *this;
387 }

References IBNLearner(), algoK2_, algoMiic_, algoSimpleMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, currentAlgorithm_, dag2BN_, filename_, greedyHillClimbing_, initialDag_, kmodeMiic_, localSearchWithTabuList_, mutualInfo_, nbDecreasingChanges_, noiseEM_, gum::ThreadNumberManager::operator=(), paramEstimatorType_, prior_, priorDatabase_, priorDbname_, priorType_, priorWeight_, ranges_, score_, scoreDatabase_, scoreType_, selectedAlgo_, and useEM_.

Here is the call graph for this function:

◆ periodSize()

Size gum::learning::IBNLearner::periodSize ( ) const
inlineoverridevirtual

how many samples between 2 stopping isEnableds

Exceptions
OutOfBoundsif p<1

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1279 of file IBNLearner.h.

1279 {
1280 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->periodSize();
1281 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1282 }

References currentAlgorithm_, and GUM_ERROR.

◆ prepareMiic_()

MixedGraph gum::learning::IBNLearner::prepareMiic_ ( )
protected

prepares the initial graph for miic

Definition at line 594 of file IBNLearner.cpp.

594 {
595 // Initialize the mixed graph to the fully connected graph
596 MixedGraph mgraph;
597 DiGraph forbiddenGraph;
598 DAG mandatoryGraph;
599
600 // GUM_CHECKPOINT
601 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
602 mgraph.addNodeWithId(i);
603 forbiddenGraph.addNodeWithId(i);
604 mandatoryGraph.addNodeWithId(i);
605 }
606
607 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
608
609 if (possible_edges.empty()) {
610 for (const NodeId i: mgraph.nodes()) {
611 for (NodeId j = 0; j < i; ++j) {
612 // contiguous nodeIds !
613 mgraph.addEdge(j, i);
614 }
615 }
616 } else {
617 for (const auto& edge: possible_edges) {
618 mgraph.addEdge(edge.first(), edge.second());
619 }
620 }
621 // GUM_CHECKPOINT
622
623 // translating the mandatory arcs for constraintMiic
624 HashTable< std::pair< NodeId, NodeId >, char > initial_marks;
625 const ArcSet& mandatory_arcs = constraintMandatoryArcs_.arcs();
626
627 // GUM_CHECKPOINT
628 for (const auto& arc: mandatory_arcs) {
629 mandatoryGraph.addArc(arc.tail(), arc.head());
630 forbiddenGraph.addArc(arc.head(), arc.head());
631 }
632
633 // GUM_CHECKPOINT
634 // translating the forbidden arcs for constraintMiic
635 const ArcSet& forbidden_arcs = constraintForbiddenArcs_.arcs();
636 for (const auto& arc: forbidden_arcs) {
637 forbiddenGraph.addArc(arc.tail(), arc.head());
638 }
639
640 // GUM_CHECKPOINT
641 const gum::NodeProperty< gum::Size > sliceOrder = constraintSliceOrder_.sliceOrder();
642 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
643 for (const auto& [n1, r1]: sliceOrder) {
644 for (const auto& [n2, r2]: copyOrder) {
645 if (r1 > r2) {
646 forbiddenGraph.addArc(n1, n2);
647 // initial_marks.insert({n1, n2}, '-');
648 } else if (r2 > r1) {
649 forbiddenGraph.addArc(n2, n1);
650 // initial_marks.insert({n2, n1}, '-');
651 }
652 }
653 copyOrder.erase(n1);
654 }
655
656 for (const auto node: constraintNoParentNodes_.nodes()) {
657 for (const auto node2: mgraph.nodes()) {
658 if (node != node2) { forbiddenGraph.addArc(node2, node); }
659 }
660 }
661
662 for (const auto node: constraintNoChildrenNodes_.nodes()) {
663 for (const auto node2: mgraph.nodes()) {
664 if (node != node2) { forbiddenGraph.addArc(node, node2); }
665 }
666 }
667
668 // GUM_CHECKPOINT
669 algoMiic_.setMaxIndegree(constraintIndegree_.maxIndegree());
670 algoMiic_.addConstraints(initial_marks);
671 algoMiic_.setMandatoryGraph(mandatoryGraph);
672 algoMiic_.setForbiddenGraph(forbiddenGraph);
673
674 // GUM_CHECKPOINT
675 // create the mutual entropy object
676 // if ( _mutual_info_ == nullptr) { this->useNMLCorrection(); }
678
679 // GUM_CHECKPOINT
680 return mgraph;
681 }
void createCorrectedMutualInformation_()
create the Corrected Mutual Information instance for Miic
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

References gum::DAG::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, createCorrectedMutualInformation_(), gum::Set< Key >::empty(), gum::NodeGraphPart::nodes(), and scoreDatabase_.

Referenced by learnDag_(), and learnPDAG().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepareSimpleMiic_()

MixedGraph gum::learning::IBNLearner::prepareSimpleMiic_ ( )
protected

prepares the initial graph for Simple Miic

◆ rawPseudoCount() [1/2]

std::vector< double > gum::learning::IBNLearner::rawPseudoCount ( const std::vector< NodeId > & vars)

Return the pseudo-counts of NodeIds vars in the base in a raw array.

Parameters
varsa vector of
Returns
a a std::vector<double> containing the contingency table

Definition at line 1106 of file IBNLearner.cpp.

1106 {
1107 if (this->hasMissingValues()) {
1108 GUM_ERROR(MissingValueInDatabase,
1109 "BNLearner cannot compute pseudo-counts with missing values in the database")
1110 }
1111 if (vars.empty()) {
1112 GUM_ERROR(OutOfBounds, "BNLearner::rawPseudoCount called with an empty vector of variables")
1113 }
1114 Tensor< double > res;
1115
1116 createPrior_();
1117 gum::learning::PseudoCount count(scoreDatabase_.parser(), *prior_, databaseRanges());
1118 return count.get(vars);
1119 }
bool hasMissingValues() const
returns true if the learner's database has missing values

References createPrior_(), databaseRanges(), gum::learning::PseudoCount::get(), GUM_ERROR, hasMissingValues(), prior_, and scoreDatabase_.

Referenced by rawPseudoCount().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rawPseudoCount() [2/2]

std::vector< double > gum::learning::IBNLearner::rawPseudoCount ( const std::vector< std::string > & vars)

Return the pseudoconts of vars in the base in a raw array.

Parameters
varsa vector of name
Returns
a std::vector<double> containing the contingency table

Definition at line 1121 of file IBNLearner.cpp.

1121 {
1122 std::vector< NodeId > ids;
1123
1124 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1125
1126 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1127 return rawPseudoCount(ids);
1128 }
std::vector< double > rawPseudoCount(const std::vector< NodeId > &vars)
Return the pseudo-counts of NodeIds vars in the base in a raw array.

References idFromName(), and rawPseudoCount().

Here is the call graph for this function:

◆ readFile_()

DatabaseTable gum::learning::IBNLearner::readFile_ ( const std::string & filename,
const std::vector< std::string > & missing_symbols )
staticprotected

reads a file and returns a databaseVectInRam

Definition at line 443 of file IBNLearner.cpp.

444 {
445 // get the extension of the file
446 isCSVFileName_(filename);
447
448 DBInitializerFromCSV initializer(filename);
449
450 const auto& var_names = initializer.variableNames();
451 const std::size_t nb_vars = var_names.size();
452
453 DBTranslatorSet translator_set;
454 DBTranslator4LabelizedVariable translator(missing_symbols);
455 for (std::size_t i = 0; i < nb_vars; ++i) {
456 translator_set.insertTranslator(translator, i);
457 }
458
459 DatabaseTable database(missing_symbols, translator_set);
460 database.setVariableNames(initializer.variableNames());
461 initializer.fillDatabase(database);
462
463 database.reorder();
464
465 return database;
466 }
static void isCSVFileName_(const std::string &filename)
checks whether the extension of a CSV filename is correct
const DatabaseTable & database() const
returns the database used by the BNLearner

References database(), gum::learning::IDBInitializer::fillDatabase(), gum::learning::DBTranslatorSet::insertTranslator(), isCSVFileName_(), and gum::learning::IDBInitializer::variableNames().

Referenced by gum::learning::IBNLearner::Database::Database().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ recordWeight()

INLINE double gum::learning::IBNLearner::recordWeight ( const std::size_t i) const

returns the weight of the ith record

Exceptions
OutOfBoundsif i is outside the set of indices of the records

Definition at line 155 of file IBNLearner_inl.h.

155 {
156 return scoreDatabase_.weight(i);
157 }

References scoreDatabase_.

◆ score() [1/2]

double gum::learning::IBNLearner::score ( const std::string & vars,
const std::vector< std::string > & knowing = {} )

Return the value of the score currently in use by the BNLearner of a variable given a set of other variables The score used is the one currently selected in the BNLearner.

Parameters
varthe name of the variable
knowingan optional vector of conditioning variables, specified by their names
Returns
a double corresponding to the value of the score

Definition at line 1095 of file IBNLearner.cpp.

1095 {
1096 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1097
1098 const NodeId id = this->idFromName(var);
1099 std::vector< NodeId > knowingIds;
1100 knowingIds.reserve(knowing.size());
1101 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1102
1103 return score(id, knowingIds);
1104 }
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...

References idFromName(), and score().

Here is the call graph for this function:

◆ score() [2/2]

double gum::learning::IBNLearner::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 variables.

Parameters
varthe NodeId of the LHS variable
knowingan optional vector of conditioning variables, specified by their NodeIds
Returns
a double corresponding to the value of the score

Definition at line 1088 of file IBNLearner.cpp.

1088 {
1089 createPrior_();
1090 createScore_();
1091
1092 return score_->score(var, knowing);
1093 }

References createPrior_(), createScore_(), and score_.

Referenced by score(), and useDatabaseRanges().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCurrentApproximationScheme()

INLINE void gum::learning::IBNLearner::setCurrentApproximationScheme ( const ApproximationScheme * approximationScheme)
inline

{@ /// distribute signals

Definition at line 1082 of file IBNLearner.h.

1082 {
1083 currentAlgorithm_ = approximationScheme;
1084 }

References currentAlgorithm_.

Referenced by gum::learning::BNLearnerListener::BNLearnerListener(), distributeProgress(), and distributeStop().

Here is the caller graph for this function:

◆ setDatabaseWeight()

INLINE void gum::learning::IBNLearner::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 new_weight

assign new weight to the rows of the learning database

Definition at line 145 of file IBNLearner_inl.h.

145 {
146 scoreDatabase_.setDatabaseWeight(new_weight);
147 }

References scoreDatabase_.

◆ setEpsilon()

void gum::learning::IBNLearner::setEpsilon ( double eps)
inlineoverridevirtual

Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)| If the criterion was disabled it will be enabled.

Exceptions
OutOfBoundsif eps<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1109 of file IBNLearner.h.

1109 {
1110 algoK2_.approximationScheme().setEpsilon(eps);
1111 greedyHillClimbing_.setEpsilon(eps);
1112 localSearchWithTabuList_.setEpsilon(eps);
1113 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setForbiddenArcs()

INLINE void gum::learning::IBNLearner::setForbiddenArcs ( const ArcSet & set)

assign a set of forbidden arcs

Definition at line 360 of file IBNLearner_inl.h.

360 {
361 constraintForbiddenArcs_.setArcs(set);
362 }

References constraintForbiddenArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setForbiddenArcs().

Here is the caller graph for this function:

◆ setInitialDAG()

INLINE void gum::learning::IBNLearner::setInitialDAG ( const DAG & dag)

sets an initial DAG structure

Definition at line 163 of file IBNLearner_inl.h.

163{ initialDag_ = dag; }

References initialDag_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setInitialDAG().

Here is the caller graph for this function:

◆ setMandatoryArcs()

INLINE void gum::learning::IBNLearner::setMandatoryArcs ( const ArcSet & set)

assign a set of mandatory arcs

Definition at line 393 of file IBNLearner_inl.h.

393 {
394 constraintMandatoryArcs_.setArcs(set);
395 }

References constraintMandatoryArcs_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setMandatoryArcs().

Here is the caller graph for this function:

◆ setMaxIndegree()

INLINE void gum::learning::IBNLearner::setMaxIndegree ( Size max_indegree)

sets the max indegree

Definition at line 204 of file IBNLearner_inl.h.

204 {
205 constraintIndegree_.setMaxIndegree(max_indegree);
206 }

References constraintIndegree_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setMaxIndegree().

Here is the caller graph for this function:

◆ setMaxIter()

void gum::learning::IBNLearner::setMaxIter ( Size max)
inlineoverridevirtual

stopping criterion on number of iterationsIf the criterion was disabled it will be enabled

Parameters
maxThe maximum number of iterations
Exceptions
OutOfBoundsif max<=1

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1189 of file IBNLearner.h.

1189 {
1190 algoK2_.approximationScheme().setMaxIter(max);
1191 greedyHillClimbing_.setMaxIter(max);
1192 localSearchWithTabuList_.setMaxIter(max);
1193 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setMaxTime()

void gum::learning::IBNLearner::setMaxTime ( double timeout)
inlineoverridevirtual

stopping criterion on timeout If the criterion was disabled it will be enabled

Exceptions
OutOfBoundsif timeout<=0.0 timeout is time in second (double).

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1230 of file IBNLearner.h.

1230 {
1231 algoK2_.approximationScheme().setMaxTime(timeout);
1232 greedyHillClimbing_.setMaxTime(timeout);
1233 localSearchWithTabuList_.setMaxTime(timeout);
1234 }

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setMinEpsilonRate()

void gum::learning::IBNLearner::setMinEpsilonRate ( double rate)
inlineoverridevirtual

Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|) If the criterion was disabled it will be enabled.

Exceptions
OutOfBoundsif rate<0

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1149 of file IBNLearner.h.

1149 {
1150 algoK2_.approximationScheme().setMinEpsilonRate(rate);
1151 greedyHillClimbing_.setMinEpsilonRate(rate);
1152 localSearchWithTabuList_.setMinEpsilonRate(rate);
1153 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setNumberOfThreads()

INLINE void gum::learning::IBNLearner::setNumberOfThreads ( Size nb)
overridevirtual

sets the number max of threads that can be used

Parameters
nbthe number max of threads to be used. If this number is set to 0, then it is defaulted to aGrUM's max number of threads

Reimplemented from gum::ThreadNumberManager.

Definition at line 570 of file IBNLearner_inl.h.

570 {
572 if (score_ != nullptr) score_->setNumberOfThreads(nb);
573 }
virtual void setNumberOfThreads(Size nb)
sets the number max of threads to be used by the class containing this ThreadNumberManager

References score_, and gum::ThreadNumberManager::setNumberOfThreads().

Here is the call graph for this function:

◆ setPeriodSize()

void gum::learning::IBNLearner::setPeriodSize ( Size p)
inlineoverridevirtual

how many samples between 2 stopping isEnableds

Exceptions
OutOfBoundsif p<1

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1273 of file IBNLearner.h.

1273 {
1274 algoK2_.approximationScheme().setPeriodSize(p);
1275 greedyHillClimbing_.setPeriodSize(p);
1276 localSearchWithTabuList_.setPeriodSize(p);
1277 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setPossibleEdges()

INLINE void gum::learning::IBNLearner::setPossibleEdges ( const EdgeSet & set)

assign a set of possible edges

Warning
Once at least one possible edge is defined, all other edges are not possible anymore

Definition at line 320 of file IBNLearner_inl.h.

320 {
321 constraintPossibleEdges_.setEdges(set);
322 }

References constraintPossibleEdges_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setPossibleEdges(), and setPossibleSkeleton().

Here is the caller graph for this function:

◆ setPossibleSkeleton()

INLINE void gum::learning::IBNLearner::setPossibleSkeleton ( const UndiGraph & skeleton)

assign a set of possible edges

Warning
Once at least one possible edge is defined, all other edges are not possible anymore

Definition at line 325 of file IBNLearner_inl.h.

325 {
326 setPossibleEdges(g.edges());
327 }
void setPossibleEdges(const EdgeSet &set)
assign a set of possible edges

References gum::EdgeGraphPart::edges(), and setPossibleEdges().

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setPossibleSkeleton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setRecordWeight()

INLINE void gum::learning::IBNLearner::setRecordWeight ( const std::size_t i,
const double weight )

sets the weight of the ith record of the database

assign new weight to the ith row of the learning database

Exceptions
OutOfBoundsif i is outside the set of indices of the records or if the weight is negative

Definition at line 150 of file IBNLearner_inl.h.

150 {
151 scoreDatabase_.setWeight(i, new_weight);
152 }

References scoreDatabase_.

◆ setSliceOrder() [1/2]

INLINE void gum::learning::IBNLearner::setSliceOrder ( const NodeProperty< NodeId > & slice_order)

sets a partial order on the nodes

Parameters
slice_ordera NodeProperty given the rank (priority) of nodes in the partial order

Definition at line 456 of file IBNLearner_inl.h.

456 {
457 constraintSliceOrder_ = StructuralConstraintSliceOrder(slice_order);
458 }

References constraintSliceOrder_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::setSliceOrder(), gum::learning::BNLearner< GUM_SCALAR >::setSliceOrder(), and setSliceOrder().

Here is the caller graph for this function:

◆ setSliceOrder() [2/2]

INLINE void gum::learning::IBNLearner::setSliceOrder ( const std::vector< std::vector< std::string > > & slices)

sets a partial order on the nodes

Parameters
slicesthe list of list of variable names

Definition at line 460 of file IBNLearner_inl.h.

460 {
461 NodeProperty< NodeId > slice_order;
462 NodeId rank = 0;
463 for (const auto& slice: slices) {
464 for (const auto& name: slice) {
465 slice_order.insert(idFromName(name), rank);
466 }
467 rank++;
468 }
469 setSliceOrder(slice_order);
470 }
void setSliceOrder(const NodeProperty< NodeId > &slice_order)
sets a partial order on the nodes

References idFromName(), gum::HashTable< Key, Val >::insert(), and setSliceOrder().

Here is the call graph for this function:

◆ setVerbosity()

void gum::learning::IBNLearner::setVerbosity ( bool v)
inlineoverridevirtual

verbosity

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1288 of file IBNLearner.h.

1288 {
1289 algoK2_.approximationScheme().setVerbosity(v);
1290 greedyHillClimbing_.setVerbosity(v);
1291 localSearchWithTabuList_.setVerbosity(v);
1292 };

References algoK2_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ stateApproximationScheme()

ApproximationSchemeSTATE gum::learning::IBNLearner::stateApproximationScheme ( ) const
inlineoverridevirtual

history

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1304 of file IBNLearner.h.

1304 {
1305 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->stateApproximationScheme();
1306 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1307 }

References currentAlgorithm_, and GUM_ERROR.

◆ useBDeuPrior()

INLINE void gum::learning::IBNLearner::useBDeuPrior ( double weight = 1.0)

use the BDeu prior

The BDeu prior adds weight to all the cells of the counts tables. In other words, it adds weight rows in the database with equally probable values.

Definition at line 508 of file IBNLearner_inl.h.

508 {
509 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
510
512 _setPriorWeight_(weight);
513
515 }
void _setPriorWeight_(double weight)
sets the prior weight

References _setPriorWeight_(), BDEU, checkScorePriorCompatibility(), GUM_ERROR, and priorType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useBDeuPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useCrossValidationFold()

std::pair< std::size_t, std::size_t > gum::learning::IBNLearner::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

When applied on (x,k), the method indicates to the subsequent learnings that they should be performed on the xth fold in a k-fold cross-validation context. For instance, if a database has 1000 rows, and if we perform a 10-fold cross-validation, then, the first learning fold (learning_fold=0) corresponds to rows interval [100,1000) and the test dataset corresponds to [0,100). The second learning fold (learning_fold=1) is [0,100) U [200,1000) and the corresponding test dataset is [100,200).

Parameters
learning_folda number indicating the set of rows used for learning. If N denotes the size of the database, and k_fold represents the number of folds in the cross validation, then the set of rows used for testing is [learning_fold * N / k_fold, (learning_fold+1) * N / k_fold) and the learning database is the complement in the database
k_foldthe value of "k" in k-fold cross validation
Returns
a pair [x,y) of rows' indices that corresponds to the indices of rows in the original database that constitute the test dataset
Exceptions
OutOfBoundsis raised if k_fold is equal to 0 or learning_fold is greater than or eqal to k_fold, or if k_fold is greater than or equal to the size of the database.

Definition at line 924 of file IBNLearner.cpp.

925 {
926 if (k_fold == 0) { GUM_ERROR(OutOfBounds, "K-fold cross validation with k=0 is forbidden") }
927
928 if (learning_fold >= k_fold) {
929 GUM_ERROR(OutOfBounds,
930 "In " << k_fold << "-fold cross validation, the learning "
931 << "fold should be strictly lower than " << k_fold
932 << " but, here, it is equal to " << learning_fold)
933 }
934
935 const std::size_t db_size = scoreDatabase_.databaseTable().nbRows();
936 if (k_fold >= db_size) {
937 GUM_ERROR(OutOfBounds,
938 "In " << k_fold << "-fold cross validation, the database's "
939 << "size should be strictly greater than " << k_fold
940 << " but, here, the database has only " << db_size << "rows")
941 }
942
943 // create the ranges of rows of the test database
944 const std::size_t foldSize = db_size / k_fold;
945 const std::size_t unfold_deb = learning_fold * foldSize;
946 const std::size_t unfold_end = unfold_deb + foldSize;
947
948 ranges_.clear();
949 if (learning_fold == std::size_t(0)) {
950 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
951 } else {
952 ranges_.push_back(std::pair< std::size_t, std::size_t >(std::size_t(0), unfold_deb));
953
954 if (learning_fold != k_fold - 1) {
955 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
956 }
957 }
958
959 return std::pair< std::size_t, std::size_t >(unfold_deb, unfold_end);
960 }

References GUM_ERROR, ranges_, and scoreDatabase_.

◆ useDatabaseRanges()

void gum::learning::IBNLearner::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

Parameters
rangesa set of pairs {(X1,Y1),...,(Xn,Yn)} of database's rows indices. The subsequent learnings are then performed only on the union of the rows [Xi,Yi), i in {1,...,n}. This is useful, e.g, when performing cross validation tasks, in which part of the database should be ignored. An empty set of ranges is equivalent to an interval [X,Y) ranging over the whole database.

Definition at line 1131 of file IBNLearner.cpp.

1132 {
1133 // use a score to detect whether the ranges are ok
1134 ScoreLog2Likelihood score(scoreDatabase_.parser(), *noPrior_);
1135 score.setRanges(new_ranges);
1136 ranges_ = score.ranges();
1137 }

References noPrior_, ranges_, score(), and scoreDatabase_.

Here is the call graph for this function:

◆ useDirichletPrior()

INLINE void gum::learning::IBNLearner::useDirichletPrior ( const std::string & filename,
double weight = 1 )

use the Dirichlet prior from a database

Definition at line 497 of file IBNLearner_inl.h.

497 {
498 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
499
500 priorDbname_ = filename;
502 _setPriorWeight_(weight);
503
505 }

References _setPriorWeight_(), checkScorePriorCompatibility(), DIRICHLET_FROM_DATABASE, GUM_ERROR, priorDbname_, and priorType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useDirichletPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useEM()

INLINE void gum::learning::IBNLearner::useEM ( const double epsilon,
const double noise = default_EM_noise )

use The EM algorithm to learn parameters

Parameters
epsilonsets the approximation stopping criterion: EM stops whenever the absolute value of the relative difference between two consecutive log-likelihoods drops below epsilon. Note that epsilon=0 is considered as a directive to not use EM. However, if you wish to forbid the use of EM, prefer executing Method forbidEM() rather than useEM(0) as it is more unequivocal.
noiseWhen EM starts, it initializes all the CPTs of the Bayes net. EM adds a noise to these CPTs by mixing their values with some random noise. The formula used is, up to some normalizing constant: new_cpt = (1-noise) * cpt + noise * random_cpt(). Of course, noise must belong to interval [0,1].
Warning
if epsilon=0, EM is not used
Exceptions
OutOfBoundsis raised if epsilon is strictly negative or if noise does not belong to interval [0,1].

Definition at line 257 of file IBNLearner_inl.h.

257 {
258 if (epsilon < 0.0)
259 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be non-negative");
260 if ((noise < 0.0) || (noise > 1.0))
261 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
262 if (epsilon > 0) {
263 useEM_ = true;
264 dag2BN_.setMinEpsilonRate(epsilon);
265 dag2BN_.setNoise(noise);
266 noiseEM_ = noise;
267 } else {
268 useEM_ = false; // epsilon == 0
269 }
270 }
double epsilon() const override
Get the value of epsilon.

References dag2BN_, epsilon(), GUM_ERROR, noiseEM_, and useEM_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useEM(), and useEMWithRateCriterion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useEMWithDiffCriterion()

INLINE void gum::learning::IBNLearner::useEMWithDiffCriterion ( const double epsilon,
const double noise = default_EM_noise )

use The EM algorithm to learn parameters with the diff stopping criterion

use The EM algorithm to learn parameters with the diff stoppîng criterion

Parameters
epsilonepsilon sets the approximation stopping criterion: EM stops whenever the difference between two consecutive log-likelihoods drops below epsilon. Note that, for using EM, epsilon should be strictly positive.
noiseWhen EM starts, it initializes all the CPTs of the Bayes net. EM adds a noise to these CPTs by mixing their values with some random noise. The formula used is, up to some normalizing constant: new_cpt = (1-noise) * cpt + noise * random_cpt(). Of course, noise must belong to interval [0,1].
Exceptions
OutOfBoundsis raised if epsilon is not strictly positive or if noise does not belong to interval [0,1].

Definition at line 280 of file IBNLearner_inl.h.

280 {
281 if (epsilon <= 0.0)
282 GUM_ERROR(OutOfBounds, "EM's min log-likelihood differences must be positive");
283 if ((noise < 0.0) || (noise > 1.0))
284 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
285 useEM_ = true;
286 dag2BN_.setEpsilon(epsilon);
287 dag2BN_.setNoise(noise);
288 noiseEM_ = noise;
289 }

References dag2BN_, epsilon(), GUM_ERROR, noiseEM_, and useEM_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useEMWithDiffCriterion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useEMWithRateCriterion()

INLINE void gum::learning::IBNLearner::useEMWithRateCriterion ( const double epsilon,
const double noise = default_EM_noise )

use The EM algorithm to learn parameters with the rate stopping criterion

Parameters
epsilonepsilon sets the approximation stopping criterion: EM stops whenever the absolute value of the relative difference between two consecutive log-likelihoods drops below epsilon. Note that, for using EM, epsilon should be strictly positive.
noiseWhen EM starts, it initializes all the CPTs of the Bayes net. EM adds a noise to these CPTs by mixing their values with some random noise. The formula used is, up to some normalizing constant: new_cpt = (1-noise) * cpt + noise * random_cpt(). Of course, noise must belong to interval [0,1].
Exceptions
OutOfBoundsis raised if epsilon is not strictly positive or if noise does not belong to interval [0,1].

Definition at line 273 of file IBNLearner_inl.h.

273 {
274 if (epsilon <= 0.0)
275 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be positive");
276 useEM(epsilon, noise);
277 }
void useEM(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters

References epsilon(), GUM_ERROR, and useEM().

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useEMWithRateCriterion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useGreedyHillClimbing()

INLINE void gum::learning::IBNLearner::useGreedyHillClimbing ( )

indicate that we wish to use a greedy hill climbing algorithm

Definition at line 244 of file IBNLearner_inl.h.

References GREEDY_HILL_CLIMBING, and selectedAlgo_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useGreedyHillClimbing().

Here is the caller graph for this function:

◆ useK2() [1/2]

INLINE void gum::learning::IBNLearner::useK2 ( const Sequence< NodeId > & order)

indicate that we wish to use K2

Definition at line 232 of file IBNLearner_inl.h.

232 {
234 algoK2_.setOrder(order);
235 }

References algoK2_, K2, and selectedAlgo_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useK2(), and gum::learning::BNLearner< GUM_SCALAR >::useK2().

Here is the caller graph for this function:

◆ useK2() [2/2]

INLINE void gum::learning::IBNLearner::useK2 ( const std::vector< NodeId > & order)

indicate that we wish to use K2

Definition at line 238 of file IBNLearner_inl.h.

238 {
240 algoK2_.setOrder(order);
241 }

References algoK2_, K2, and selectedAlgo_.

◆ useLocalSearchWithTabuList()

INLINE void gum::learning::IBNLearner::useLocalSearchWithTabuList ( Size tabu_size = 100,
Size nb_decrease = 2 )

indicate that we wish to use a local search with tabu list

Parameters
tabu_sizeindicate the size of the tabu list
nb_decreaseindicate the max number of changes decreasing the score consecutively that we allow to apply

Definition at line 249 of file IBNLearner_inl.h.

249 {
251 nbDecreasingChanges_ = nb_decrease;
252 constraintTabuList_.setTabuListSize(tabu_size);
253 localSearchWithTabuList_.setMaxNbDecreasingChanges(nb_decrease);
254 }

References constraintTabuList_, LOCAL_SEARCH_WITH_TABU_LIST, localSearchWithTabuList_, nbDecreasingChanges_, and selectedAlgo_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useLocalSearchWithTabuList().

Here is the caller graph for this function:

◆ useMDLCorrection()

INLINE void gum::learning::IBNLearner::useMDLCorrection ( )

indicate that we wish to use the MDL correction for MIIC

Exceptions
OperationNotAllowedwhen MIIC is not the selected algorithm

Definition at line 217 of file IBNLearner_inl.h.

References kmodeMiic_, and gum::learning::CorrectedMutualInformation::MDL.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useMDLCorrection().

Here is the caller graph for this function:

◆ useMIIC()

INLINE void gum::learning::IBNLearner::useMIIC ( )

indicate that we wish to use MIIC

Definition at line 209 of file IBNLearner_inl.h.

References MIIC, and selectedAlgo_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useMIIC().

Here is the caller graph for this function:

◆ useNMLCorrection()

INLINE void gum::learning::IBNLearner::useNMLCorrection ( )

indicate that we wish to use the NML correction for and MIIC

indicate that we wish to use the NML correction for MIIC

Exceptions
OperationNotAllowedwhen MIIC is not the selected algorithm

Definition at line 212 of file IBNLearner_inl.h.

References kmodeMiic_, and gum::learning::CorrectedMutualInformation::NML.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useNMLCorrection().

Here is the caller graph for this function:

◆ useNoCorrection()

INLINE void gum::learning::IBNLearner::useNoCorrection ( )

indicate that we wish to use the NoCorr correction for MIIC

Exceptions
OperationNotAllowedwhen MIIC is not the selected algorithm

Definition at line 222 of file IBNLearner_inl.h.

References kmodeMiic_, and gum::learning::CorrectedMutualInformation::NoCorr.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useNoCorrection().

Here is the caller graph for this function:

◆ useNoPrior()

INLINE void gum::learning::IBNLearner::useNoPrior ( )

use no prior

Definition at line 481 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), NO_prior, and priorType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useNoPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreAIC()

INLINE void gum::learning::IBNLearner::useScoreAIC ( )

indicate that we wish to use an AIC score

Definition at line 168 of file IBNLearner_inl.h.

References AIC, checkScorePriorCompatibility(), and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreAIC().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreBD()

INLINE void gum::learning::IBNLearner::useScoreBD ( )

indicate that we wish to use a BD score

Definition at line 174 of file IBNLearner_inl.h.

References BD, checkScorePriorCompatibility(), and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreBD().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreBDeu()

INLINE void gum::learning::IBNLearner::useScoreBDeu ( )

indicate that we wish to use a BDeu score

Definition at line 180 of file IBNLearner_inl.h.

References BDeu, checkScorePriorCompatibility(), and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreBDeu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreBIC()

INLINE void gum::learning::IBNLearner::useScoreBIC ( )

indicate that we wish to use a BIC score

Definition at line 186 of file IBNLearner_inl.h.

References BIC, checkScorePriorCompatibility(), and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreBIC().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreK2()

INLINE void gum::learning::IBNLearner::useScoreK2 ( )

indicate that we wish to use a K2 score

Definition at line 192 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), K2, and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreK2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useScoreLog2Likelihood()

INLINE void gum::learning::IBNLearner::useScoreLog2Likelihood ( )

indicate that we wish to use a Log2Likelihood score

Definition at line 198 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), LOG2LIKELIHOOD, and scoreType_.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useScoreLog2Likelihood().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ useSmoothingPrior()

INLINE void gum::learning::IBNLearner::useSmoothingPrior ( double weight = 1)

use the prior smoothing

Parameters
weightpass in argument a weight if you wish to assign a weight to the smoothing, else the current weight of the IBNLearner will be used.

Definition at line 487 of file IBNLearner_inl.h.

487 {
488 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
489
491 _setPriorWeight_(weight);
492
494 }

References _setPriorWeight_(), checkScorePriorCompatibility(), GUM_ERROR, priorType_, and SMOOTHING.

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useSmoothingPrior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verbosity()

bool gum::learning::IBNLearner::verbosity ( ) const
inlineoverridevirtual

verbosity

Implements gum::IApproximationSchemeConfiguration.

Definition at line 1294 of file IBNLearner.h.

1294 {
1295 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->verbosity();
1296 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
1297 }

References currentAlgorithm_, and GUM_ERROR.

Member Data Documentation

◆ _nb_threads_

Size gum::ThreadNumberManager::_nb_threads_ {0}
privateinherited

the max number of threads used by the class

Definition at line 126 of file threadNumberManager.h.

126{0};

◆ algoK2_

◆ algoMiic_

Miic gum::learning::IBNLearner::algoMiic_
protected

the Constraint MIIC algorithm

Definition at line 1001 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), latentVariables(), learnDag_(), learnPDAG(), operator=(), operator=(), and prepareMiic_().

◆ algoSimpleMiic_

SimpleMiic gum::learning::IBNLearner::algoSimpleMiic_
protected

the MIIC algorithm

Definition at line 998 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), operator=(), and operator=().

◆ constraintForbiddenArcs_

StructuralConstraintForbiddenArcs gum::learning::IBNLearner::constraintForbiddenArcs_
protected

the constraint on forbidden arcs

Definition at line 976 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), addForbiddenArc(), eraseForbiddenArc(), learnDag_(), operator=(), operator=(), prepareMiic_(), and setForbiddenArcs().

◆ constraintIndegree_

StructuralConstraintIndegree gum::learning::IBNLearner::constraintIndegree_
protected

the constraint for indegrees

Definition at line 970 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), learnDag_(), operator=(), operator=(), prepareMiic_(), and setMaxIndegree().

◆ constraintMandatoryArcs_

StructuralConstraintMandatoryArcs gum::learning::IBNLearner::constraintMandatoryArcs_
protected

the constraint on mandatory arcs

Definition at line 982 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), addMandatoryArc(), eraseMandatoryArc(), learnDag_(), operator=(), operator=(), prepareMiic_(), and setMandatoryArcs().

◆ constraintNoChildrenNodes_

StructuralConstraintNoChildrenNodes gum::learning::IBNLearner::constraintNoChildrenNodes_
protected

the constraint on no children nodes

Definition at line 988 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), addNoChildrenNode(), eraseNoChildrenNode(), learnDag_(), operator=(), operator=(), and prepareMiic_().

◆ constraintNoParentNodes_

StructuralConstraintNoParentNodes gum::learning::IBNLearner::constraintNoParentNodes_
protected

the constraint on no parent nodes

Definition at line 985 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), addNoParentNode(), eraseNoParentNode(), learnDag_(), operator=(), operator=(), and prepareMiic_().

◆ constraintPossibleEdges_

StructuralConstraintPossibleEdges gum::learning::IBNLearner::constraintPossibleEdges_
protected

the constraint on possible Edges

Definition at line 979 of file IBNLearner.h.

Referenced by addPossibleEdge(), erasePossibleEdge(), learnDag_(), prepareMiic_(), and setPossibleEdges().

◆ constraintSliceOrder_

StructuralConstraintSliceOrder gum::learning::IBNLearner::constraintSliceOrder_
protected

the constraint for 2TBNs

Definition at line 967 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), learnDag_(), operator=(), operator=(), prepareMiic_(), and setSliceOrder().

◆ constraintTabuList_

StructuralConstraintTabuList gum::learning::IBNLearner::constraintTabuList_
protected

the constraint for tabu lists

Definition at line 973 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), learnDag_(), operator=(), operator=(), and useLocalSearchWithTabuList().

◆ currentAlgorithm_

◆ dag2BN_

◆ default_EM_noise

double gum::learning::IBNLearner::default_EM_noise {0.1}
staticconstexpr

the default noise amount added to CPTs during EM's initialization (see method useEM())

Definition at line 120 of file IBNLearner.h.

120{0.1};

Referenced by gum::learning::BNLearner< GUM_SCALAR >::useEM(), gum::learning::BNLearner< GUM_SCALAR >::useEMWithDiffCriterion(), and gum::learning::BNLearner< GUM_SCALAR >::useEMWithRateCriterion().

◆ filename_

std::string gum::learning::IBNLearner::filename_ {"-"}
protected

the filename database

Definition at line 1032 of file IBNLearner.h.

1032{"-"};

Referenced by IBNLearner(), IBNLearner(), IBNLearner(), IBNLearner(), operator=(), and operator=().

◆ greedyHillClimbing_

◆ inducedTypes_

bool gum::learning::IBNLearner::inducedTypes_ {false}
protected

the policy for typing variables

Definition at line 935 of file IBNLearner.h.

935{false};

Referenced by IBNLearner(), IBNLearner(), IBNLearner(), and IBNLearner().

◆ initialDag_

DAG gum::learning::IBNLearner::initialDag_
protected

an initial DAG given to learners

Definition at line 1029 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), initialDAG(), learnDag_(), operator=(), operator=(), and setInitialDAG().

◆ kmodeMiic_

◆ localSearchWithTabuList_

◆ mutualInfo_

CorrectedMutualInformation* gum::learning::IBNLearner::mutualInfo_ {nullptr}
protected

the selected correction for miic

Definition at line 953 of file IBNLearner.h.

953{nullptr};

Referenced by ~IBNLearner(), createCorrectedMutualInformation_(), learnDag_(), learnPDAG(), operator=(), and operator=().

◆ nbDecreasingChanges_

Size gum::learning::IBNLearner::nbDecreasingChanges_ {2}
protected

Definition at line 1035 of file IBNLearner.h.

1035{2};

Referenced by IBNLearner(), IBNLearner(), operator=(), operator=(), and useLocalSearchWithTabuList().

◆ noiseEM_

double gum::learning::IBNLearner::noiseEM_ {0.1}
protected

the noise factor (in (0,1)) used by EM for perturbing the CPT during init

Definition at line 950 of file IBNLearner.h.

950{0.1};

Referenced by IBNLearner(), IBNLearner(), operator=(), operator=(), useEM(), and useEMWithDiffCriterion().

◆ noPrior_

NoPrior* gum::learning::IBNLearner::noPrior_ {nullptr}
protected

◆ onProgress

◆ onStop

Signaler1< const std::string& > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 83 of file IApproximationSchemeConfiguration.h.

Referenced by gum::learning::IBNLearner::distributeStop().

◆ paramEstimatorType_

ParamEstimatorType gum::learning::IBNLearner::paramEstimatorType_ {ParamEstimatorType::ML}
protected

the type of the parameter estimator

Definition at line 944 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), createParamEstimator_(), operator=(), and operator=().

◆ prior_

Prior* gum::learning::IBNLearner::prior_ {nullptr}
protected

◆ priorDatabase_

Database* gum::learning::IBNLearner::priorDatabase_ {nullptr}
protected

the database used by the Dirichlet a priori

Definition at line 1023 of file IBNLearner.h.

1023{nullptr};

Referenced by ~IBNLearner(), learnDag_(), operator=(), and operator=().

◆ priorDbname_

std::string gum::learning::IBNLearner::priorDbname_
protected

the filename for the Dirichlet a priori, if any

Definition at line 1026 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), operator=(), operator=(), and useDirichletPrior().

◆ priorType_

◆ priorWeight_

double gum::learning::IBNLearner::priorWeight_ {1.0f}
protected

the weight of the prior

Definition at line 964 of file IBNLearner.h.

964{1.0f};

Referenced by IBNLearner(), IBNLearner(), _setPriorWeight_(), checkScorePriorCompatibility(), operator=(), and operator=().

◆ ranges_

std::vector< std::pair< std::size_t, std::size_t > > gum::learning::IBNLearner::ranges_
protected

◆ score_

Score* gum::learning::IBNLearner::score_ {nullptr}
protected

the score used

Definition at line 941 of file IBNLearner.h.

941{nullptr};

Referenced by ~IBNLearner(), createParamEstimator_(), createScore_(), learnDag_(), operator=(), operator=(), score(), and setNumberOfThreads().

◆ scoreDatabase_

◆ scoreType_

ScoreType gum::learning::IBNLearner::scoreType_ {ScoreType::BDeu}
protected

◆ selectedAlgo_

AlgoType gum::learning::IBNLearner::selectedAlgo_ {AlgoType::MIIC}
protected

◆ useEM_

bool gum::learning::IBNLearner::useEM_ {false}
protected

a Boolean indicating whether we should use EM for parameter learning or not

Definition at line 947 of file IBNLearner.h.

947{false};

Referenced by IBNLearner(), IBNLearner(), EM(), EMState(), EMStateMessage(), forbidEM(), isUsingEM(), operator=(), operator=(), useEM(), and useEMWithDiffCriterion().


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