aGrUM 3.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:
[legend]
Collaboration diagram for gum::learning::IBNLearner:
[legend]

Classes

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

Public Types

enum class  ScoreType {
  AIC , BD , BDeu , BIC ,
  fNML , K2 , LOG2LIKELIHOOD , MDL
}
 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 ,
  PC , FCI , EXTENDED_GREEDY_HILL_CLIMBING , GREEDY_THICK_THINNING
}
 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 unsetTotalOrder ()
 removes the current total ordering constraint, if any
void setForbiddenArcs (const ArcSet &set)
 removes a total
void setMandatoryArcs (const ArcSet &set)
 assign a set of mandatory arcs
Constructors / Destructors
 IBNLearner (std::string_view filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
 read the database file for the score / parameter estimation and var names
 IBNLearner (const DatabaseTable &db)
 read the database file for the score / parameter estimation and var names
template<GUM_Numeric GUM_SCALAR>
 IBNLearner (std::string_view 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
 ~IBNLearner () override
 destructor
Operators
IBNLearner & operator= (const IBNLearner &)
 copy operator
IBNLearner & operator= (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)
PAG learnPAG ()
 learn a PAG — only valid when useFCI() has been called
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 (std::string_view var) const
 learn a structure from a file (must have read the db before)
NodeId idFromName (std::string_view var_name) const
 returns the node id corresponding to a variable name
const DatabaseTable & database () 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, double > chi2 (NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
 Return the <statistic,pvalue> pair for chi2 test in the database.
std::pair< double, double > chi2 (std::string_view name1, std::string_view name2, const std::vector< std::string > &knowing={})
 Return the <statistic,pvalue> pair for the BNLearner.
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.
std::pair< double, double > G2 (std::string_view name1, std::string_view 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 (std::string_view var1, std::string_view 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 (std::string_view var1, std::string_view 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 (std::string_view 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< double > rawPseudoCount (const std::vector< NodeId > &vars)
 Return the pseudo-counts of NodeIds vars in the base in a raw array.
std::vector< double > rawPseudoCount (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)
 use The EM algorithm to learn parameters
void useEM (const double epsilon)
 use The EM algorithm to learn parameters, with the default noise
void useEMWithRateCriterion (const double epsilon, const double noise)
 use The EM algorithm to learn parameters with the rate stopping criterion
void useEMWithRateCriterion (const double epsilon)
 use The EM algorithm with the rate stopping criterion and the default noise (key emNoise)
void useEMWithDiffCriterion (const double epsilon, const double noise)
 use The EM algorithm to learn parameters with the diff stopping criterion
void useEMWithDiffCriterion (const double epsilon)
 use The EM algorithm with the diff stopping criterion and the default noise (key emNoise)
void forbidEM ()
 prevent using the EM algorithm for parameter learning
bool isUsingEM () const
 indicates whether we use EM for parameter learning
EMApproximationScheme & EM ()
 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 useScorefNML ()
 indicate that we wish to use a fNML score
void useScoreK2 ()
 indicate that we wish to use a K2 score
void useScoreLog2Likelihood ()
 indicate that we wish to use a Log2Likelihood score
void useScoreMDL ()
 indicate that we wish to use a MDL score
a prior selection / parameterization
void useNoPrior ()
 use no prior
void useBDeuPrior (double weight)
 use the BDeu prior
void useBDeuPrior ()
 use the BDeu prior with the default weight (key priorWeight of the section learning)
void useSmoothingPrior (double weight)
 use the prior smoothing
void useSmoothingPrior ()
 use the prior smoothing with the default weight (key priorWeight of the section learning)
void useDirichletPrior (std::string_view filename, double weight)
 use the Dirichlet prior from a database
void useDirichletPrior (std::string_view filename)
 use the Dirichlet prior from a database with the default weight (key priorWeight)
std::string checkScorePriorCompatibility () const
 checks whether the current score and prior are compatible
allow/forbid the graph operations used during learning
void allowArcAdditions (bool allow=true)
 allow (true)/forbid (false) to add arcs during learning.
void allowArcDeletions (bool allow=true)
 allow (true)/forbid (false) to delete arcs during learning.
void allowArcReversals (bool allow=true)
 allow (true)/forbid (false) to reverse arcs during learning.
void allowArcTriangleDeletions (bool allow=true)
 allow (true)/forbid (false) to delete arc triangles during learning.
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< Arc > latentVariables () const
 get the list of arcs hiding latent variables
PC parameterization
void useChi2Test ()
 indicate that we wish to use Chi2 independence test for PC
void useG2Test ()
 indicate that we wish to use G2 independence test for PC
void setPCAlpha (double alpha)
 set the significance threshold alpha for PC. If it is never set, PC uses the key learning.alpha of the configuration, as it was when the learner was constructed.
void setPCStable (bool stable)
 set stable mode for PC — defer removals to end of each depth level (default true)
void setPCMaxCondSetSize (Size max_k)
 set maximum conditioning set size for PC (default Size(-1) = unlimited)
void setPCUnshieldedColliderSorted (bool sorted)
 set unshielded-collider ordering for PC: sorted=true uses descending p-value order (strongest evidence first); sorted=false uses natural traversal order (default false)
FCI parameterization
void useFCIChi2Test ()
 indicate that we wish to use Chi2 independence test for FCI
void useFCIG2Test ()
 indicate that we wish to use G2 independence test for FCI
void setFCIAlpha (double alpha)
 set the significance threshold alpha for FCI. If it is never set, FCI uses the key learning.alpha of the configuration, as it was when the learner was constructed.
void setFCIMaxPathLength (Size max_len)
 set maximum discriminating-path length for FCI R4 (default Size(-1) = unlimited)
void setFCIExhaustiveSepSet (bool exhaustive)
 enable exhaustive sepset mode for FCI skeleton learning (default false)
bool fciExhaustiveSepSet () const
 return true when FCI uses exhaustive sepset mode
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 unsetSliceOrder ()
 removes the slice order constraint
void setTotalOrder (const Sequence< NodeId > &order)
 sets a total order over some nodes
void setTotalOrder (const std::vector< std::string > &order)
 sets the max indegree
assign a new forbidden arc
void addForbiddenArc (const Arc &arc)
void addForbiddenArc (NodeId tail, NodeId head)
void addForbiddenArc (std::string_view tail, std::string_view head)
remove a forbidden arc
void eraseForbiddenArc (const Arc &arc)
void eraseForbiddenArc (NodeId tail, NodeId head)
void eraseForbiddenArc (std::string_view tail, std::string_view head)
assign a new mandatory arc
void addMandatoryArc (const Arc &arc)
void addMandatoryArc (NodeId tail, NodeId head)
void addMandatoryArc (std::string_view tail, std::string_view head)
remove a mandatory arc
void eraseMandatoryArc (const Arc &arc)
void eraseMandatoryArc (NodeId tail, NodeId head)
void eraseMandatoryArc (std::string_view tail, std::string_view head)
add a node with no parent
void addNoParentNode (NodeId node)
void addNoParentNode (std::string_view node)
remove a node with no parent
void eraseNoParentNode (NodeId node)
void eraseNoParentNode (std::string_view node)
add a node with no children
void addNoChildrenNode (NodeId node)
void addNoChildrenNode (std::string_view node)
remove a node with no children
void eraseNoChildrenNode (NodeId node)
void eraseNoChildrenNode (std::string_view 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, any edge is possible. However, once at least one possible edge is defined, all the other edges not declared possible are considered as impossible.
void addPossibleEdge (const Edge &edge)
void addPossibleEdge (NodeId tail, NodeId head)
void addPossibleEdge (std::string_view tail, std::string_view head)
remove a possible edge
void erasePossibleEdge (const Edge &edge)
void erasePossibleEdge (NodeId tail, NodeId head)
void erasePossibleEdge (std::string_view tail, std::string_view head)
Multithreading
void setNumberOfThreads (Size nb) override
 sets the number max of threads that can be used
redistribute signals AND implementation of interface
void setCurrentApproximationScheme (const ApproximationScheme *approximationScheme)
 {@ /// distribute signals
void distributeProgress (const ApproximationScheme *approximationScheme, Size pourcent, double error, double time)
 {@ /// distribute signals
void distributeStop (const ApproximationScheme *approximationScheme, std::string_view 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
Size getNumberOfThreads () const override
 returns the current max number of threads used by the class containing this ThreadNumberManager
bool isGumNumberOfThreadsOverriden () const override
 indicates whether the class containing this ThreadNumberManager set its own number of threads

Public Attributes

Signaler< Size, double, double > onProgress
 Progression, error and time.
Signaler< std::string_view > onStop
 Criteria messageApproximationScheme.

Protected Types

enum class  IndepTestType { Chi2 , G2 }
 independence test type for PC More...

Protected Member Functions

PAG learnPAG_ ()
PDAG learnPDAG_ ()
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
ParamEstimator * createParamEstimator_ (const DBRowGeneratorParser &parser, bool take_into_account_score=true)
 create the parameter estimator used for learning
DAG learnDag_ ()
 returns the DAG learnt
MixedGraph prepareMiic_ ()
 prepares the initial graph for miic
MixedGraph preparePC_ ()
 prepares the initial graph and independence test for PC
MixedGraph prepareFCI_ ()
 prepares the initial graph and independence test for FCI
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_ (std::string_view filename, const std::vector< std::string > &missing_symbols)
 reads a file and returns a databaseVectInRam
static void isCSVFileName_ (std::string_view 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
Score * score_ {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
CorrectedMutualInformation * mutualInfo_ {nullptr}
 the selected correction for miic
BNLearnerPriorType priorType_ {BNLearnerPriorType::NO_prior}
 the a priorselected for the score and parameters
Prior * prior_ {nullptr}
 the prior used
NoPrior * noPrior_ {nullptr}
double priorWeight_ {1.0f}
 the weight of the prior. It is always written by the useXxxPrior() methods, which read learning.priorWeight when no weight is given.
StructuralConstraintSliceOrder constraintSliceOrder_
 the constraint for 2TBNs
StructuralConstraintTotalOrder constraintTotalOrder_
 the total order ing constraint
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_ {preferredAlgo()}
 the learning algorithm ; it is initialized from the configuration, see preferredAlgo()
bool allowArcAdditions_ {true}
 whether we allow or not arc additions during learning
bool allowArcDeletions_ {true}
 whether we allow or not arc deletions during learning
bool allowArcReversals_ {true}
 whether we allow or not arc reversals during learning
bool allowArcTriangleDeletions_ {true}
 whether we allow or not arc deletions during learning
K2 algoK2_
 the K2 algorithm
Miic algoMiic_
 the Constraint MIIC algorithm
CorrectedMutualInformation::KModeTypes kmodeMiic_
 the penalty used in MIIC
gum::learning::PC algoPC_
 the PC algorithm
IndepTestType indepTestTypePC_ {IndepTestType::Chi2}
IndependenceTest * indepTestPC_ {nullptr}
 owned independence test object for PC (rebuilt before each learn call)
double alphaPc_ {gum::config().typed< double >("learning", "alpha")}
 PC parameters the threshold of the tests ; it is initialized from the key learning.alpha.
bool stablePc_ {true}
Size maxCondSetSizePc_ {Size(-1)}
bool sortedUCPc_ {false}
gum::learning::FCI algoFCI_
 the FCI algorithm
IndepTestType indepTestTypeFCI_ {IndepTestType::Chi2}
 independence test type for FCI (reuses IndepTestType defined above)
IndependenceTest * indepTestFCI_ {nullptr}
 owned independence test object for FCI (rebuilt before each learn call)
double alphaFci_ {gum::config().typed< double >("learning", "alpha")}
 FCI parameters the threshold of the tests ; it is initialized from the key learning.alpha.
Size maxPathLengthFci_ {Size(-1)}
bool exhaustiveSepSetFci_ {false}
DAG2BNLearner dag2BN_
 the parametric EM
GreedyHillClimbing greedyHillClimbing_
 the greedy hill climbing algorithm
GreedyHillClimbing extendedGreedyHillClimbing_
 the extended greedy hill climbing
GreedyThickThinning greedyThickThinning_
 the greedy thick-thinning 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
Database * priorDatabase_ {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 tabuListSize_ {100}
Size nbDecreasingChanges_ {2}
const ApproximationScheme * currentAlgorithm_ {nullptr}

Private Attributes

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

Learning algorithm selection

void useGreedyHillClimbing ()
 indicate that we wish to use a greedy hill climbing algorithm
void useExtendedGreedyHillClimbing ()
 indicate that we wish to use the extended greedy hill climbing algorithm
void useLocalSearchWithTabuList (Size tabu_size, Size nb_decrease)
 indicate that we wish to use a local search with tabu list
void useLocalSearchWithTabuList (Size tabu_size)
 indicate that we wish to use a local search with tabu list
void useLocalSearchWithTabuList ()
 indicate that we wish to use a local search with tabu list and the default parameters
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
void usePC ()
 indicate that we wish to use PC (Chi2 test by default)
void useFCI ()
 indicate that we wish to use FCI (Chi2 test by default)
void useGreedyThickThinning ()
 indicate that we wish to use greedy thick-thinning
void setGreedyThickThinningReversals (bool allow)
 enable or disable arc reversals in the thin phase of greedy thick-thinning
bool greedyThickThinningReversals () const
 returns whether arc reversals are allowed in the thin phase of greedy thick-thinning
bool isConstraintBased () const
 indicate if the selected algorithm is constraint-based
bool isScoreBased () const
 indicate if the selected algorithm is score-based
static AlgoType preferredAlgo ()
 the algorithm used by the learners when none is selected explicitly

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 105 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 
PC 
FCI 
EXTENDED_GREEDY_HILL_CLIMBING 
GREEDY_THICK_THINNING 

Definition at line 126 of file IBNLearner.h.

126 {
127 K2,
128 GREEDY_HILL_CLIMBING,
129 LOCAL_SEARCH_WITH_TABU_LIST,
130 MIIC,
131 PC,
132 FCI,
133 EXTENDED_GREEDY_HILL_CLIMBING,
134 GREEDY_THICK_THINNING
135 };

◆ ApproximationSchemeSTATE

The different state of an approximation scheme.

Enumerator
Undefined 
Continue 
Epsilon 
Rate 
Limit 
TimeLimit 
Stopped 

Definition at line 87 of file IApproximationSchemeConfiguration.h.

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

◆ BNLearnerPriorType

an enumeration to select the prior

Enumerator
NO_prior 
SMOOTHING 
DIRICHLET_FROM_DATABASE 
DIRICHLET_FROM_BAYESNET 
BDEU 

Definition at line 117 of file IBNLearner.h.

117 {
118 NO_prior,
119 SMOOTHING,
120 DIRICHLET_FROM_DATABASE,
121 DIRICHLET_FROM_BAYESNET,
122 BDEU
123 };

◆ IndepTestType

enum class gum::learning::IBNLearner::IndepTestType
strongprotected

independence test type for PC

Enumerator
Chi2 
G2 

Definition at line 1249 of file IBNLearner.h.

1249{ Chi2, G2 };

◆ ParamEstimatorType

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

Enumerator
ML 

Definition at line 114 of file IBNLearner.h.

114{ ML };

◆ ScoreType

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

Enumerator
AIC 
BD 
BDeu 
BIC 
fNML 
K2 
LOG2LIKELIHOOD 
MDL 

Definition at line 110 of file IBNLearner.h.

110{ AIC, BD, BDeu, BIC, fNML, K2, LOG2LIKELIHOOD, MDL };

Constructor & Destructor Documentation

◆ IBNLearner() [1/5]

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

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

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) {
207
208 GUM_CONSTRUCTOR(IBNLearner)
209 }
const DatabaseTable & databaseTable() const
returns the internal database table
Database scoreDatabase_
the database to be used by the scores and parameter estimators
std::string filename_
the filename database
IBNLearner(std::string_view filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
read the database file for the score / parameter estimation and var names
bool inducedTypes_
the policy for typing variables
NoPrior(const DatabaseTable &database, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor

References IBNLearner(), gum::learning::NoPrior::NoPrior(), gum::learning::IBNLearner::Database::databaseTable(), filename_, inducedTypes_, noPrior_, and scoreDatabase_.

Referenced by gum::learning::IBNLearner::Database::Database(), IBNLearner(), IBNLearner(), IBNLearner(), IBNLearner(), IBNLearner(), ~IBNLearner(), gum::learning::BNLearner< GUM_SCALAR >::EMsetPeriodSize(), 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) {
213 GUM_CONSTRUCTOR(IBNLearner)
214 }

References IBNLearner(), gum::learning::NoPrior::NoPrior(), gum::learning::IBNLearner::Database::databaseTable(), noPrior_, and scoreDatabase_.

Here is the call graph for this function:

◆ IBNLearner() [3/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::IBNLearner::IBNLearner ( std::string_view 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 101 of file IBNLearner_tpl.h.

103 :
104 scoreDatabase_(filename, bn, missing_symbols) {
105 filename_ = filename;
107 inducedTypes_ = false;
108 GUM_CONSTRUCTOR(IBNLearner);
109 }

References IBNLearner(), gum::learning::NoPrior::NoPrior(), gum::learning::IBNLearner::Database::databaseTable(), 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_),
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_), allowArcAdditions_(from.allowArcAdditions_),
228 allowArcDeletions_(from.allowArcDeletions_), allowArcReversals_(from.allowArcReversals_),
229 allowArcTriangleDeletions_(from.allowArcTriangleDeletions_), algoK2_(from.algoK2_),
230 algoMiic_(from.algoMiic_), kmodeMiic_(from.kmodeMiic_),
231 indepTestTypePC_(from.indepTestTypePC_), alphaPc_(from.alphaPc_), stablePc_(from.stablePc_),
232 maxCondSetSizePc_(from.maxCondSetSizePc_), sortedUCPc_(from.sortedUCPc_),
233 indepTestTypeFCI_(from.indepTestTypeFCI_), alphaFci_(from.alphaFci_),
234 maxPathLengthFci_(from.maxPathLengthFci_), exhaustiveSepSetFci_(from.exhaustiveSepSetFci_),
235 dag2BN_(from.dag2BN_), greedyHillClimbing_(from.greedyHillClimbing_),
236 extendedGreedyHillClimbing_(from.extendedGreedyHillClimbing_),
237 greedyThickThinning_(from.greedyThickThinning_),
238 localSearchWithTabuList_(from.localSearchWithTabuList_), scoreDatabase_(from.scoreDatabase_),
239 ranges_(from.ranges_), priorDbname_(from.priorDbname_), initialDag_(from.initialDag_),
240 filename_(from.filename_), tabuListSize_(from.tabuListSize_),
241 nbDecreasingChanges_(from.nbDecreasingChanges_) {
243
244 GUM_CONS_CPY(IBNLearner)
245 }
ThreadNumberManager(Size nb_threads=0)
default constructor
StructuralConstraintNoParentNodes constraintNoParentNodes_
the constraint on no parent nodes
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
std::string priorDbname_
the filename for the Dirichlet a priori, if any
double priorWeight_
the weight of the prior. It is always written by the useXxxPrior() methods, which read learning....
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done
GreedyHillClimbing extendedGreedyHillClimbing_
the extended greedy hill climbing
bool allowArcTriangleDeletions_
whether we allow or not arc deletions during learning
K2 algoK2_
the K2 algorithm
IndepTestType indepTestTypeFCI_
independence test type for FCI (reuses IndepTestType defined above)
AlgoType selectedAlgo_
the learning algorithm ; it is initialized from the configuration, see preferredAlgo()
bool allowArcAdditions_
whether we allow or not arc additions during learning
bool useEM_
a Boolean indicating whether we should use EM for parameter learning or not
DAG2BNLearner dag2BN_
the parametric EM
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
the constraint on no children nodes
ParamEstimatorType paramEstimatorType_
the type of the parameter estimator
ScoreType scoreType_
the score selected for learning
double alphaFci_
FCI parameters the threshold of the tests ; it is initialized from the key learning....
double alphaPc_
PC parameters the threshold of the tests ; it is initialized from the key learning....
StructuralConstraintIndegree constraintIndegree_
the constraint for indegrees
bool allowArcDeletions_
whether we allow or not arc deletions during learning
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
Miic algoMiic_
the Constraint MIIC algorithm
IndepTestType indepTestTypePC_
StructuralConstraintForbiddenArcs constraintForbiddenArcs_
the constraint on forbidden arcs
GreedyHillClimbing greedyHillClimbing_
the greedy hill climbing algorithm
StructuralConstraintTabuList constraintTabuList_
the constraint for tabu lists
DAG initialDag_
an initial DAG given to learners
GreedyThickThinning greedyThickThinning_
the greedy thick-thinning algorithm
bool allowArcReversals_
whether we allow or not arc reversals during learning
LocalSearchWithTabuList localSearchWithTabuList_
the local search with tabu list algorithm
StructuralConstraintSliceOrder constraintSliceOrder_
the constraint for 2TBNs
CorrectedMutualInformation::KModeTypes kmodeMiic_
the penalty used in MIIC

References gum::IApproximationSchemeConfiguration::IApproximationSchemeConfiguration(), IBNLearner(), gum::learning::NoPrior::NoPrior(), gum::ThreadNumberManager::ThreadNumberManager(), algoK2_, algoMiic_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, alphaFci_, alphaPc_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, dag2BN_, gum::learning::IBNLearner::Database::databaseTable(), exhaustiveSepSetFci_, extendedGreedyHillClimbing_, filename_, greedyHillClimbing_, greedyThickThinning_, indepTestTypeFCI_, indepTestTypePC_, inducedTypes_, initialDag_, kmodeMiic_, localSearchWithTabuList_, maxCondSetSizePc_, maxPathLengthFci_, nbDecreasingChanges_, noPrior_, paramEstimatorType_, priorDbname_, priorType_, priorWeight_, ranges_, scoreDatabase_, scoreType_, selectedAlgo_, sortedUCPc_, stablePc_, tabuListSize_, and useEM_.

Here is the call graph for this function:

◆ IBNLearner() [5/5]

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

move constructor

Definition at line 247 of file IBNLearner.cpp.

247 :
248 ThreadNumberManager(std::move(from)), inducedTypes_(from.inducedTypes_),
249 scoreType_(from.scoreType_), paramEstimatorType_(from.paramEstimatorType_),
250 useEM_(from.useEM_), priorType_(from.priorType_), priorWeight_(from.priorWeight_),
251 constraintSliceOrder_(std::move(from.constraintSliceOrder_)),
252 constraintIndegree_(std::move(from.constraintIndegree_)),
253 constraintTabuList_(std::move(from.constraintTabuList_)),
254 constraintForbiddenArcs_(std::move(from.constraintForbiddenArcs_)),
255 constraintMandatoryArcs_(std::move(from.constraintMandatoryArcs_)),
256 constraintNoParentNodes_(std::move(from.constraintNoParentNodes_)),
257 constraintNoChildrenNodes_(std::move(from.constraintNoChildrenNodes_)),
258 selectedAlgo_(from.selectedAlgo_), allowArcAdditions_(from.allowArcAdditions_),
259 allowArcDeletions_(from.allowArcDeletions_), allowArcReversals_(from.allowArcReversals_),
260 allowArcTriangleDeletions_(from.allowArcTriangleDeletions_), algoK2_(std::move(from.algoK2_)),
261 algoMiic_(std::move(from.algoMiic_)), kmodeMiic_(from.kmodeMiic_),
262 indepTestTypePC_(from.indepTestTypePC_), alphaPc_(from.alphaPc_), stablePc_(from.stablePc_),
263 maxCondSetSizePc_(from.maxCondSetSizePc_), sortedUCPc_(from.sortedUCPc_),
264 indepTestTypeFCI_(from.indepTestTypeFCI_), alphaFci_(from.alphaFci_),
265 maxPathLengthFci_(from.maxPathLengthFci_), exhaustiveSepSetFci_(from.exhaustiveSepSetFci_),
266 dag2BN_(std::move(from.dag2BN_)), greedyHillClimbing_(std::move(from.greedyHillClimbing_)),
267 extendedGreedyHillClimbing_(std::move(from.extendedGreedyHillClimbing_)),
268 greedyThickThinning_(std::move(from.greedyThickThinning_)),
269 localSearchWithTabuList_(std::move(from.localSearchWithTabuList_)),
270 scoreDatabase_(std::move(from.scoreDatabase_)), ranges_(std::move(from.ranges_)),
271 priorDbname_(std::move(from.priorDbname_)), initialDag_(std::move(from.initialDag_)),
272 filename_(std::move(from.filename_)), tabuListSize_(from.tabuListSize_),
273 nbDecreasingChanges_(std::move(from.nbDecreasingChanges_)) {
275
276 GUM_CONS_MOV(IBNLearner)
277 }

References IBNLearner(), gum::learning::NoPrior::NoPrior(), gum::ThreadNumberManager::ThreadNumberManager(), algoK2_, algoMiic_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, alphaFci_, alphaPc_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, dag2BN_, gum::learning::IBNLearner::Database::databaseTable(), exhaustiveSepSetFci_, extendedGreedyHillClimbing_, filename_, greedyHillClimbing_, greedyThickThinning_, indepTestTypeFCI_, indepTestTypePC_, inducedTypes_, initialDag_, kmodeMiic_, localSearchWithTabuList_, maxCondSetSizePc_, maxPathLengthFci_, nbDecreasingChanges_, noPrior_, paramEstimatorType_, priorDbname_, priorType_, priorWeight_, ranges_, scoreDatabase_, scoreType_, selectedAlgo_, sortedUCPc_, stablePc_, tabuListSize_, and useEM_.

Here is the call graph for this function:

◆ ~IBNLearner()

gum::learning::IBNLearner::~IBNLearner ( )
override

destructor

Definition at line 279 of file IBNLearner.cpp.

279 {
280 if (score_) delete score_;
281
282 if (prior_) delete prior_;
283
284 if (noPrior_) delete noPrior_;
285
286 if (priorDatabase_) delete priorDatabase_;
287
288 if (mutualInfo_) delete mutualInfo_;
289
290 if (indepTestPC_) delete indepTestPC_;
291
292 if (indepTestFCI_) delete indepTestFCI_;
293
294 GUM_DESTRUCTOR(IBNLearner)
295 }
Prior * prior_
the prior used
CorrectedMutualInformation * mutualInfo_
the selected correction for miic
IndependenceTest * indepTestPC_
owned independence test object for PC (rebuilt before each learn call)
Database * priorDatabase_
the database used by the Dirichlet a priori
Score * score_
the score used
IndependenceTest * indepTestFCI_
owned independence test object for FCI (rebuilt before each learn call)

References IBNLearner(), indepTestFCI_, indepTestPC_, 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 675 of file IBNLearner_inl.h.

675 {
676 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
677
678 priorWeight_ = weight;
680 }
std::string checkScorePriorCompatibility() const
checks whether the current score and prior are compatible
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References checkScorePriorCompatibility(), GUM_ERROR, and priorWeight_.

Referenced by useBDeuPrior(), 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 548 of file IBNLearner_inl.h.

void addArc(const Arc &arc)
assign a new forbidden arc

References gum::learning::StructuralConstraintForbiddenArcs::addArc(), and constraintForbiddenArcs_.

Referenced by addForbiddenArc(), and addForbiddenArc().

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

◆ addForbiddenArc() [2/3]

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

Definition at line 556 of file IBNLearner_inl.h.

556 {
557 addForbiddenArc(Arc(tail, head));
558 }
Arc(NodeId tail, NodeId head)
basic constructor. Creates tail -> head.
void addForbiddenArc(const Arc &arc)

References gum::Arc::Arc(), and addForbiddenArc().

Here is the call graph for this function:

◆ addForbiddenArc() [3/3]

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

Definition at line 566 of file IBNLearner_inl.h.

566 {
568 }
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name

References gum::Arc::Arc(), addForbiddenArc(), and idFromName().

Here is the call graph for this function:

◆ addMandatoryArc() [1/3]

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

Definition at line 581 of file IBNLearner_inl.h.

void addArc(const Arc &arc)
assign a new forbidden arc

References gum::learning::StructuralConstraintMandatoryArcs::addArc(), and constraintMandatoryArcs_.

Referenced by addMandatoryArc(), and addMandatoryArc().

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

◆ addMandatoryArc() [2/3]

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

Definition at line 629 of file IBNLearner_inl.h.

629 {
630 addMandatoryArc(Arc(tail, head));
631 }
void addMandatoryArc(const Arc &arc)

References gum::Arc::Arc(), and addMandatoryArc().

Here is the call graph for this function:

◆ addMandatoryArc() [3/3]

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

Definition at line 619 of file IBNLearner_inl.h.

619 {
621 }

References gum::Arc::Arc(), addMandatoryArc(), and idFromName().

Here is the call graph for this function:

◆ addNoChildrenNode() [1/2]

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

Definition at line 602 of file IBNLearner_inl.h.

602 {
604 }
void addNode(NodeId node)
assign a new node without children

References gum::learning::StructuralConstraintNoChildrenNodes::addNode(), and constraintNoChildrenNodes_.

Referenced by addNoChildrenNode().

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

◆ addNoChildrenNode() [2/2]

INLINE void gum::learning::IBNLearner::addNoChildrenNode ( std::string_view node)

Definition at line 606 of file IBNLearner_inl.h.

606 {
608 }
void addNoChildrenNode(NodeId node)

References addNoChildrenNode(), and idFromName().

Here is the call graph for this function:

◆ addNoParentNode() [1/2]

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

Definition at line 588 of file IBNLearner_inl.h.

void addNode(NodeId node)
assign a new node without parent

References gum::learning::StructuralConstraintNoParentNodes::addNode(), and constraintNoParentNodes_.

Referenced by addNoParentNode().

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

◆ addNoParentNode() [2/2]

INLINE void gum::learning::IBNLearner::addNoParentNode ( std::string_view node)

Definition at line 590 of file IBNLearner_inl.h.

590 {
592 }
void addNoParentNode(NodeId node)

References addNoParentNode(), and idFromName().

Here is the call graph for this function:

◆ addPossibleEdge() [1/3]

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

Definition at line 513 of file IBNLearner_inl.h.

513 {
515 }
StructuralConstraintPossibleEdges constraintPossibleEdges_
the constraint on possible Edges
void addEdge(const Edge &edge)
assign a new forbidden arc

References gum::learning::StructuralConstraintPossibleEdges::addEdge(), and constraintPossibleEdges_.

Referenced by addPossibleEdge(), and addPossibleEdge().

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

◆ addPossibleEdge() [2/3]

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

Definition at line 523 of file IBNLearner_inl.h.

523 {
524 addPossibleEdge(Edge(tail, head));
525 }
Edge(NodeId aN1, NodeId aN2)
constructs a new edge (aN1,aN2)
void addPossibleEdge(const Edge &edge)

References gum::Edge::Edge(), and addPossibleEdge().

Here is the call graph for this function:

◆ addPossibleEdge() [3/3]

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

Definition at line 533 of file IBNLearner_inl.h.

533 {
535 }

References gum::Edge::Edge(), addPossibleEdge(), and idFromName().

Here is the call graph for this function:

◆ allowArcAdditions()

INLINE void gum::learning::IBNLearner::allowArcAdditions ( bool allow = true)

allow (true)/forbid (false) to add arcs during learning.

This affects only Extended Greedy Hill Climbing and Local Search with Tabu List. Greedy Hill Climbing and K2 always allow arc additions.

Definition at line 485 of file IBNLearner_inl.h.

485{ allowArcAdditions_ = allow; }

References allowArcAdditions_.

◆ allowArcDeletions()

INLINE void gum::learning::IBNLearner::allowArcDeletions ( bool allow = true)

allow (true)/forbid (false) to delete arcs during learning.

This affects only Extended Greedy Hill Climbing and Local Search with Tabu List. Greedy Hill Climbing always allows arc deletions while K2 always forbid them. If you wish a K2-like algorithm that enables arc deletions, use and extended greedy hill climbing combined with a TotalOrder constraint.

Definition at line 488 of file IBNLearner_inl.h.

488{ allowArcDeletions_ = allow; }

References allowArcDeletions_.

◆ allowArcReversals()

INLINE void gum::learning::IBNLearner::allowArcReversals ( bool allow = true)

allow (true)/forbid (false) to reverse arcs during learning.

This affects only Extended Greedy Hill Climbing and Local Search with Tabu List. Greedy Hill Climbing always allows arc reversals while K2 always forbid them (due to its total ordering constraint).

Definition at line 491 of file IBNLearner_inl.h.

491{ allowArcReversals_ = allow; }

References allowArcReversals_.

◆ allowArcTriangleDeletions()

INLINE void gum::learning::IBNLearner::allowArcTriangleDeletions ( bool allow = true)

allow (true)/forbid (false) to delete arc triangles during learning.

This affects only Extended Greedy Hill Climbing and Local Search with Tabu List. Greedy Hill Climbing and K2 always forbid arc triangle deletions.

Definition at line 494 of file IBNLearner_inl.h.

494 {
496 }

References allowArcTriangleDeletions_.

◆ 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 1300 of file IBNLearner.cpp.

1300 {
1301 if (this->isConstraintBased()) return "";
1302
1303 const auto prior = getPriorType_();
1304
1305 switch (scoreType_) {
1307 case AIC : return ScoreAIC::isPriorCompatible(prior, priorWeight_);
1308
1309 case BD : return ScoreBD::isPriorCompatible(prior, priorWeight_);
1310
1311 case BDeu : return ScoreBDeu::isPriorCompatible(prior, priorWeight_);
1312
1313 case BIC : return ScoreBIC::isPriorCompatible(prior, priorWeight_);
1314
1315 case fNML : return ScorefNML::isPriorCompatible(prior, priorWeight_);
1316
1317 case K2 : return ScoreK2::isPriorCompatible(prior, priorWeight_);
1318
1320
1321 case MDL : return ScoreMDL::isPriorCompatible(prior, priorWeight_);
1322
1323 default : return "IBNLearner does not support yet this score";
1324 }
1325 }
ScoreType
an enumeration enabling to select easily the score we wish to use
Definition IBNLearner.h:110
PriorType getPriorType_() const
returns the type (as a string) of a given prior
bool isConstraintBased() const
indicate if the selected algorithm is constraint-based
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
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
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
std::string isPriorCompatible() const final
indicates whether the prior is compatible (meaningful) with the score

References getPriorType_(), isConstraintBased(), gum::learning::ScoreAIC::isPriorCompatible(), gum::learning::ScoreBD::isPriorCompatible(), gum::learning::ScoreBDeu::isPriorCompatible(), gum::learning::ScoreBIC::isPriorCompatible(), gum::learning::ScorefNML::isPriorCompatible(), gum::learning::ScoreK2::isPriorCompatible(), gum::learning::ScoreLog2Likelihood::isPriorCompatible(), priorWeight_, and scoreType_.

Referenced by _setPriorWeight_(), useBDeuPrior(), useDirichletPrior(), useNoPrior(), useScoreAIC(), useScoreBD(), useScoreBDeu(), useScoreBIC(), useScorefNML(), useScoreK2(), useScoreLog2Likelihood(), useScoreMDL(), 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 ( 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 1368 of file IBNLearner.cpp.

1368 {
1369 createPrior_();
1370 gum::learning::IndepTestChi2 chi2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1371
1372 return chi2score.statistics(id1, id2, knowing);
1373 }
DBRowGeneratorParser & parser()
returns the parser for the database
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(), gum::learning::IBNLearner::Database::parser(), 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:

◆ chi2() [2/2]

std::pair< double, double > gum::learning::IBNLearner::chi2 ( std::string_view name1,
std::string_view 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 1375 of file IBNLearner.cpp.

1377 {
1378 std::vector< NodeId > knowingIds;
1379 std::transform(knowing.begin(),
1380 knowing.end(),
1381 std::back_inserter(knowingIds),
1382 [this](const std::string& c) { return this->idFromName(c); });
1383 return chi2(idFromName(name1), idFromName(name2), knowingIds);
1384 }
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:

◆ clearDatabaseRanges()

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

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

Definition at line 775 of file IBNLearner_inl.h.

775{ ranges_.clear(); }

References ranges_.

◆ correctedMutualInformation() [1/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 1433 of file IBNLearner.cpp.

1435 {
1436 createPrior_();
1437 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(),
1438 *prior_,
1439 databaseRanges());
1440
1441 switch (kmodeMiic_) {
1443 case MDL : cmi.useMDL(); break;
1444
1445 case NML : cmi.useNML(); break;
1446
1447 case NoCorr : cmi.useNoCorr(); break;
1448
1449 default :
1450 GUM_ERROR(NotImplementedYet,
1451 "The BNLearner's corrected mutual information class does "
1452 << "not implement yet this correction : " << int(kmodeMiic_))
1453 }
1454 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1455 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1456 }
KModeTypes
the description type for the complexity correction
double weight(const std::size_t i) const
returns the weight of the ith record
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

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

Referenced by correctedMutualInformation().

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

◆ correctedMutualInformation() [2/2]

double gum::learning::IBNLearner::correctedMutualInformation ( std::string_view var1,
std::string_view 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 1458 of file IBNLearner.cpp.

1460 {
1461 std::vector< NodeId > knowingIds;
1462
1463 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1464
1465 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1466
1467 return correctedMutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1468 }
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:

◆ createCorrectedMutualInformation_()

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

create the Corrected Mutual Information instance for Miic

Definition at line 996 of file IBNLearner.cpp.

996 {
997 if (mutualInfo_ != nullptr) delete mutualInfo_;
998
1000 *noPrior_,
1001 ranges_,
1003 switch (kmodeMiic_) {
1005 case MDL : mutualInfo_->useMDL(); break;
1006 case NML : mutualInfo_->useNML(); break;
1007 case NoCorr : mutualInfo_->useNoCorr(); break;
1008 default :
1009 GUM_ERROR(NotImplementedYet,
1010 "The BNLearner's corrected mutual information class does "
1011 << "not implement yet this correction : " << int(kmodeMiic_))
1012 }
1013 }
void useNML()
use the kNML penalty function
CorrectedMutualInformation(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
void useNoCorr()
use no correction/penalty function
void useMDL()
use the MDL penalty function
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
returns the mapping between node ids and their columns in the database

References gum::learning::CorrectedMutualInformation::CorrectedMutualInformation(), GUM_ERROR, kmodeMiic_, mutualInfo_, gum::learning::IBNLearner::Database::nodeId2Columns(), noPrior_, gum::learning::IBNLearner::Database::parser(), ranges_, scoreDatabase_, gum::learning::CorrectedMutualInformation::useMDL(), gum::learning::CorrectedMutualInformation::useNML(), and gum::learning::CorrectedMutualInformation::useNoCorr().

Referenced by createPrior_(), and prepareMiic_().

Here is the call graph for this function:
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 589 of file IBNLearner.cpp.

590 {
591 ParamEstimator* param_estimator = nullptr;
592
593 // create the new estimator
594 switch (paramEstimatorType_) {
596 if (take_into_account_score && (score_ != nullptr)) {
597 param_estimator = new ParamEstimatorML(parser,
598 *prior_,
600 ranges_,
602 } else {
603 param_estimator = new ParamEstimatorML(parser,
604 *prior_,
605 *noPrior_,
606 ranges_,
608 }
609
610 break;
611
612 default :
613 GUM_ERROR(OperationNotAllowed,
614 "IBNLearner does not support " << "yet this parameter estimator")
615 }
616
617 // assign the number of threads
618 param_estimator->setNumberOfThreads(
620
621 // assign the set of ranges
622 param_estimator->setRanges(ranges_);
623
624 return param_estimator;
625 }
ParamEstimatorML(const DBRowGeneratorParser &parser, const Prior &external_prior, const Prior &_score_internal_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
virtual const Prior & internalPrior() const =0
returns the internal prior of the score
virtual Size getNumberOfThreads() const =0
returns the current max number of threads of the scheduler
virtual bool isGumNumberOfThreadsOverriden() const =0
indicates whether the user set herself the number of threads

References gum::learning::ParamEstimatorML::ParamEstimatorML(), gum::ThreadNumberManager::getNumberOfThreads(), GUM_ERROR, gum::learning::Score::internalPrior(), gum::ThreadNumberManager::isGumNumberOfThreadsOverriden(), ML, gum::learning::IBNLearner::Database::nodeId2Columns(), noPrior_, paramEstimatorType_, prior_, ranges_, score_, scoreDatabase_, gum::learning::ParamEstimator::setNumberOfThreads(), and gum::learning::ParamEstimator::setRanges().

Referenced by createPrior_().

Here is the call graph for this function:
Here is the caller 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 >.

References createCorrectedMutualInformation_(), createParamEstimator_(), createScore_(), currentTime(), disableEpsilon(), disableMaxIter(), disableMaxTime(), disableMinEpsilonRate(), distributeProgress(), distributeStop(), EMCurrentTime(), EMdisableEpsilon(), EMdisableMaxIter(), EMdisableMaxTime(), EMdisableMinEpsilonRate(), EMenableEpsilon(), EMenableMaxIter(), EMenableMaxTime(), EMenableMinEpsilonRate(), EMEpsilon(), EMHistory(), EMisEnabledEpsilon(), EMisEnabledMaxIter(), EMisEnabledMaxTime(), EMisEnabledMinEpsilonRate(), EMMaxIter(), EMMaxTime(), EMMinEpsilonRate(), EMnbrIterations(), EMPeriodSize(), EMsetEpsilon(), EMsetMaxIter(), EMsetMaxTime(), EMsetMinEpsilonRate(), EMsetPeriodSize(), EMsetVerbosity(), EMStateApproximationScheme(), EMVerbosity(), enableEpsilon(), enableMaxIter(), enableMaxTime(), enableMinEpsilonRate(), epsilon(), getPriorType_(), history(), isEnabledEpsilon(), isEnabledMaxIter(), isEnabledMaxTime(), isEnabledMinEpsilonRate(), learnDag_(), maxIter(), maxTime(), minEpsilonRate(), nbrIterations(), periodSize(), prepareFCI_(), prepareMiic_(), preparePC_(), setCurrentApproximationScheme(), setEpsilon(), setMaxIter(), setMaxTime(), setMinEpsilonRate(), setPeriodSize(), setVerbosity(), stateApproximationScheme(), and verbosity().

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 516 of file IBNLearner.cpp.

516 {
517 // first, save the old score, to be delete if everything is ok
518 Score* old_score = score_;
519
520 // create the new scoring function
521 switch (scoreType_) {
522 case ScoreType::AIC :
524 *prior_,
525 ranges_,
527 break;
528
529 case ScoreType::BD :
531 *prior_,
532 ranges_,
534 break;
535
536 case ScoreType::BDeu :
538 *prior_,
539 ranges_,
541 break;
542
543 case ScoreType::BIC :
545 *prior_,
546 ranges_,
548 break;
549
550 case ScoreType::fNML :
552 *prior_,
553 ranges_,
555 break;
556
557 case ScoreType::K2 :
559 *prior_,
560 ranges_,
562 break;
563
566 *prior_,
567 ranges_,
569 break;
570
571 case ScoreType::MDL :
573 *prior_,
574 ranges_,
576 break;
577
578 default : GUM_ERROR(OperationNotAllowed, "IBNLearner does not support yet this score")
579 }
580
581 // remove the old score, if any
582 if (old_score != nullptr) delete old_score;
583
584 // assign the number of threads
586 : 0);
587 }
ScoreAIC(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreBD(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreBDeu(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreBIC(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreK2(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreLog2Likelihood(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
void setNumberOfThreads(Size nb) override
sets the number max of threads that can be used
ScorefNML(const DBRowGeneratorParser &parser, const Prior &prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
ScoreBIC ScoreMDL
Definition scoreMDL.h:67

References gum::learning::ScoreAIC::ScoreAIC(), gum::learning::ScoreBD::ScoreBD(), gum::learning::ScoreBDeu::ScoreBDeu(), gum::learning::ScoreBIC::ScoreBIC(), gum::learning::ScorefNML::ScorefNML(), gum::learning::ScoreK2::ScoreK2(), gum::learning::ScoreLog2Likelihood::ScoreLog2Likelihood(), AIC, BD, BDeu, BIC, fNML, gum::ThreadNumberManager::getNumberOfThreads(), GUM_ERROR, gum::ThreadNumberManager::isGumNumberOfThreadsOverriden(), K2, LOG2LIKELIHOOD, MDL, gum::learning::IBNLearner::Database::nodeId2Columns(), gum::learning::IBNLearner::Database::parser(), prior_, ranges_, score_, scoreDatabase_, scoreType_, and gum::learning::Score::setNumberOfThreads().

Referenced by createPrior_(), learnDAG(), and score().

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

◆ currentTime()

INLINE double gum::learning::IBNLearner::currentTime ( ) const
overridevirtual

get the current running time in second (double)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 936 of file IBNLearner_inl.h.

936 {
937 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->currentTime();
938 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
939 }
double currentTime() const override
Returns the current running time in second.
const ApproximationScheme * currentAlgorithm_

References currentAlgorithm_, gum::ApproximationScheme::currentTime(), and GUM_ERROR.

Referenced by createPrior_().

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

◆ database()

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

returns the database used by the BNLearner

Definition at line 778 of file IBNLearner_inl.h.

778 {
780 }

References gum::learning::IBNLearner::Database::databaseTable(), and scoreDatabase_.

Referenced by readFile_().

Here is the call graph for this function:
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 770 of file IBNLearner_inl.h.

770 {
771 return ranges_;
772 }

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 162 of file IBNLearner_inl.h.

162{ return scoreDatabase_.weight(); }

References scoreDatabase_, and gum::learning::IBNLearner::Database::weight().

Here is the call graph for this function:

◆ disableEpsilon()

INLINE void gum::learning::IBNLearner::disableEpsilon ( )
overridevirtual

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 843 of file IBNLearner_inl.h.

843 {
848 }
void disableEpsilon() override
Disable stopping criterion on epsilon.
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::disableEpsilon(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ disableMaxIter()

INLINE void gum::learning::IBNLearner::disableMaxIter ( )
overridevirtual

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 905 of file IBNLearner_inl.h.

905 {
910 }
void disableMaxIter() override
Disable stopping criterion on max iterations.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::disableMaxIter(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ disableMaxTime()

INLINE void gum::learning::IBNLearner::disableMaxTime ( )
overridevirtual

Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 941 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::disableMaxTime(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ disableMinEpsilonRate()

INLINE void gum::learning::IBNLearner::disableMinEpsilonRate ( )
overridevirtual

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 874 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::disableMinEpsilonRate(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ distributeProgress()

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

{@ /// distribute signals

Definition at line 817 of file IBNLearner_inl.h.

820 {
821 setCurrentApproximationScheme(approximationScheme);
822 if (onProgress.hasListener()) GUM_EMIT3(onProgress, pourcent, error, time);
823 }
Signaler< Size, double, double > onProgress
Progression, error and time.
void setCurrentApproximationScheme(const ApproximationScheme *approximationScheme)
{@ /// distribute signals
#define GUM_EMIT3(signal, arg1, arg2, arg3)
Definition signaler.h:291

References GUM_EMIT3, gum::__sig__::BasicSignaler< Args... >::hasListener(), gum::IApproximationSchemeConfiguration::onProgress, and setCurrentApproximationScheme().

Referenced by createPrior_(), and gum::learning::BNLearnerListener::whenProgress().

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

◆ distributeStop()

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

distribute signals

Definition at line 825 of file IBNLearner_inl.h.

826 {
827 setCurrentApproximationScheme(approximationScheme);
828 if (onStop.hasListener()) GUM_EMIT1(onStop, message);
829 }
Signaler< std::string_view > onStop
Criteria messageApproximationScheme.
#define GUM_EMIT1(signal, arg1)
Definition signaler.h:289

References GUM_EMIT1, gum::__sig__::BasicSignaler< Args... >::hasListener(), gum::IApproximationSchemeConfiguration::onStop, and setCurrentApproximationScheme().

Referenced by createPrior_(), and gum::learning::BNLearnerListener::whenStop().

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

◆ domainSize() [1/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 761 of file IBNLearner_inl.h.

761{ return scoreDatabase_.domainSizes()[var]; }
const std::vector< std::size_t > & domainSizes() const
returns the domain sizes of the variables

References gum::learning::IBNLearner::Database::domainSizes(), and scoreDatabase_.

Here is the call graph for this function:

◆ domainSize() [2/2]

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

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

Definition at line 764 of file IBNLearner_inl.h.

764 {
766 }

References gum::learning::IBNLearner::Database::domainSizes(), idFromName(), and scoreDatabase_.

Here is the call graph for this function:

◆ 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 756 of file IBNLearner_inl.h.

756 {
758 }

References gum::learning::IBNLearner::Database::domainSizes(), and scoreDatabase_.

Here is the call graph for this function:

◆ 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 467 of file IBNLearner_inl.h.

467 {
468 if (useEM_) return dag2BN_;
469 else GUM_ERROR(NotFound, "EM is currently forbidden. Please enable it with useEM()")
470 }

References dag2BN_, GUM_ERROR, and useEM_.

◆ EMCurrentTime()

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

get the current running time in second (double)

Definition at line 1038 of file IBNLearner_inl.h.

1038{ return dag2BN_.currentTime(); }

References gum::ApproximationScheme::currentTime(), and dag2BN_.

Referenced by createPrior_().

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

◆ EMdisableEpsilon()

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

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

Definition at line 1006 of file IBNLearner_inl.h.

References dag2BN_, and gum::ApproximationScheme::disableEpsilon().

Referenced by createPrior_().

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

◆ EMdisableMaxIter()

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

Disable stopping criterion on max iterations.

Definition at line 1028 of file IBNLearner_inl.h.

References dag2BN_, and gum::ApproximationScheme::disableMaxIter().

Referenced by createPrior_().

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

◆ EMdisableMaxTime()

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

Disable EM's timeout stopping criterion.

Definition at line 1040 of file IBNLearner_inl.h.

References dag2BN_, and gum::ApproximationScheme::disableMaxTime().

Referenced by createPrior_().

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

◆ EMdisableMinEpsilonRate()

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

Disable the log-likelihood evolution rate stopping criterion.

Definition at line 1016 of file IBNLearner_inl.h.

References dag2BN_, and gum::ApproximationScheme::disableMinEpsilonRate().

Referenced by createPrior_().

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

◆ EMenableEpsilon()

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

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 1008 of file IBNLearner_inl.h.

void enableEpsilon() override
Enable stopping criterion on epsilon.

References dag2BN_, and gum::ApproximationScheme::enableEpsilon().

Referenced by createPrior_().

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

◆ EMenableMaxIter()

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

Enable stopping criterion on max iterations.

Definition at line 1030 of file IBNLearner_inl.h.

void enableMaxIter() override
Enable stopping criterion on max iterations.

References dag2BN_, and gum::ApproximationScheme::enableMaxIter().

Referenced by createPrior_().

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

◆ EMenableMaxTime()

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

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 1042 of file IBNLearner_inl.h.

void enableMaxTime() override
Enable stopping criterion on timeout.

References dag2BN_, and gum::ApproximationScheme::enableMaxTime().

Referenced by createPrior_().

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

◆ EMenableMinEpsilonRate()

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

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 1018 of file IBNLearner_inl.h.

void enableMinEpsilonRate() override
Enable stopping criterion on epsilon rate.

References dag2BN_, and gum::ApproximationScheme::enableMinEpsilonRate().

Referenced by createPrior_().

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

◆ EMEpsilon()

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

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 1004 of file IBNLearner_inl.h.

1004{ return dag2BN_.epsilon(); }
double epsilon() const override
Returns the value of epsilon.

References dag2BN_, and gum::ApproximationScheme::epsilon().

Referenced by createPrior_().

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

◆ EMHistory()

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

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 1061 of file IBNLearner_inl.h.

1061{ return dag2BN_.history(); }
const std::vector< double > & history() const override
Returns the scheme history.

References dag2BN_, and gum::ApproximationScheme::history().

Referenced by createPrior_().

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

◆ EMisEnabledEpsilon()

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

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

Definition at line 1010 of file IBNLearner_inl.h.

1010{ return dag2BN_.isEnabledEpsilon(); }
bool isEnabledEpsilon() const override
Returns true if stopping criterion on epsilon is enabled, false otherwise.

References dag2BN_, and gum::ApproximationScheme::isEnabledEpsilon().

Referenced by createPrior_().

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

◆ EMisEnabledMaxIter()

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

Definition at line 1032 of file IBNLearner_inl.h.

1032{ return dag2BN_.isEnabledMaxIter(); }
bool isEnabledMaxIter() const override
Returns true if stopping criterion on max iterations is enabled, false otherwise.

References dag2BN_, and gum::ApproximationScheme::isEnabledMaxIter().

Referenced by createPrior_().

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

◆ EMisEnabledMaxTime()

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

Definition at line 1044 of file IBNLearner_inl.h.

1044{ return dag2BN_.isEnabledMaxTime(); }
bool isEnabledMaxTime() const override
Returns true if stopping criterion on timeout is enabled, false otherwise.

References dag2BN_, and gum::ApproximationScheme::isEnabledMaxTime().

Referenced by createPrior_().

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

◆ EMisEnabledMinEpsilonRate()

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

Definition at line 1020 of file IBNLearner_inl.h.

1020 {
1022 }
bool isEnabledMinEpsilonRate() const override
Returns true if stopping criterion on epsilon rate is enabled, false otherwise.

References dag2BN_, and gum::ApproximationScheme::isEnabledMinEpsilonRate().

Referenced by createPrior_().

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

◆ EMMaxIter()

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

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 1026 of file IBNLearner_inl.h.

1026{ return dag2BN_.maxIter(); }
Size maxIter() const override
Returns the criterion on number of iterations.

References dag2BN_, and gum::ApproximationScheme::maxIter().

Referenced by createPrior_().

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

◆ EMMaxTime()

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

@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 1036 of file IBNLearner_inl.h.

1036{ return dag2BN_.maxTime(); }
double maxTime() const override
Returns the timeout (in seconds).

References dag2BN_, and gum::ApproximationScheme::maxTime().

Referenced by createPrior_().

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

◆ EMMinEpsilonRate()

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

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 1014 of file IBNLearner_inl.h.

1014{ return dag2BN_.minEpsilonRate(); }
double minEpsilonRate() const override
Returns the value of the minimal epsilon rate.

References dag2BN_, and gum::ApproximationScheme::minEpsilonRate().

Referenced by createPrior_().

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

◆ EMnbrIterations()

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

returns the number of iterations performed by the last EM execution

Definition at line 1059 of file IBNLearner_inl.h.

1059{ return dag2BN_.nbrIterations(); }
Size nbrIterations() const override
Returns the number of iterations.

References dag2BN_, and gum::ApproximationScheme::nbrIterations().

Referenced by createPrior_().

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

◆ EMPeriodSize()

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

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 1048 of file IBNLearner_inl.h.

1048{ return dag2BN_.periodSize(); }
Size periodSize() const override
Returns the period size.

References dag2BN_, and gum::ApproximationScheme::periodSize().

Referenced by createPrior_().

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

◆ EMsetEpsilon()

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

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 1002 of file IBNLearner_inl.h.

1002{ dag2BN_.setEpsilon(eps); }
void setEpsilon(double eps) override
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...

References dag2BN_, and gum::learning::EMApproximationScheme::setEpsilon().

Referenced by createPrior_().

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

◆ EMsetMaxIter()

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

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 1024 of file IBNLearner_inl.h.

1024{ dag2BN_.setMaxIter(max); }
void setMaxIter(Size max) override
Stopping criterion on number of iterations.

References dag2BN_, and gum::ApproximationScheme::setMaxIter().

Referenced by createPrior_().

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

◆ EMsetMaxTime()

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

add a stopping criterion on timeout

Parameters
timeoutthe timeout in milliseconds
Exceptions
OutOfBoundsif timeout<=0.0

Definition at line 1034 of file IBNLearner_inl.h.

1034{ dag2BN_.setMaxTime(timeout); }
void setMaxTime(double timeout) override
Stopping criterion on timeout.

References dag2BN_, and gum::ApproximationScheme::setMaxTime().

Referenced by createPrior_().

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

◆ EMsetMinEpsilonRate()

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

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 1012 of file IBNLearner_inl.h.

1012{ dag2BN_.setMinEpsilonRate(rate); }
void setMinEpsilonRate(double rate) override
sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate

References dag2BN_, and gum::learning::EMApproximationScheme::setMinEpsilonRate().

Referenced by createPrior_().

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

◆ EMsetPeriodSize()

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

how many samples between 2 stoppings isEnabled

Exceptions
OutOfBoundsif p<1

Definition at line 1046 of file IBNLearner_inl.h.

1046{ dag2BN_.setPeriodSize(p); }
void setPeriodSize(Size p) override
How many samples between two stopping is enable.

References dag2BN_, and gum::ApproximationScheme::setPeriodSize().

Referenced by createPrior_().

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

◆ EMsetVerbosity()

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

sets or unsets EM's verbosity

Definition at line 1050 of file IBNLearner_inl.h.

1050{ dag2BN_.setVerbosity(v); }
void setVerbosity(bool v) override
Set the verbosity on (true) or off (false).

References dag2BN_, and gum::ApproximationScheme::setVerbosity().

Referenced by createPrior_().

Here is the call graph for this function:
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 473 of file IBNLearner_inl.h.

References dag2BN_, gum::ApproximationScheme::stateApproximationScheme(), gum::IApproximationSchemeConfiguration::Undefined, and useEM_.

Here is the call graph for this function:

◆ EMStateApproximationScheme()

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

get the current state of EM

Definition at line 1055 of file IBNLearner_inl.h.

1055 {
1057 }

References dag2BN_, and gum::ApproximationScheme::stateApproximationScheme().

Referenced by createPrior_().

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

◆ EMStateMessage()

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

returns the state of the EM algorithm

Definition at line 479 of file IBNLearner_inl.h.

479 {
481 else return "EM is currently forbidden. Please enable it with useEM()";
482 }
std::string messageApproximationScheme() const
Returns the approximation scheme message.

References dag2BN_, gum::IApproximationSchemeConfiguration::messageApproximationScheme(), and useEM_.

Here is the call graph for this function:

◆ EMVerbosity()

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

returns the EM's verbosity status

Definition at line 1052 of file IBNLearner_inl.h.

1052{ return dag2BN_.verbosity(); }
bool verbosity() const override
Returns true if verbosity is enabled.

References dag2BN_, and gum::ApproximationScheme::verbosity().

Referenced by createPrior_().

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

◆ enableEpsilon()

INLINE void gum::learning::IBNLearner::enableEpsilon ( )
overridevirtual

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 850 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::enableEpsilon(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ enableMaxIter()

INLINE void gum::learning::IBNLearner::enableMaxIter ( )
overridevirtual

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 912 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::enableMaxIter(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ enableMaxTime()

INLINE void gum::learning::IBNLearner::enableMaxTime ( )
overridevirtual

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 948 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::enableMaxTime(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ enableMinEpsilonRate()

INLINE void gum::learning::IBNLearner::enableMinEpsilonRate ( )
overridevirtual

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 881 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, gum::ApproximationScheme::enableMinEpsilonRate(), greedyHillClimbing_, and localSearchWithTabuList_.

Referenced by createPrior_().

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

◆ epsilon()

INLINE double gum::learning::IBNLearner::epsilon ( ) const
overridevirtual

Get the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 838 of file IBNLearner_inl.h.

838 {
839 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->epsilon();
840 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
841 }

References currentAlgorithm_, gum::ApproximationScheme::epsilon(), and GUM_ERROR.

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

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

◆ eraseForbiddenArc() [1/3]

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

Definition at line 551 of file IBNLearner_inl.h.

551 {
553 }
void eraseArc(const Arc &arc)
remove a forbidden arc

References constraintForbiddenArcs_, and gum::learning::StructuralConstraintForbiddenArcs::eraseArc().

Referenced by eraseForbiddenArc(), and eraseForbiddenArc().

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

◆ eraseForbiddenArc() [2/3]

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

Definition at line 561 of file IBNLearner_inl.h.

561 {
562 eraseForbiddenArc(Arc(tail, head));
563 }
void eraseForbiddenArc(const Arc &arc)

References gum::Arc::Arc(), and eraseForbiddenArc().

Here is the call graph for this function:

◆ eraseForbiddenArc() [3/3]

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

Definition at line 571 of file IBNLearner_inl.h.

571 {
573 }

References gum::Arc::Arc(), eraseForbiddenArc(), and idFromName().

Here is the call graph for this function:

◆ eraseMandatoryArc() [1/3]

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

Definition at line 584 of file IBNLearner_inl.h.

584 {
586 }
void eraseArc(const Arc &arc)
remove a forbidden arc

References constraintMandatoryArcs_, and gum::learning::StructuralConstraintMandatoryArcs::eraseArc().

Referenced by eraseMandatoryArc(), and eraseMandatoryArc().

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

◆ eraseMandatoryArc() [2/3]

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

Definition at line 634 of file IBNLearner_inl.h.

634 {
635 eraseMandatoryArc(Arc(tail, head));
636 }
void eraseMandatoryArc(const Arc &arc)

References gum::Arc::Arc(), and eraseMandatoryArc().

Here is the call graph for this function:

◆ eraseMandatoryArc() [3/3]

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

Definition at line 624 of file IBNLearner_inl.h.

624 {
626 }

References gum::Arc::Arc(), eraseMandatoryArc(), and idFromName().

Here is the call graph for this function:

◆ eraseNoChildrenNode() [1/2]

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

Definition at line 610 of file IBNLearner_inl.h.

610 {
612 }
void eraseNode(NodeId node)
remove a forbidden w node without children

References constraintNoChildrenNodes_, and gum::learning::StructuralConstraintNoChildrenNodes::eraseNode().

Referenced by eraseNoChildrenNode().

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

◆ eraseNoChildrenNode() [2/2]

INLINE void gum::learning::IBNLearner::eraseNoChildrenNode ( std::string_view node)

Definition at line 614 of file IBNLearner_inl.h.

614 {
616 }
void eraseNoChildrenNode(NodeId node)

References eraseNoChildrenNode(), and idFromName().

Here is the call graph for this function:

◆ eraseNoParentNode() [1/2]

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

Definition at line 594 of file IBNLearner_inl.h.

594 {
596 }
void eraseNode(NodeId node)
remove a node without parent

References constraintNoParentNodes_, and gum::learning::StructuralConstraintNoParentNodes::eraseNode().

Referenced by eraseNoParentNode().

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

◆ eraseNoParentNode() [2/2]

INLINE void gum::learning::IBNLearner::eraseNoParentNode ( std::string_view node)

Definition at line 598 of file IBNLearner_inl.h.

598 {
600 }
void eraseNoParentNode(NodeId node)

References eraseNoParentNode(), and idFromName().

Here is the call graph for this function:

◆ erasePossibleEdge() [1/3]

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

Definition at line 518 of file IBNLearner_inl.h.

518 {
520 }
void eraseEdge(const Edge &edge)
remove a forbidden arc

References constraintPossibleEdges_, and gum::learning::StructuralConstraintPossibleEdges::eraseEdge().

Referenced by erasePossibleEdge(), and erasePossibleEdge().

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

◆ erasePossibleEdge() [2/3]

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

Definition at line 528 of file IBNLearner_inl.h.

528 {
529 erasePossibleEdge(Edge(tail, head));
530 }
void erasePossibleEdge(const Edge &edge)

References gum::Edge::Edge(), and erasePossibleEdge().

Here is the call graph for this function:

◆ erasePossibleEdge() [3/3]

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

Definition at line 538 of file IBNLearner_inl.h.

538 {
540 }

References gum::Edge::Edge(), erasePossibleEdge(), and idFromName().

Here is the call graph for this function:

◆ fciExhaustiveSepSet()

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

return true when FCI uses exhaustive sepset mode

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 272 of file IBNLearner_inl.h.

272 {
274 GUM_ERROR(OperationNotAllowed,
275 "fciExhaustiveSepSet() is only valid when using the FCI algorithm")
276 }
278 }

References exhaustiveSepSetFci_, FCI, GUM_ERROR, and selectedAlgo_.

◆ forbidEM()

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

prevent using the EM algorithm for parameter learning

forbid to use EM

Definition at line 461 of file IBNLearner_inl.h.

461{ useEM_ = false; }

References useEM_.

◆ G2() [1/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 1387 of file IBNLearner.cpp.

1387 {
1388 createPrior_();
1389 gum::learning::IndepTestG2 g2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1390 return g2score.statistics(id1, id2, knowing);
1391 }

References createPrior_(), databaseRanges(), gum::learning::IBNLearner::Database::parser(), 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:

◆ G2() [2/2]

std::pair< double, double > gum::learning::IBNLearner::G2 ( std::string_view name1,
std::string_view 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 1393 of file IBNLearner.cpp.

1395 {
1396 std::vector< NodeId > knowingIds;
1397 std::transform(knowing.begin(),
1398 knowing.end(),
1399 std::back_inserter(knowingIds),
1400 [this](const std::string& c) { return this->idFromName(c); });
1401 return G2(idFromName(name1), idFromName(name2), knowingIds);
1402 }
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:

◆ getNumberOfThreads()

◆ getPriorType_()

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

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

Definition at line 735 of file IBNLearner_inl.h.

References gum::learning::BDeuPriorType, gum::learning::DirichletPriorType, GUM_ERROR, gum::learning::NoPriorType, priorType_, and gum::learning::SmoothingPriorType.

Referenced by checkScorePriorCompatibility(), and createPrior_().

Here is the caller graph for this function:

◆ greedyThickThinningReversals()

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

returns whether arc reversals are allowed in the thin phase of greedy thick-thinning

Definition at line 383 of file IBNLearner_inl.h.

383 {
385 }
bool allowReversalsInThinPhase() const
returns whether arc reversals are allowed in the thin phase

References gum::learning::GreedyThickThinning::allowReversalsInThinPhase(), and greedyThickThinning_.

Here is the call 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 498 of file IBNLearner_inl.h.

498 {
500 }
bool hasMissingValues() const
indicates whether the database contains some missing values

References gum::learning::IBNLearner::Database::databaseTable(), gum::learning::IDatabaseTable< T_DATA >::hasMissingValues(), and scoreDatabase_.

Referenced by rawPseudoCount().

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

◆ history()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 995 of file IBNLearner_inl.h.

995 {
996 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->history();
997 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
998 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::history().

Referenced by createPrior_().

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

◆ idFromName()

INLINE NodeId gum::learning::IBNLearner::idFromName ( std::string_view 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 137 of file IBNLearner_inl.h.

137 {
138 return scoreDatabase_.idFromName(var_name);
139 }
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name

References gum::learning::IBNLearner::Database::idFromName(), and scoreDatabase_.

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

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

◆ initialDAG()

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

returns the initial DAG structure

Definition at line 167 of file IBNLearner_inl.h.

167{ return initialDag_; }

References initialDag_.

◆ isConstraintBased()

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

indicate if the selected algorithm is constraint-based

Definition at line 796 of file IBNLearner_inl.h.

References EXTENDED_GREEDY_HILL_CLIMBING, FCI, GREEDY_HILL_CLIMBING, GREEDY_THICK_THINNING, K2, LOCAL_SEARCH_WITH_TABU_LIST, MIIC, PC, and selectedAlgo_.

Referenced by checkScorePriorCompatibility(), and isScoreBased().

Here is the caller graph for this function:

◆ isCSVFileName_()

void gum::learning::IBNLearner::isCSVFileName_ ( std::string_view filename)
staticprotected

checks whether the extension of a CSV filename is correct

Definition at line 474 of file IBNLearner.cpp.

474 {
475 // get the extension of the file
476
477 if (auto filename_size = Size(filename.size()); filename_size < 4) {
478 GUM_ERROR(FormatNotFound,
479 "IBNLearner could not determine the "
480 "file type of the database")
481 }
482
483 std::string extension(filename.substr(filename.size() - 4));
484 std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
485
486 if (extension != ".csv") {
487 GUM_ERROR(OperationNotAllowed, "IBNLearner does not support yet this type of database file")
488 }
489 }

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()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 857 of file IBNLearner_inl.h.

857 {
858 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledEpsilon();
859 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
860 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::isEnabledEpsilon().

Referenced by createPrior_().

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

◆ isEnabledMaxIter()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 919 of file IBNLearner_inl.h.

919 {
920 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxIter();
921 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
922 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::isEnabledMaxIter().

Referenced by createPrior_().

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

◆ isEnabledMaxTime()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 955 of file IBNLearner_inl.h.

955 {
956 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxTime();
957 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
958 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::isEnabledMaxTime().

Referenced by createPrior_().

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

◆ isEnabledMinEpsilonRate()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 888 of file IBNLearner_inl.h.

888 {
890 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
891 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::isEnabledMinEpsilonRate().

Referenced by createPrior_().

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

◆ isGumNumberOfThreadsOverriden()

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

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

Implements gum::IThreadNumberManager.

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

Here is the caller graph for this function:

◆ isScoreBased()

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

indicate if the selected algorithm is score-based

Definition at line 810 of file IBNLearner_inl.h.

810{ return !isConstraintBased(); }

References isConstraintBased().

Here is the call graph for this function:

◆ isUsingEM()

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

indicates whether we use EM for parameter learning

Definition at line 464 of file IBNLearner_inl.h.

464{ 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 346 of file IBNLearner_inl.h.

346 {
347 return algoMiic_.latentVariables();
348 }
const std::vector< Arc > latentVariables() const

References algoMiic_, and gum::learning::ConstraintBasedLearning::latentVariables().

Here is the call graph for this function:

◆ learnDAG()

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

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

Definition at line 986 of file IBNLearner.cpp.

986 {
987 createPrior_();
988 createScore_();
989 auto dag = learnDag_();
990 for (const auto i: dag) {
991 dag.setName(i, scoreDatabase_.databaseTable().variableName(i));
992 }
993 return dag;
994 }
DAG learnDag_()
returns the DAG learnt
void createScore_()
create the score used for learning
const std::string & variableName(const std::size_t k) const
returns the name of the kth column of the IDatabaseTable

References createPrior_(), createScore_(), gum::learning::IBNLearner::Database::databaseTable(), learnDag_(), scoreDatabase_, and gum::learning::IDatabaseTable< T_DATA >::variableName().

Here is the call graph for this function:

◆ learnDag_()

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

returns the DAG learnt

Definition at line 1015 of file IBNLearner.cpp.

1015 {
1016 // check that the database does not contain any missing value
1018 || ((priorDatabase_ != nullptr)
1021 GUM_ERROR(MissingValueInDatabase,
1022 "For the moment, the BNLearner is unable to cope "
1023 "with missing values in databases")
1024 }
1025 // add the mandatory arcs to the initial dag and remove the forbidden ones
1026 // from the initial graph
1027 DAG init_graph = initialDag_;
1028
1029 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
1030 if (!init_graph.exists(arc.tail())) init_graph.addNodeWithId(arc.tail());
1031
1032 if (!init_graph.exists(arc.head())) init_graph.addNodeWithId(arc.head());
1033
1034 init_graph.addArc(arc.tail(), arc.head());
1035 }
1036
1037 for (const auto& arc: constraintForbiddenArcs_.arcs())
1038 init_graph.eraseArc(arc);
1039
1040
1041 switch (selectedAlgo_) {
1042 // ========================================================================
1043 case AlgoType::PC : {
1044 BNLearnerListener listener(this, algoPC_);
1045 MixedGraph mgraph = this->preparePC_();
1046 return algoPC_.learnDAG(mgraph);
1047 }
1048
1049 // ========================================================================
1050 case AlgoType::FCI : {
1051 BNLearnerListener listener(this, algoFCI_);
1052 MixedGraph mgraph = this->prepareFCI_();
1053 return algoFCI_.learnDAG(mgraph);
1054 }
1055
1056 // ========================================================================
1057 case AlgoType::MIIC : {
1058 BNLearnerListener listener(this, algoMiic_);
1059 // create the mixedGraph and the corrected mutual information
1060 MixedGraph mgraph = this->prepareMiic_();
1061
1063 return algoMiic_.learnDAG(mgraph);
1064 }
1065
1066 // ========================================================================
1068 BNLearnerListener listener(this, greedyHillClimbing_);
1069 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1070 StructuralConstraintForbiddenArcs,
1071 StructuralConstraintPossibleEdges,
1072 StructuralConstraintSliceOrder,
1073 StructuralConstraintNoParentNodes,
1074 StructuralConstraintNoChildrenNodes,
1075 StructuralConstraintTotalOrder >
1076 invariable_constraints;
1077 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1079 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1081 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1083 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1085 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1087 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1089 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1091
1092 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1093 variable_constraints;
1094 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1095
1096 GraphChangesSelector4DiGraph selector(*score_,
1097 invariable_constraints,
1098 variable_constraints);
1099
1100 // enforce that greedy hill climbing uses arc additions, deletions and reversals
1101 // and only these operations
1102 selector.useArcAdditions(true);
1103 selector.useArcDeletions(true);
1104 selector.useArcReversals(true);
1105 selector.useArcTriangleDeletions(false);
1106
1107 return greedyHillClimbing_.learnStructure(selector, init_graph);
1108 }
1109
1110 // ========================================================================
1112 BNLearnerListener listener(this, extendedGreedyHillClimbing_);
1113 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1114 StructuralConstraintForbiddenArcs,
1115 StructuralConstraintPossibleEdges,
1116 StructuralConstraintNoParentNodes,
1117 StructuralConstraintNoChildrenNodes,
1118 StructuralConstraintSliceOrder,
1119 StructuralConstraintTotalOrder >
1120 invariable_constraints;
1121 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1123 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1125 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1127 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1129 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1131 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1133 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1135
1136 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1137 variable_constraints;
1138 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1139
1140 GraphChangesSelector4DiGraph selector(*score_,
1141 invariable_constraints,
1142 variable_constraints);
1143
1144 selector.useArcAdditions(allowArcAdditions_);
1145 selector.useArcDeletions(allowArcDeletions_);
1146 selector.useArcReversals(allowArcReversals_);
1147 selector.useArcTriangleDeletions(allowArcTriangleDeletions_);
1148
1149 return greedyHillClimbing_.learnStructure(selector, init_graph);
1150 }
1151
1152 // ========================================================================
1154 BNLearnerListener listener(this, greedyThickThinning_);
1155 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1156 StructuralConstraintForbiddenArcs,
1157 StructuralConstraintPossibleEdges,
1158 StructuralConstraintSliceOrder,
1159 StructuralConstraintNoParentNodes,
1160 StructuralConstraintNoChildrenNodes,
1161 StructuralConstraintTotalOrder >
1162 invariable_constraints;
1163 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1165 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1167 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1169 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1171 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1173 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1175 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1177
1178 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1179 variable_constraints;
1180 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1181
1182 GraphChangesSelector4DiGraph selector(*score_,
1183 invariable_constraints,
1184 variable_constraints);
1185
1186 return greedyThickThinning_.learnStructure(selector, init_graph);
1187 }
1188
1189 // ========================================================================
1191 BNLearnerListener listener(this, localSearchWithTabuList_);
1192 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1193 StructuralConstraintForbiddenArcs,
1194 StructuralConstraintPossibleEdges,
1195 StructuralConstraintSliceOrder,
1196 StructuralConstraintNoParentNodes,
1197 StructuralConstraintNoChildrenNodes,
1198 StructuralConstraintTotalOrder >
1199 invariable_constraints;
1200 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1202 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1204 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1206 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1208 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1210 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1212 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1214
1215 StructuralConstraintSetStatic< StructuralConstraintTabuList,
1216 StructuralConstraintIndegree,
1217 StructuralConstraintDAG >
1218 variable_constraints;
1219 static_cast< StructuralConstraintTabuList& >(variable_constraints) = constraintTabuList_;
1220 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1221
1222 GraphChangesSelector4DiGraph selector(*score_,
1223 invariable_constraints,
1224 variable_constraints);
1225
1226 selector.useArcAdditions(allowArcAdditions_);
1227 selector.useArcDeletions(allowArcDeletions_);
1228 selector.useArcReversals(allowArcReversals_);
1229 selector.useArcTriangleDeletions(allowArcTriangleDeletions_);
1230
1231 return localSearchWithTabuList_.learnStructure(selector, init_graph);
1232 }
1233
1234 // ========================================================================
1235 case AlgoType::K2 : {
1236 BNLearnerListener listener(this, algoK2_.approximationScheme());
1237 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1238 StructuralConstraintForbiddenArcs,
1239 StructuralConstraintPossibleEdges,
1240 StructuralConstraintNoParentNodes,
1241 StructuralConstraintNoChildrenNodes,
1242 StructuralConstraintTotalOrder >
1243 invariable_constraints;
1244 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1246 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1248 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1250 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1252 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1254 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1256
1257 // if some mandatory arcs are incompatible with the order, use a DAG
1258 // constraint instead of a DiGraph constraint to avoid cycles
1259 const ArcSet& mandatory_arcs
1260 = static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints).arcs();
1261 const Sequence< NodeId >& order = algoK2_.order();
1262 bool order_compatible = true;
1263
1264 for (const auto& arc: mandatory_arcs) {
1265 if (order.pos(arc.tail()) >= order.pos(arc.head())) {
1266 order_compatible = false;
1267 break;
1268 }
1269 }
1270
1271 if (order_compatible) {
1272 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDiGraph >
1273 variable_constraints;
1274 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1275
1276 GraphChangesSelector4DiGraph selector(*score_,
1277 invariable_constraints,
1278 variable_constraints);
1279
1280 return algoK2_.learnStructure(selector, init_graph);
1281 } else {
1282 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1283 variable_constraints;
1284 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1285
1286 GraphChangesSelector4DiGraph selector(*score_,
1287 invariable_constraints,
1288 variable_constraints);
1289
1290 return algoK2_.learnStructure(selector, init_graph);
1291 }
1292 }
1293 }
1294
1295 GUM_ERROR(OperationNotAllowed,
1296 "the learnDAG method has not been implemented for this "
1297 "learning algorithm")
1298 }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
DAG learnDAG(MixedGraph graph)
learns a DAG
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
MixedGraph preparePC_()
prepares the initial graph and independence test for PC
gum::learning::FCI algoFCI_
the FCI algorithm
StructuralConstraintTotalOrder constraintTotalOrder_
the total order ing constraint
MixedGraph prepareFCI_()
prepares the initial graph and independence test for FCI
gum::learning::PC algoPC_
the PC algorithm
MixedGraph prepareMiic_()
prepares the initial graph for miic
const Sequence< NodeId > & order() const noexcept
returns the current order
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Definition K2_tpl.h:63
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
void setMutualInformation(CorrectedMutualInformation &mi)
Definition Miic.cpp:89
const ArcSet & arcs() const
returns the set of mandatory arcs
const ArcSet & arcs() const
returns the set of mandatory arcs
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...

References gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), algoFCI_, algoK2_, algoMiic_, algoPC_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, gum::learning::K2::approximationScheme(), gum::learning::StructuralConstraintForbiddenArcs::arcs(), gum::learning::StructuralConstraintMandatoryArcs::arcs(), constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTabuList_, constraintTotalOrder_, gum::learning::IBNLearner::Database::databaseTable(), DIRICHLET_FROM_DATABASE, gum::ArcGraphPart::eraseArc(), gum::NodeGraphPart::exists(), EXTENDED_GREEDY_HILL_CLIMBING, extendedGreedyHillClimbing_, FCI, GREEDY_HILL_CLIMBING, GREEDY_THICK_THINNING, greedyHillClimbing_, greedyThickThinning_, GUM_ERROR, gum::learning::IDatabaseTable< T_DATA >::hasMissingValues(), initialDag_, K2, gum::learning::ConstraintBasedLearning::learnDAG(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::GreedyThickThinning::learnStructure(), gum::learning::K2::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), LOCAL_SEARCH_WITH_TABU_LIST, localSearchWithTabuList_, MIIC, mutualInfo_, gum::learning::K2::order(), PC, gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::pos(), prepareFCI_(), prepareMiic_(), preparePC_(), priorDatabase_, priorType_, score_, scoreDatabase_, selectedAlgo_, gum::learning::Miic::setMutualInformation(), gum::learning::GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE >::useArcAdditions(), gum::learning::GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE >::useArcDeletions(), gum::learning::GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE >::useArcReversals(), and gum::learning::GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE >::useArcTriangleDeletions().

Referenced by createPrior_(), and learnDAG().

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

◆ learnPAG()

PAG gum::learning::IBNLearner::learnPAG ( )

learn a PAG — only valid when useFCI() has been called

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 978 of file IBNLearner.cpp.

978 {
979 auto pag = learnPAG_();
980 for (const auto i: pag) {
981 pag.setName(i, scoreDatabase_.databaseTable().variableName(i));
982 }
983 return pag;
984 }

References gum::learning::IBNLearner::Database::databaseTable(), learnPAG_(), scoreDatabase_, and gum::learning::IDatabaseTable< T_DATA >::variableName().

Here is the call graph for this function:

◆ learnPAG_()

PAG gum::learning::IBNLearner::learnPAG_ ( )
protected

Definition at line 964 of file IBNLearner.cpp.

964 {
966 GUM_ERROR(OperationNotAllowed, "learnPAG() is only valid when using the FCI algorithm")
967 }
969 GUM_ERROR(MissingValueInDatabase,
970 "For the moment, the BNLearner is unable to learn "
971 << "structures with missing values in databases")
972 }
973 BNLearnerListener listener(this, algoFCI_);
974 MixedGraph mgraph = this->prepareFCI_();
975 return algoFCI_.learnPAG(mgraph);
976 }
PAG learnPAG(MixedGraph graph)
primary FCI output: learn a PAG from the given node-only or partial graph
Definition FCI.cpp:818

References algoFCI_, gum::learning::IBNLearner::Database::databaseTable(), FCI, GUM_ERROR, gum::learning::IDatabaseTable< T_DATA >::hasMissingValues(), gum::learning::FCI::learnPAG(), prepareFCI_(), scoreDatabase_, and selectedAlgo_.

Referenced by learnPAG().

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 956 of file IBNLearner.cpp.

956 {
957 auto pdag = learnPDAG_();
958 for (const auto i: pdag) {
959 pdag.setName(i, scoreDatabase_.databaseTable().variableName(i));
960 }
961 return pdag;
962 }

References gum::learning::IBNLearner::Database::databaseTable(), learnPDAG_(), scoreDatabase_, and gum::learning::IDatabaseTable< T_DATA >::variableName().

Here is the call graph for this function:

◆ learnPDAG_()

PDAG gum::learning::IBNLearner::learnPDAG_ ( )
protected

Definition at line 923 of file IBNLearner.cpp.

923 {
926 GUM_ERROR(OperationNotAllowed,
927 "Score-based algorithms do not build PDAG. Please use a constraint-based "
928 "algorithm instead")
929 }
930 // check that the database does not contain any missing value
932 GUM_ERROR(MissingValueInDatabase,
933 "For the moment, the BNLearner is unable to learn "
934 << "structures with missing values in databases")
935 }
936
938 BNLearnerListener listener(this, algoPC_);
939 MixedGraph mgraph = this->preparePC_();
940 return algoPC_.learnPDAG(mgraph);
941 }
942
944 BNLearnerListener listener(this, algoFCI_);
945 MixedGraph mgraph = this->prepareFCI_();
946 return algoFCI_.learnPDAG(mgraph);
947 }
948
949 BNLearnerListener listener(this, algoMiic_);
950 // create the mixedGraph_constraint_MandatoryArcs.arcs
951 MixedGraph mgraph = this->prepareMiic_();
953 return algoMiic_.learnPDAG(mgraph);
954 }
PDAG learnPDAG(MixedGraph graph)
learns the essential graph (CPDAG)

References algoFCI_, algoMiic_, algoPC_, gum::learning::IBNLearner::Database::databaseTable(), FCI, GUM_ERROR, gum::learning::IDatabaseTable< T_DATA >::hasMissingValues(), gum::learning::ConstraintBasedLearning::learnPDAG(), MIIC, mutualInfo_, PC, prepareFCI_(), prepareMiic_(), preparePC_(), scoreDatabase_, selectedAlgo_, and gum::learning::Miic::setMutualInformation().

Referenced by learnPDAG().

Here is the call graph for this function:
Here is the caller 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 1404 of file IBNLearner.cpp.

1405 {
1406 createPrior_();
1407 gum::learning::ScoreLog2Likelihood ll2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1408
1409 std::vector< NodeId > total(vars);
1410 total.insert(total.end(), knowing.begin(), knowing.end());
1411 double LLtotal = ll2score.score(IdCondSet(total, false, true));
1412 if (knowing.size() == (Size)0) {
1413 return LLtotal;
1414 } else {
1415 double LLknw = ll2score.score(IdCondSet(knowing, false, true));
1416 return LLtotal - LLknw;
1417 }
1418 }
IdCondSet()
default constructor

References gum::learning::IdCondSet::IdCondSet(), createPrior_(), databaseRanges(), gum::learning::IBNLearner::Database::parser(), 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 1420 of file IBNLearner.cpp.

1421 {
1422 std::vector< NodeId > ids;
1423 std::vector< NodeId > knowingIds;
1424
1425 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1426
1427 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1428 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1429
1430 return logLikelihood(ids, knowingIds);
1431 }
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()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 900 of file IBNLearner_inl.h.

900 {
901 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxIter();
902 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
903 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::maxIter().

Referenced by createPrior_().

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

◆ maxTime()

INLINE double gum::learning::IBNLearner::maxTime ( ) const
overridevirtual

returns the timeout (in seconds)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 931 of file IBNLearner_inl.h.

931 {
932 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxTime();
933 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
934 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::maxTime().

Referenced by createPrior_().

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

◆ messageApproximationScheme()

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

Returns the approximation scheme message.

Returns
Returns the approximation scheme message.

Definition at line 64 of file IApproximationSchemeConfiguration.cpp.

64 {
65 switch (stateApproximationScheme()) {
66 case ApproximationSchemeSTATE::Continue : return "in progress";
67
69 return std::format("stopped with epsilon={}", epsilon());
70
72 return std::format("stopped with rate={}", minEpsilonRate());
73
75 return std::format("stopped with max iteration={}", maxIter());
76
78 return std::format("stopped with timeout={}", maxTime());
79
80 case ApproximationSchemeSTATE::Stopped : return "stopped on request";
81
82 case ApproximationSchemeSTATE::Undefined : return "undefined state";
83 }
84 return {};
85 }
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::ApproximationScheme::continueApproximationScheme(), gum::learning::IBNLearner::EMStateMessage(), and gum::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg().

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

◆ minEpsilonRate()

INLINE double gum::learning::IBNLearner::minEpsilonRate ( ) const
overridevirtual

Get the value of the minimal epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 869 of file IBNLearner_inl.h.

869 {
870 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->minEpsilonRate();
871 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
872 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::minEpsilonRate().

Referenced by createPrior_().

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

◆ mutualInformation() [1/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 1470 of file IBNLearner.cpp.

1472 {
1474 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(), prior, databaseRanges());
1475 cmi.useNoCorr();
1476
1477 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1478 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1479 }

References gum::learning::NoPrior::NoPrior(), databaseRanges(), gum::learning::IBNLearner::Database::databaseTable(), gum::learning::IBNLearner::Database::nodeId2Columns(), gum::learning::IBNLearner::Database::parser(), gum::learning::CorrectedMutualInformation::score(), scoreDatabase_, gum::learning::CorrectedMutualInformation::useNoCorr(), and gum::learning::IBNLearner::Database::weight().

Referenced by mutualInformation().

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

◆ mutualInformation() [2/2]

double gum::learning::IBNLearner::mutualInformation ( std::string_view var1,
std::string_view 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 1481 of file IBNLearner.cpp.

1483 {
1484 std::vector< NodeId > knowingIds;
1485
1486 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1487
1488 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1489
1490 return mutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1491 }
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:

◆ 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 142 of file IBNLearner_inl.h.

142 {
143 return scoreDatabase_.nameFromId(id);
144 }
const std::string & nameFromId(NodeId id) const
returns the variable name corresponding to a given node id

References gum::learning::IBNLearner::Database::nameFromId(), and scoreDatabase_.

Here is the call graph for this function:

◆ names()

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

returns the names of the variables in the database

Definition at line 751 of file IBNLearner_inl.h.

751 {
752 return scoreDatabase_.names();
753 }
const std::vector< std::string > & names() const
returns the names of the variables in the database

References gum::learning::IBNLearner::Database::names(), and scoreDatabase_.

Here is the call graph for this function:

◆ nbCols()

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

Definition at line 782 of file IBNLearner_inl.h.

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

References gum::learning::IBNLearner::Database::domainSizes(), and scoreDatabase_.

Here is the call graph for this function:

◆ nbrIterations()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 990 of file IBNLearner_inl.h.

990 {
991 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->nbrIterations();
992 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
993 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::nbrIterations().

Referenced by createPrior_().

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

◆ nbRows()

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

Definition at line 784 of file IBNLearner_inl.h.

784{ return scoreDatabase_.databaseTable().size(); }
std::size_t size() const noexcept
returns the number of records (rows) in the database

References gum::learning::IBNLearner::Database::databaseTable(), scoreDatabase_, and gum::learning::IDatabaseTable< T_DATA >::size().

Here is the call graph for this function:

◆ operator=() [1/2]

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

copy operator

Definition at line 297 of file IBNLearner.cpp.

297 {
298 if (this != &from) {
299 if (score_) {
300 delete score_;
301 score_ = nullptr;
302 }
303
304 if (prior_) {
305 delete prior_;
306 prior_ = nullptr;
307 }
308
309 if (priorDatabase_) {
310 delete priorDatabase_;
311 priorDatabase_ = nullptr;
312 }
313
314 if (mutualInfo_) {
315 delete mutualInfo_;
316 mutualInfo_ = nullptr;
317 }
318
320 scoreType_ = from.scoreType_;
321 paramEstimatorType_ = from.paramEstimatorType_;
322 useEM_ = from.useEM_;
323 priorType_ = from.priorType_;
324 priorWeight_ = from.priorWeight_;
325 constraintSliceOrder_ = from.constraintSliceOrder_;
326 constraintIndegree_ = from.constraintIndegree_;
327 constraintTabuList_ = from.constraintTabuList_;
328 constraintForbiddenArcs_ = from.constraintForbiddenArcs_;
329 constraintNoParentNodes_ = from.constraintNoParentNodes_;
330 constraintNoChildrenNodes_ = from.constraintNoChildrenNodes_;
331 constraintMandatoryArcs_ = from.constraintMandatoryArcs_;
332 selectedAlgo_ = from.selectedAlgo_;
333 allowArcAdditions_ = from.allowArcAdditions_;
334 allowArcDeletions_ = from.allowArcDeletions_;
335 allowArcReversals_ = from.allowArcReversals_;
336 allowArcTriangleDeletions_ = from.allowArcTriangleDeletions_;
337 algoK2_ = from.algoK2_;
338 algoMiic_ = from.algoMiic_;
339 kmodeMiic_ = from.kmodeMiic_;
340 indepTestTypePC_ = from.indepTestTypePC_;
341 alphaPc_ = from.alphaPc_;
342 stablePc_ = from.stablePc_;
343 maxCondSetSizePc_ = from.maxCondSetSizePc_;
344 sortedUCPc_ = from.sortedUCPc_;
345 indepTestTypeFCI_ = from.indepTestTypeFCI_;
346 alphaFci_ = from.alphaFci_;
347 maxPathLengthFci_ = from.maxPathLengthFci_;
348 exhaustiveSepSetFci_ = from.exhaustiveSepSetFci_;
349 dag2BN_ = from.dag2BN_;
350 greedyHillClimbing_ = from.greedyHillClimbing_;
351 extendedGreedyHillClimbing_ = from.extendedGreedyHillClimbing_;
352 greedyThickThinning_ = from.greedyThickThinning_;
353 localSearchWithTabuList_ = from.localSearchWithTabuList_;
354 scoreDatabase_ = from.scoreDatabase_;
355 ranges_ = from.ranges_;
356 priorDbname_ = from.priorDbname_;
357 initialDag_ = from.initialDag_;
358 filename_ = from.filename_;
359 tabuListSize_ = from.tabuListSize_;
360 nbDecreasingChanges_ = from.nbDecreasingChanges_;
361 currentAlgorithm_ = nullptr;
362 }
363
364 return *this;
365 }
ThreadNumberManager & operator=(const ThreadNumberManager &from)
copy operator

References IBNLearner(), algoK2_, algoMiic_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, alphaFci_, alphaPc_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, currentAlgorithm_, dag2BN_, exhaustiveSepSetFci_, extendedGreedyHillClimbing_, filename_, greedyHillClimbing_, greedyThickThinning_, indepTestTypeFCI_, indepTestTypePC_, initialDag_, kmodeMiic_, localSearchWithTabuList_, maxCondSetSizePc_, maxPathLengthFci_, mutualInfo_, nbDecreasingChanges_, gum::ThreadNumberManager::operator=(), paramEstimatorType_, prior_, priorDatabase_, priorDbname_, priorType_, priorWeight_, ranges_, score_, scoreDatabase_, scoreType_, selectedAlgo_, sortedUCPc_, stablePc_, tabuListSize_, 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 367 of file IBNLearner.cpp.

367 {
368 if (this != &from) {
369 if (score_) {
370 delete score_;
371 score_ = nullptr;
372 }
373
374 if (prior_) {
375 delete prior_;
376 prior_ = nullptr;
377 }
378
379 if (priorDatabase_) {
380 delete priorDatabase_;
381 priorDatabase_ = nullptr;
382 }
383
384 if (mutualInfo_) {
385 delete mutualInfo_;
386 mutualInfo_ = nullptr;
387 }
388
389 ThreadNumberManager::operator=(std::move(from));
390 scoreType_ = from.scoreType_;
391 paramEstimatorType_ = from.paramEstimatorType_;
392 useEM_ = from.useEM_;
393 priorType_ = from.priorType_;
394 priorWeight_ = from.priorWeight_;
395 constraintSliceOrder_ = std::move(from.constraintSliceOrder_);
396 constraintIndegree_ = std::move(from.constraintIndegree_);
397 constraintTabuList_ = std::move(from.constraintTabuList_);
398 constraintForbiddenArcs_ = std::move(from.constraintForbiddenArcs_);
399 constraintNoParentNodes_ = std::move(from.constraintNoParentNodes_);
400 constraintNoChildrenNodes_ = std::move(from.constraintNoChildrenNodes_);
401 constraintMandatoryArcs_ = std::move(from.constraintMandatoryArcs_);
402 selectedAlgo_ = from.selectedAlgo_;
403 allowArcAdditions_ = from.allowArcAdditions_;
404 allowArcDeletions_ = from.allowArcDeletions_;
405 allowArcReversals_ = from.allowArcReversals_;
406 allowArcTriangleDeletions_ = from.allowArcTriangleDeletions_;
407 algoK2_ = from.algoK2_;
408 algoMiic_ = std::move(from.algoMiic_);
409 kmodeMiic_ = from.kmodeMiic_;
410 indepTestTypePC_ = from.indepTestTypePC_;
411 alphaPc_ = from.alphaPc_;
412 stablePc_ = from.stablePc_;
413 maxCondSetSizePc_ = from.maxCondSetSizePc_;
414 sortedUCPc_ = from.sortedUCPc_;
415 indepTestTypeFCI_ = from.indepTestTypeFCI_;
416 alphaFci_ = from.alphaFci_;
417 maxPathLengthFci_ = from.maxPathLengthFci_;
418 exhaustiveSepSetFci_ = from.exhaustiveSepSetFci_;
419 dag2BN_ = std::move(from.dag2BN_);
420 greedyHillClimbing_ = std::move(from.greedyHillClimbing_);
421 extendedGreedyHillClimbing_ = std::move(from.extendedGreedyHillClimbing_);
422 greedyThickThinning_ = std::move(from.greedyThickThinning_);
423 localSearchWithTabuList_ = std::move(from.localSearchWithTabuList_);
424 scoreDatabase_ = std::move(from.scoreDatabase_);
425 ranges_ = std::move(from.ranges_);
426 priorDbname_ = std::move(from.priorDbname_);
427 filename_ = std::move(from.filename_);
428 initialDag_ = std::move(from.initialDag_);
429 tabuListSize_ = from.tabuListSize_;
430 nbDecreasingChanges_ = std::move(from.nbDecreasingChanges_);
431 currentAlgorithm_ = nullptr;
432 }
433
434 return *this;
435 }

References IBNLearner(), algoK2_, algoMiic_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, alphaFci_, alphaPc_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, currentAlgorithm_, dag2BN_, exhaustiveSepSetFci_, extendedGreedyHillClimbing_, filename_, greedyHillClimbing_, greedyThickThinning_, indepTestTypeFCI_, indepTestTypePC_, initialDag_, kmodeMiic_, localSearchWithTabuList_, maxCondSetSizePc_, maxPathLengthFci_, mutualInfo_, nbDecreasingChanges_, gum::ThreadNumberManager::operator=(), paramEstimatorType_, prior_, priorDatabase_, priorDbname_, priorType_, priorWeight_, ranges_, score_, scoreDatabase_, scoreType_, selectedAlgo_, sortedUCPc_, stablePc_, tabuListSize_, and useEM_.

Here is the call graph for this function:

◆ periodSize()

INLINE Size gum::learning::IBNLearner::periodSize ( ) const
overridevirtual

how many samples between 2 stopping isEnableds

Exceptions
OutOfBoundsif p<1

Implements gum::IApproximationSchemeConfiguration.

Definition at line 967 of file IBNLearner_inl.h.

967 {
968 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->periodSize();
969 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
970 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::periodSize().

Referenced by createPrior_().

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

◆ preferredAlgo()

IBNLearner::AlgoType gum::learning::IBNLearner::preferredAlgo ( )
static

the algorithm used by the learners when none is selected explicitly

It is read from the configuration key "learning" / "BNLearnerPreferredAlgo". A learner takes it when it is constructed and does not follow later changes of the configuration. K2 cannot be the preferred algorithm since it requires an order.

Exceptions
InvalidArgumentif the configured name is not a known algorithm

Definition at line 910 of file IBNLearner.cpp.

910 {
911 const auto name = gum::config().typed< std::string >("learning", "BNLearnerPreferredAlgo");
912 if (name == "MIIC") return AlgoType::MIIC;
913 if (name == "PC") return AlgoType::PC;
914 if (name == "FCI") return AlgoType::FCI;
915 if (name == "GreedyHillClimbing") return AlgoType::GREEDY_HILL_CLIMBING;
916 if (name == "ExtendedGreedyHillClimbing") return AlgoType::EXTENDED_GREEDY_HILL_CLIMBING;
917 if (name == "LocalSearchWithTabuList") return AlgoType::LOCAL_SEARCH_WITH_TABU_LIST;
918 if (name == "GreedyThickThinning") return AlgoType::GREEDY_THICK_THINNING;
919 GUM_ERROR(InvalidArgument,
920 "'" << name << "' is not a valid value for learning.BNLearnerPreferredAlgo")
921 }
T typed(std::string_view section, std::string_view key) const
Value of section.key converted according to its declared type.
Configuration & config()
A short name for Configuration::instance() : gum::config().epsilonStandard(). It is not inline so tha...

References gum::config(), EXTENDED_GREEDY_HILL_CLIMBING, FCI, GREEDY_HILL_CLIMBING, GREEDY_THICK_THINNING, GUM_ERROR, LOCAL_SEARCH_WITH_TABU_LIST, MIIC, PC, and gum::Configuration::typed().

Here is the call graph for this function:

◆ prepareFCI_()

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

prepares the initial graph and independence test for FCI

Definition at line 820 of file IBNLearner.cpp.

820 {
821 MixedGraph mgraph;
822 DiGraph forbiddenGraph;
823 DAG mandatoryGraph;
824
825 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
826 mgraph.addNodeWithId(i);
827 forbiddenGraph.addNodeWithId(i);
828 mandatoryGraph.addNodeWithId(i);
829 }
830
831 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
832 if (possible_edges.empty()) {
833 for (const NodeId i: mgraph.nodes()) {
834 for (NodeId j = 0; j < i; ++j) {
835 mgraph.addEdge(j, i);
836 }
837 }
838 } else {
839 for (const auto& edge: possible_edges) {
840 mgraph.addEdge(edge.first(), edge.second());
841 }
842 }
843
844 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
845 mandatoryGraph.addArc(arc.tail(), arc.head());
846 forbiddenGraph.addArc(arc.head(), arc.tail());
847 }
848 for (const auto& arc: constraintForbiddenArcs_.arcs()) {
849 forbiddenGraph.addArc(arc.tail(), arc.head());
850 }
851
853 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
854 for (const auto& [n1, r1]: sliceOrder) {
855 for (const auto& [n2, r2]: copyOrder) {
856 if (r1 > r2) {
857 forbiddenGraph.addArc(n1, n2);
858 } else if (r2 > r1) {
859 forbiddenGraph.addArc(n2, n1);
860 }
861 }
862 copyOrder.erase(n1);
863 }
864
865 const auto& totalOrder = constraintTotalOrder_.totalOrder();
866 for (auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
867 for (auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
868 forbiddenGraph.addArc(*iter2, *iter1);
869 }
870 }
871
872 for (const auto node: constraintNoParentNodes_.nodes()) {
873 for (const auto node2: mgraph.nodes()) {
874 if (node != node2) { forbiddenGraph.addArc(node2, node); }
875 }
876 }
877 for (const auto node: constraintNoChildrenNodes_.nodes()) {
878 for (const auto node2: mgraph.nodes()) {
879 if (node != node2) { forbiddenGraph.addArc(node, node2); }
880 }
881 }
882
883 if (indepTestFCI_) {
884 delete indepTestFCI_;
885 indepTestFCI_ = nullptr;
886 }
889 *noPrior_,
890 ranges_,
892 } else {
894 *noPrior_,
895 ranges_,
897 }
898
900 algoFCI_.setMandatoryGraph(mandatoryGraph);
901 algoFCI_.setForbiddenGraph(forbiddenGraph);
906
907 return mgraph;
908 }
void setAlpha(double alpha)
maximum conditioning set size; Size(-1) = unlimited (default)
void setIndependenceTest(IndependenceTest &test)
inject independence test (non-owning: caller manages lifetime)
void setExhaustiveSepSet(bool exhaustive)
exhaustive sepset mode: accumulate union of all separating sets found at each depth,...
void setMandatoryGraph(const gum::DAG &mandaGraph)
void setForbiddenGraph(const gum::DiGraph &forbidGraph)
void setMaxPathLength(Size maxLen)
maximum path length for R4 discriminating-path search; Size(-1) = unlimited
Definition FCI.cpp:82
IndepTestChi2(const DBRowGeneratorParser &parser, const Prior &external_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
IndepTestG2(const DBRowGeneratorParser &parser, const Prior &external_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
Size maxIndegree() const
sets the default max indegree for all the nodes in the property
const NodeSet & nodes() const
returns the set of w nodes without children
const NodeSet & nodes() const
returns the set of nodes without parent
const EdgeSet & edges() const
returns the set of mandatory arcs
const NodeProperty< NodeId > & sliceOrder() const
returns the current slice order
const Sequence< NodeId > & totalOrder() const
returns the current Total order
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::learning::IndepTestChi2::IndepTestChi2(), gum::learning::IndepTestG2::IndepTestG2(), gum::DAG::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoFCI_, alphaFci_, gum::learning::StructuralConstraintForbiddenArcs::arcs(), gum::learning::StructuralConstraintMandatoryArcs::arcs(), Chi2, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTotalOrder_, gum::learning::IBNLearner::Database::databaseTable(), gum::learning::StructuralConstraintPossibleEdges::edges(), gum::Set< Key >::empty(), exhaustiveSepSetFci_, indepTestFCI_, indepTestTypeFCI_, gum::learning::StructuralConstraintIndegree::maxIndegree(), maxPathLengthFci_, gum::learning::IBNLearner::Database::nodeId2Columns(), gum::learning::StructuralConstraintNoChildrenNodes::nodes(), gum::learning::StructuralConstraintNoParentNodes::nodes(), gum::NodeGraphPart::nodes(), noPrior_, gum::learning::IBNLearner::Database::parser(), ranges_, scoreDatabase_, gum::learning::CIBasedLearning::setAlpha(), gum::learning::CIBasedLearning::setExhaustiveSepSet(), gum::learning::ConstraintBasedLearning::setForbiddenGraph(), gum::learning::CIBasedLearning::setIndependenceTest(), gum::learning::ConstraintBasedLearning::setMandatoryGraph(), gum::learning::ConstraintBasedLearning::setMaxIndegree(), gum::learning::FCI::setMaxPathLength(), gum::learning::StructuralConstraintSliceOrder::sliceOrder(), and gum::learning::StructuralConstraintTotalOrder::totalOrder().

Referenced by createPrior_(), learnDag_(), learnPAG_(), and learnPDAG_().

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

◆ prepareMiic_()

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

prepares the initial graph for miic

Definition at line 628 of file IBNLearner.cpp.

628 {
629 // Initialize the mixed graph to the fully connected graph
630 MixedGraph mgraph;
631 DiGraph forbiddenGraph;
632 DAG mandatoryGraph;
633
634 // GUM_CHECKPOINT
635 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
636 mgraph.addNodeWithId(i);
637 forbiddenGraph.addNodeWithId(i);
638 mandatoryGraph.addNodeWithId(i);
639 }
640
641 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
642
643 if (possible_edges.empty()) {
644 for (const NodeId i: mgraph.nodes()) {
645 for (NodeId j = 0; j < i; ++j) {
646 // contiguous nodeIds !
647 mgraph.addEdge(j, i);
648 }
649 }
650 } else {
651 for (const auto& edge: possible_edges) {
652 mgraph.addEdge(edge.first(), edge.second());
653 }
654 }
655 // GUM_CHECKPOINT
656
657 // translating the mandatory arcs for constraintMiic
658 HashTable< std::pair< NodeId, NodeId >, char > initial_marks;
659 const ArcSet& mandatory_arcs = constraintMandatoryArcs_.arcs();
660
661 // GUM_CHECKPOINT
662 for (const auto& arc: mandatory_arcs) {
663 mandatoryGraph.addArc(arc.tail(), arc.head());
664 // MIIC's marks mechanism (orientationMiic_) handles the reverse direction;
665 // adding it to forbiddenGraph would cause DuplicateElement (unlike preparePC_).
666 }
667
668 // GUM_CHECKPOINT
669 // translating the forbidden arcs for constraintMiic
670 const ArcSet& forbidden_arcs = constraintForbiddenArcs_.arcs();
671 for (const auto& arc: forbidden_arcs) {
672 forbiddenGraph.addArc(arc.tail(), arc.head());
673 }
674
675 // GUM_CHECKPOINT
677 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
678 for (const auto& [n1, r1]: sliceOrder) {
679 for (const auto& [n2, r2]: copyOrder) {
680 if (r1 > r2) {
681 forbiddenGraph.addArc(n1, n2);
682 // initial_marks.insert({n1, n2}, '-');
683 } else if (r2 > r1) {
684 forbiddenGraph.addArc(n2, n1);
685 // initial_marks.insert({n2, n1}, '-');
686 }
687 }
688 copyOrder.erase(n1);
689 }
690
691 // GUM_CHECKPOINT
692 const auto& totalOrder = constraintTotalOrder_.totalOrder();
693 for (auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
694 const auto node1 = *iter1;
695 for (auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
696 forbiddenGraph.addArc(*iter2, node1);
697 }
698 }
699
700 for (const auto node: constraintNoParentNodes_.nodes()) {
701 for (const auto node2: mgraph.nodes()) {
702 if (node != node2) { forbiddenGraph.addArc(node2, node); }
703 }
704 }
705
706 for (const auto node: constraintNoChildrenNodes_.nodes()) {
707 for (const auto node2: mgraph.nodes()) {
708 if (node != node2) { forbiddenGraph.addArc(node, node2); }
709 }
710 }
711
712 // GUM_CHECKPOINT
714 algoMiic_.addConstraints(initial_marks);
715 algoMiic_.setMandatoryGraph(mandatoryGraph);
716 algoMiic_.setForbiddenGraph(forbiddenGraph);
717
718 // GUM_CHECKPOINT
719 // create the mutual entropy object
720 // if ( _mutual_info_ == nullptr) { this->useNMLCorrection(); }
722
723 // GUM_CHECKPOINT
724 return mgraph;
725 }
void addConstraints(const HashTable< std::pair< NodeId, NodeId >, char > &constraints)
void createCorrectedMutualInformation_()
create the Corrected Mutual Information instance for Miic

References gum::DAG::addArc(), gum::DiGraph::addArc(), gum::learning::ConstraintBasedLearning::addConstraints(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoMiic_, gum::learning::StructuralConstraintForbiddenArcs::arcs(), gum::learning::StructuralConstraintMandatoryArcs::arcs(), constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTotalOrder_, createCorrectedMutualInformation_(), gum::learning::IBNLearner::Database::databaseTable(), gum::learning::StructuralConstraintPossibleEdges::edges(), gum::Set< Key >::empty(), gum::learning::StructuralConstraintIndegree::maxIndegree(), gum::learning::StructuralConstraintNoChildrenNodes::nodes(), gum::learning::StructuralConstraintNoParentNodes::nodes(), gum::NodeGraphPart::nodes(), scoreDatabase_, gum::learning::ConstraintBasedLearning::setForbiddenGraph(), gum::learning::ConstraintBasedLearning::setMandatoryGraph(), gum::learning::ConstraintBasedLearning::setMaxIndegree(), gum::learning::StructuralConstraintSliceOrder::sliceOrder(), and gum::learning::StructuralConstraintTotalOrder::totalOrder().

Referenced by createPrior_(), learnDag_(), and learnPDAG_().

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

◆ preparePC_()

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

prepares the initial graph and independence test for PC

Definition at line 727 of file IBNLearner.cpp.

727 {
728 MixedGraph mgraph;
729 DiGraph forbiddenGraph;
730 DAG mandatoryGraph;
731
732 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
733 mgraph.addNodeWithId(i);
734 forbiddenGraph.addNodeWithId(i);
735 mandatoryGraph.addNodeWithId(i);
736 }
737
738 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
739 if (possible_edges.empty()) {
740 for (const NodeId i: mgraph.nodes()) {
741 for (NodeId j = 0; j < i; ++j) {
742 mgraph.addEdge(j, i);
743 }
744 }
745 } else {
746 for (const auto& edge: possible_edges) {
747 mgraph.addEdge(edge.first(), edge.second());
748 }
749 }
750
751 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
752 mandatoryGraph.addArc(arc.tail(), arc.head());
753 forbiddenGraph.addArc(arc.head(), arc.tail());
754 }
755 for (const auto& arc: constraintForbiddenArcs_.arcs()) {
756 forbiddenGraph.addArc(arc.tail(), arc.head());
757 }
758
760 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
761 for (const auto& [n1, r1]: sliceOrder) {
762 for (const auto& [n2, r2]: copyOrder) {
763 if (r1 > r2) {
764 forbiddenGraph.addArc(n1, n2);
765 } else if (r2 > r1) {
766 forbiddenGraph.addArc(n2, n1);
767 }
768 }
769 copyOrder.erase(n1);
770 }
771
772 const auto& totalOrder = constraintTotalOrder_.totalOrder();
773 for (auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
774 for (auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
775 forbiddenGraph.addArc(*iter2, *iter1);
776 }
777 }
778
779 for (const auto node: constraintNoParentNodes_.nodes()) {
780 for (const auto node2: mgraph.nodes()) {
781 if (node != node2) { forbiddenGraph.addArc(node2, node); }
782 }
783 }
784 for (const auto node: constraintNoChildrenNodes_.nodes()) {
785 for (const auto node2: mgraph.nodes()) {
786 if (node != node2) { forbiddenGraph.addArc(node, node2); }
787 }
788 }
789
790 // build the independence test (owned by IBNLearner)
791 if (indepTestPC_) {
792 delete indepTestPC_;
793 indepTestPC_ = nullptr;
794 }
797 *noPrior_,
798 ranges_,
800 } else {
802 *noPrior_,
803 ranges_,
805 }
806
808 algoPC_.setMandatoryGraph(mandatoryGraph);
809 algoPC_.setForbiddenGraph(forbiddenGraph);
816
817 return mgraph;
818 }
void setUCPriority(UCPriority p)
collider candidate ordering (default: Standard)
@ Sorted
descending p-value order (strongest evidence first)
@ Standard
process triples in natural traversal order
void setMaxCondSetSize(Size max_k)
maximum conditioning set size; Size(-1) = unlimited (default)
void setStable(bool stable)
stable mode: defer edge removals until end of each depth (default: true)

References gum::learning::IndepTestChi2::IndepTestChi2(), gum::learning::IndepTestG2::IndepTestG2(), gum::DAG::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoPC_, alphaPc_, gum::learning::StructuralConstraintForbiddenArcs::arcs(), gum::learning::StructuralConstraintMandatoryArcs::arcs(), Chi2, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTotalOrder_, gum::learning::IBNLearner::Database::databaseTable(), gum::learning::StructuralConstraintPossibleEdges::edges(), gum::Set< Key >::empty(), indepTestPC_, indepTestTypePC_, maxCondSetSizePc_, gum::learning::StructuralConstraintIndegree::maxIndegree(), gum::learning::IBNLearner::Database::nodeId2Columns(), gum::learning::StructuralConstraintNoChildrenNodes::nodes(), gum::learning::StructuralConstraintNoParentNodes::nodes(), gum::NodeGraphPart::nodes(), noPrior_, gum::learning::IBNLearner::Database::parser(), ranges_, scoreDatabase_, gum::learning::CIBasedLearning::setAlpha(), gum::learning::ConstraintBasedLearning::setForbiddenGraph(), gum::learning::CIBasedLearning::setIndependenceTest(), gum::learning::ConstraintBasedLearning::setMandatoryGraph(), gum::learning::CIBasedLearning::setMaxCondSetSize(), gum::learning::ConstraintBasedLearning::setMaxIndegree(), gum::learning::CIBasedLearning::setStable(), gum::learning::CIBasedLearning::setUCPriority(), gum::learning::StructuralConstraintSliceOrder::sliceOrder(), gum::learning::CIBasedLearning::Sorted, sortedUCPc_, stablePc_, gum::learning::CIBasedLearning::Standard, and gum::learning::StructuralConstraintTotalOrder::totalOrder().

Referenced by createPrior_(), learnDag_(), and learnPDAG_().

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

◆ 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 std::vector<double> containing the contingency table

Definition at line 1511 of file IBNLearner.cpp.

1511 {
1512 if (this->hasMissingValues()) {
1513 GUM_ERROR(MissingValueInDatabase,
1514 "BNLearner cannot compute pseudo-counts with missing values in the database")
1515 }
1516 if (vars.empty()) {
1517 GUM_ERROR(OutOfBounds, "BNLearner::rawPseudoCount called with an empty vector of variables")
1518 }
1519 Tensor< double > res;
1520
1521 createPrior_();
1522 gum::learning::PseudoCount count(scoreDatabase_.parser(), *prior_, databaseRanges());
1523 return count.get(vars);
1524 }
bool hasMissingValues() const
returns true if the learner's database has missing values
template class GUM_SHARED_PUBLIC Tensor< double >
Definition tensor.cpp:53

References createPrior_(), databaseRanges(), gum::learning::PseudoCount::get(), GUM_ERROR, hasMissingValues(), gum::learning::IBNLearner::Database::parser(), prior_, scoreDatabase_, and gum::Tensor< double >.

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 1526 of file IBNLearner.cpp.

1526 {
1527 std::vector< NodeId > ids;
1528
1529 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1530
1531 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1532 return rawPseudoCount(ids);
1533 }
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_ ( std::string_view filename,
const std::vector< std::string > & missing_symbols )
staticprotected

reads a file and returns a databaseVectInRam

Definition at line 491 of file IBNLearner.cpp.

492 {
493 // get the extension of the file
494 isCSVFileName_(filename);
495
496 DBInitializerFromCSV initializer{std::string(filename)};
497
498 const auto& var_names = initializer.variableNames();
499 const std::size_t nb_vars = var_names.size();
500
501 DBTranslatorSet translator_set;
502 DBTranslator4LabelizedVariable translator(missing_symbols);
503 for (std::size_t i = 0; i < nb_vars; ++i) {
504 translator_set.insertTranslator(translator, i);
505 }
506
507 DatabaseTable database(missing_symbols, translator_set);
508 database.setVariableNames(initializer.variableNames());
509 initializer.fillDatabase(database);
510
512
513 return database;
514 }
void setVariableNames(const std::vector< std::string > &names, const bool from_external_object=true) override
sets the names of the variables
void reorder(const std::size_t k, const bool k_is_input_col=false)
performs a reordering of the kth translator or of the first translator parsing the kth column of the ...
static void isCSVFileName_(std::string_view 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_(), gum::learning::DatabaseTable::reorder(), gum::learning::DatabaseTable::setVariableNames(), 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 157 of file IBNLearner_inl.h.

157 {
158 return scoreDatabase_.weight(i);
159 }

References scoreDatabase_, and gum::learning::IBNLearner::Database::weight().

Here is the call graph for this function:

◆ score() [1/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 1493 of file IBNLearner.cpp.

1493 {
1494 createPrior_();
1495 createScore_();
1496
1497 return score_->score(var, knowing);
1498 }
double score(const NodeId var)
returns the score of a single node

References createPrior_(), createScore_(), gum::learning::Score::score(), and score_.

Referenced by score(), and useDatabaseRanges().

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

◆ score() [2/2]

double gum::learning::IBNLearner::score ( std::string_view 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 1500 of file IBNLearner.cpp.

1500 {
1501 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1502
1503 const NodeId id = this->idFromName(var);
1504 std::vector< NodeId > knowingIds;
1505 knowingIds.reserve(knowing.size());
1506 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1507
1508 return score(id, knowingIds);
1509 }
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:

◆ setCurrentApproximationScheme()

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

{@ /// distribute signals

Definition at line 813 of file IBNLearner_inl.h.

813 {
814 currentAlgorithm_ = approximationScheme;
815 }

References currentAlgorithm_.

Referenced by gum::learning::BNLearnerListener::BNLearnerListener(), createPrior_(), 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 147 of file IBNLearner_inl.h.

147 {
149 }
void setDatabaseWeight(const double new_weight)
assign a weight to all the rows of the database so that the sum of their weights is equal to new_weig...

References scoreDatabase_, and gum::learning::IBNLearner::Database::setDatabaseWeight().

Here is the call graph for this function:

◆ setEpsilon()

INLINE void gum::learning::IBNLearner::setEpsilon ( double eps)
overridevirtual

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 831 of file IBNLearner_inl.h.

831 {
835 dag2BN_.setEpsilon(eps);
836 }
void setEpsilon(double eps) override
Given that we approximate f(t), stopping criterion on |f(t+1)-f(t)|.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, gum::ApproximationScheme::setEpsilon(), and gum::learning::EMApproximationScheme::setEpsilon().

Referenced by createPrior_().

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

◆ setFCIAlpha()

INLINE void gum::learning::IBNLearner::setFCIAlpha ( double alpha)

set the significance threshold alpha for FCI. If it is never set, FCI uses the key learning.alpha of the configuration, as it was when the learner was constructed.

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 248 of file IBNLearner_inl.h.

248 {
250 GUM_ERROR(OperationNotAllowed, "setFCIAlpha() is only valid when using the FCI algorithm")
251 }
252 alphaFci_ = alpha;
253 }

References alphaFci_, FCI, GUM_ERROR, and selectedAlgo_.

◆ setFCIExhaustiveSepSet()

INLINE void gum::learning::IBNLearner::setFCIExhaustiveSepSet ( bool exhaustive)

enable exhaustive sepset mode for FCI skeleton learning (default false)

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 264 of file IBNLearner_inl.h.

264 {
266 GUM_ERROR(OperationNotAllowed,
267 "setFCIExhaustiveSepSet() is only valid when using the FCI algorithm")
268 }
269 exhaustiveSepSetFci_ = exhaustive;
270 }

References exhaustiveSepSetFci_, FCI, GUM_ERROR, and selectedAlgo_.

◆ setFCIMaxPathLength()

INLINE void gum::learning::IBNLearner::setFCIMaxPathLength ( Size max_len)

set maximum discriminating-path length for FCI R4 (default Size(-1) = unlimited)

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 256 of file IBNLearner_inl.h.

256 {
258 GUM_ERROR(OperationNotAllowed,
259 "setFCIMaxPathLength() is only valid when using the FCI algorithm")
260 }
261 maxPathLengthFci_ = max_len;
262 }

References FCI, GUM_ERROR, maxPathLengthFci_, and selectedAlgo_.

◆ setForbiddenArcs()

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

removes a total

assign a set of forbidden arcs

Definition at line 543 of file IBNLearner_inl.h.

543 {
545 }
void setArcs(const ArcSet &set)
assign a set of forbidden arcs

References constraintForbiddenArcs_, and gum::learning::StructuralConstraintForbiddenArcs::setArcs().

Here is the call graph for this function:

◆ setGreedyThickThinningReversals()

INLINE void gum::learning::IBNLearner::setGreedyThickThinningReversals ( bool allow)

enable or disable arc reversals in the thin phase of greedy thick-thinning

Definition at line 378 of file IBNLearner_inl.h.

378 {
380 }
void setAllowReversalsInThinPhase(bool allow)
enable or disable arc reversals during the thin phase (default: false)

References greedyThickThinning_, and gum::learning::GreedyThickThinning::setAllowReversalsInThinPhase().

Here is the call graph for this function:

◆ setInitialDAG()

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

sets an initial DAG structure

Definition at line 165 of file IBNLearner_inl.h.

165{ initialDag_ = dag; }

References initialDag_.

◆ setMandatoryArcs()

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

assign a set of mandatory arcs

Definition at line 576 of file IBNLearner_inl.h.

576 {
578 }
void setArcs(const ArcSet &set)
assign a set of forbidden arcs

References constraintMandatoryArcs_, and gum::learning::StructuralConstraintMandatoryArcs::setArcs().

Here is the call graph for this function:

◆ setMaxIndegree()

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

sets the max indegree

Definition at line 218 of file IBNLearner_inl.h.

218 {
220 }
void setMaxIndegree(Size max_indegree, bool update_all_node=false)
resets the default max indegree and possibly updates the indegree of all nodes

References constraintIndegree_, and gum::learning::StructuralConstraintIndegree::setMaxIndegree().

Here is the call graph for this function:

◆ setMaxIter()

INLINE void gum::learning::IBNLearner::setMaxIter ( Size max)
overridevirtual

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 893 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, and gum::ApproximationScheme::setMaxIter().

Referenced by createPrior_().

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

◆ setMaxTime()

INLINE void gum::learning::IBNLearner::setMaxTime ( double timeout)
overridevirtual

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 924 of file IBNLearner_inl.h.

924 {
928 dag2BN_.setMaxTime(timeout);
929 }

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, and gum::ApproximationScheme::setMaxTime().

Referenced by createPrior_().

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

◆ setMinEpsilonRate()

INLINE void gum::learning::IBNLearner::setMinEpsilonRate ( double rate)
overridevirtual

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 862 of file IBNLearner_inl.h.

862 {
867 }
void setMinEpsilonRate(double rate) override
Given that we approximate f(t), stopping criterion on d/dt(|f(t+1)-f(t)|).

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, gum::ApproximationScheme::setMinEpsilonRate(), and gum::learning::EMApproximationScheme::setMinEpsilonRate().

Referenced by createPrior_().

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

◆ 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

Implements gum::IThreadNumberManager.

Definition at line 787 of file IBNLearner_inl.h.

787 {
789 if (score_ != nullptr) score_->setNumberOfThreads(nb);
790 }
void setNumberOfThreads(Size nb) override
sets the number max of threads to be used by the class containing this ThreadNumberManager

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

Here is the call graph for this function:

◆ setPCAlpha()

INLINE void gum::learning::IBNLearner::setPCAlpha ( double alpha)

set the significance threshold alpha for PC. If it is never set, PC uses the key learning.alpha of the configuration, as it was when the learner was constructed.

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 297 of file IBNLearner_inl.h.

297 {
299 GUM_ERROR(OperationNotAllowed, "setPCAlpha() is only valid when using the PC algorithm")
300 }
301 alphaPc_ = alpha;
302 }

References alphaPc_, GUM_ERROR, PC, and selectedAlgo_.

◆ setPCMaxCondSetSize()

INLINE void gum::learning::IBNLearner::setPCMaxCondSetSize ( Size max_k)

set maximum conditioning set size for PC (default Size(-1) = unlimited)

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 313 of file IBNLearner_inl.h.

313 {
315 GUM_ERROR(OperationNotAllowed,
316 "setPCMaxCondSetSize() is only valid when using the PC algorithm")
317 }
318 maxCondSetSizePc_ = max_k;
319 }

References GUM_ERROR, maxCondSetSizePc_, PC, and selectedAlgo_.

◆ setPCStable()

INLINE void gum::learning::IBNLearner::setPCStable ( bool stable)

set stable mode for PC — defer removals to end of each depth level (default true)

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 305 of file IBNLearner_inl.h.

305 {
307 GUM_ERROR(OperationNotAllowed, "setPCStable() is only valid when using the PC algorithm")
308 }
309 stablePc_ = stable;
310 }

References GUM_ERROR, PC, selectedAlgo_, and stablePc_.

◆ setPCUnshieldedColliderSorted()

INLINE void gum::learning::IBNLearner::setPCUnshieldedColliderSorted ( bool sorted)

set unshielded-collider ordering for PC: sorted=true uses descending p-value order (strongest evidence first); sorted=false uses natural traversal order (default false)

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 322 of file IBNLearner_inl.h.

322 {
324 GUM_ERROR(OperationNotAllowed,
325 "setPCUnshieldedColliderSorted() is only valid when using the PC algorithm")
326 }
327 sortedUCPc_ = sorted;
328 }

References GUM_ERROR, PC, selectedAlgo_, and sortedUCPc_.

◆ setPeriodSize()

INLINE void gum::learning::IBNLearner::setPeriodSize ( Size p)
overridevirtual

how many samples between 2 stopping isEnableds

Exceptions
OutOfBoundsif p<1

Implements gum::IApproximationSchemeConfiguration.

Definition at line 960 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, and gum::ApproximationScheme::setPeriodSize().

Referenced by createPrior_().

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

◆ 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 503 of file IBNLearner_inl.h.

503 {
505 }
void setEdges(const EdgeSet &set)
assign a set of forbidden arcs

References constraintPossibleEdges_, and gum::learning::StructuralConstraintPossibleEdges::setEdges().

Referenced by setPossibleSkeleton().

Here is the call graph for this function:
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 508 of file IBNLearner_inl.h.

508 {
509 setPossibleEdges(g.edges());
510 }
void setPossibleEdges(const EdgeSet &set)
assign a set of possible edges

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

Here is the call 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 152 of file IBNLearner_inl.h.

152 {
153 scoreDatabase_.setWeight(i, new_weight);
154 }
void setWeight(const std::size_t i, const double weight)
sets the weight of the ith record

References scoreDatabase_, and gum::learning::IBNLearner::Database::setWeight().

Here is the call graph for this function:

◆ 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 639 of file IBNLearner_inl.h.

References gum::learning::StructuralConstraintSliceOrder::StructuralConstraintSliceOrder(), and constraintSliceOrder_.

Referenced by setSliceOrder(), and unsetSliceOrder().

Here is the call graph for this function:
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. If it is empty, this is equivalent to removing the constraint (useful if you had previously added a slice order constraint and you do not want to use it anymore)

Definition at line 643 of file IBNLearner_inl.h.

643 {
644 NodeProperty< NodeId > slice_order;
645 NodeId rank = 0;
646 for (const auto& slice: slices) {
647 for (const auto& name: slice) {
648 slice_order.insert(idFromName(name), rank);
649 }
650 rank++;
651 }
652 setSliceOrder(slice_order);
653 }
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:

◆ setTotalOrder() [1/2]

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

sets a total order over some nodes

This defines a total ordering constraint on the nodes belonging to the sequence. If you plan to use K2, do not use this constraint, prefer using method useK2(order).

Note that all the nodes of the graph to be learned need not belong to order: if a node does not belong to it, then it just means that there is no constraint on this node in the total ordering.

Note also that you can both exploit a total ordering and slice ordering. For instance, we may wish that the topological ordering of the graph we learn satisfies that 1 < 3 < 4 < 5 and 2 < 3, 4 and 5, then use a total ordering 1 < 3 < 4 < 5 combined with a slice ordering {2} < {3,4,5}.

Parameters
order

Definition at line 658 of file IBNLearner_inl.h.

References gum::learning::StructuralConstraintTotalOrder::StructuralConstraintTotalOrder(), and constraintTotalOrder_.

Referenced by setTotalOrder(), and unsetTotalOrder().

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

◆ setTotalOrder() [2/2]

INLINE void gum::learning::IBNLearner::setTotalOrder ( const std::vector< std::string > & order)

sets the max indegree

Definition at line 663 of file IBNLearner_inl.h.

663 {
664 Sequence< NodeId > sequence;
665 for (const auto& name: order) {
666 sequence.insert(idFromName(name));
667 }
668 setTotalOrder(sequence);
669 }
void setTotalOrder(const Sequence< NodeId > &order)
sets a total order over some nodes

References idFromName(), gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::insert(), and setTotalOrder().

Here is the call graph for this function:

◆ setVerbosity()

INLINE void gum::learning::IBNLearner::setVerbosity ( bool v)
overridevirtual

verbosity

Implements gum::IApproximationSchemeConfiguration.

Definition at line 972 of file IBNLearner_inl.h.

References algoK2_, gum::learning::K2::approximationScheme(), dag2BN_, greedyHillClimbing_, localSearchWithTabuList_, and gum::ApproximationScheme::setVerbosity().

Referenced by createPrior_().

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

◆ stateApproximationScheme()

INLINE IApproximationSchemeConfiguration::ApproximationSchemeSTATE gum::learning::IBNLearner::stateApproximationScheme ( ) const
overridevirtual

history

Implements gum::IApproximationSchemeConfiguration.

Definition at line 985 of file IBNLearner_inl.h.

985 {
987 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
988 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::stateApproximationScheme().

Referenced by createPrior_().

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

◆ unsetSliceOrder()

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

removes the slice order constraint

The methd is useful if you had previously added a slice order constraint and you do not want to use it anymore

Definition at line 655 of file IBNLearner_inl.h.

References setSliceOrder().

Here is the call graph for this function:

◆ unsetTotalOrder()

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

removes the current total ordering constraint, if any

Definition at line 672 of file IBNLearner_inl.h.

672{ setTotalOrder(Sequence< NodeId >()); }

References setTotalOrder().

Here is the call graph for this function:

◆ useBDeuPrior() [1/2]

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

use the BDeu prior with the default weight (key priorWeight of the section learning)

Definition at line 720 of file IBNLearner_inl.h.

720 {
721 useBDeuPrior(gum::config().typed< double >("learning", "priorWeight"));
722 }
void useBDeuPrior(double weight)
use the BDeu prior

References gum::config(), and useBDeuPrior().

Here is the call graph for this function:

◆ useBDeuPrior() [2/2]

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

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 725 of file IBNLearner_inl.h.

725 {
726 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
727
729 _setPriorWeight_(weight);
730
732 }
void _setPriorWeight_(double weight)
sets the prior weight

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

Referenced by useBDeuPrior().

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

◆ useChi2Test()

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

indicate that we wish to use Chi2 independence test for PC

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 281 of file IBNLearner_inl.h.

281 {
283 GUM_ERROR(OperationNotAllowed, "useChi2Test() is only valid when using the PC algorithm")
284 }
286 }

References Chi2, GUM_ERROR, indepTestTypePC_, PC, and selectedAlgo_.

◆ 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 1329 of file IBNLearner.cpp.

1330 {
1331 if (k_fold == 0) { GUM_ERROR(OutOfBounds, "K-fold cross validation with k=0 is forbidden") }
1332
1333 if (learning_fold >= k_fold) {
1334 GUM_ERROR(OutOfBounds,
1335 "In " << k_fold << "-fold cross validation, the learning "
1336 << "fold should be strictly lower than " << k_fold
1337 << " but, here, it is equal to " << learning_fold)
1338 }
1339
1340 const std::size_t db_size = scoreDatabase_.databaseTable().nbRows();
1341 if (k_fold >= db_size) {
1342 GUM_ERROR(OutOfBounds,
1343 "In " << k_fold << "-fold cross validation, the database's "
1344 << "size should be strictly greater than " << k_fold
1345 << " but, here, the database has only " << db_size << "rows")
1346 }
1347
1348 // create the ranges of rows of the test database
1349 const std::size_t foldSize = db_size / k_fold;
1350 const std::size_t unfold_deb = learning_fold * foldSize;
1351 const std::size_t unfold_end = unfold_deb + foldSize;
1352
1353 ranges_.clear();
1354 if (learning_fold == std::size_t(0)) {
1355 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1356 } else {
1357 ranges_.push_back(std::pair< std::size_t, std::size_t >(std::size_t(0), unfold_deb));
1358
1359 if (learning_fold != k_fold - 1) {
1360 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1361 }
1362 }
1363
1364 return std::pair< std::size_t, std::size_t >(unfold_deb, unfold_end);
1365 }
std::size_t nbRows() const noexcept
returns the number of records (rows) in the database

References gum::learning::IBNLearner::Database::databaseTable(), GUM_ERROR, gum::learning::IDatabaseTable< T_DATA >::nbRows(), ranges_, and scoreDatabase_.

Here is the call graph for this function:

◆ 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 1536 of file IBNLearner.cpp.

1537 {
1538 // use a score to detect whether the ranges are ok
1539 ScoreLog2Likelihood score(scoreDatabase_.parser(), *noPrior_);
1540 score.setRanges(new_ranges);
1541 ranges_ = score.ranges();
1542 }

References noPrior_, gum::learning::IBNLearner::Database::parser(), gum::learning::Score::ranges(), ranges_, score(), scoreDatabase_, and gum::learning::Score::setRanges().

Here is the call graph for this function:

◆ useDirichletPrior() [1/2]

INLINE void gum::learning::IBNLearner::useDirichletPrior ( std::string_view filename)

use the Dirichlet prior from a database with the default weight (key priorWeight)

Definition at line 704 of file IBNLearner_inl.h.

704 {
705 useDirichletPrior(filename, gum::config().typed< double >("learning", "priorWeight"));
706 }
void useDirichletPrior(std::string_view filename, double weight)
use the Dirichlet prior from a database

References gum::config(), and useDirichletPrior().

Here is the call graph for this function:

◆ useDirichletPrior() [2/2]

INLINE void gum::learning::IBNLearner::useDirichletPrior ( std::string_view filename,
double weight )

use the Dirichlet prior from a database

Definition at line 709 of file IBNLearner_inl.h.

709 {
710 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
711
712 priorDbname_ = filename;
714 _setPriorWeight_(weight);
715
717 }

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

Referenced by useDirichletPrior().

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

◆ useEM() [1/2]

INLINE void gum::learning::IBNLearner::useEM ( const double epsilon)

use The EM algorithm to learn parameters, with the default noise

use The EM algorithm to learn parameters with the default noise

Parameters
epsilonsets the approximation stopping criterion (see useEM(epsilon, noise))
See also
the key emNoise of the section learning of gum::Configuration, which gives the noise
Exceptions
OutOfBoundsis raised if epsilon is strictly negative.

Definition at line 411 of file IBNLearner_inl.h.

411 {
412 useEM(epsilon, gum::config().typed< double >("learning", "emNoise"));
413 }
void useEM(const double epsilon, const double noise)
use The EM algorithm to learn parameters
double epsilon() const override
Get the value of epsilon.

References gum::config(), epsilon(), and useEM().

Here is the call graph for this function:

◆ useEM() [2/2]

INLINE void gum::learning::IBNLearner::useEM ( const double epsilon,
const double 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 416 of file IBNLearner_inl.h.

416 {
417 if (epsilon < 0.0)
418 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be non-negative");
419 if ((noise < 0.0) || (noise > 1.0))
420 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
421 if (epsilon > 0) {
422 useEM_ = true;
424 dag2BN_.setNoise(noise);
425 } else {
426 useEM_ = false; // epsilon == 0
427 }
428 }
DAG2BNLearner & setNoise(const double noise)
sets the noise amount used to perturb the initial CPTs used by EM

References dag2BN_, epsilon(), GUM_ERROR, gum::learning::EMApproximationScheme::setMinEpsilonRate(), gum::learning::DAG2BNLearner::setNoise(), and useEM_.

Referenced by useEM(), and useEMWithRateCriterion().

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

◆ useEMWithDiffCriterion() [1/2]

INLINE void gum::learning::IBNLearner::useEMWithDiffCriterion ( const double epsilon)

use The EM algorithm with the diff stopping criterion and the default noise (key emNoise)

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

Definition at line 445 of file IBNLearner_inl.h.

445 {
446 useEMWithDiffCriterion(epsilon, gum::config().typed< double >("learning", "emNoise"));
447 }
void useEMWithDiffCriterion(const double epsilon, const double noise)
use The EM algorithm to learn parameters with the diff stopping criterion

References gum::config(), epsilon(), and useEMWithDiffCriterion().

Here is the call graph for this function:

◆ useEMWithDiffCriterion() [2/2]

INLINE void gum::learning::IBNLearner::useEMWithDiffCriterion ( const double epsilon,
const double 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 450 of file IBNLearner_inl.h.

450 {
451 if (epsilon <= 0.0)
452 GUM_ERROR(OutOfBounds, "EM's min log-likelihood differences must be positive");
453 if ((noise < 0.0) || (noise > 1.0))
454 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
455 useEM_ = true;
457 dag2BN_.setNoise(noise);
458 }

References dag2BN_, epsilon(), GUM_ERROR, gum::learning::EMApproximationScheme::setEpsilon(), gum::learning::DAG2BNLearner::setNoise(), and useEM_.

Referenced by useEMWithDiffCriterion().

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

◆ useEMWithRateCriterion() [1/2]

INLINE void gum::learning::IBNLearner::useEMWithRateCriterion ( const double epsilon)

use The EM algorithm with the rate stopping criterion and the default noise (key emNoise)

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

Definition at line 432 of file IBNLearner_inl.h.

432 {
433 useEMWithRateCriterion(epsilon, gum::config().typed< double >("learning", "emNoise"));
434 }
void useEMWithRateCriterion(const double epsilon, const double noise)
use The EM algorithm to learn parameters with the rate stopping criterion

References gum::config(), epsilon(), and useEMWithRateCriterion().

Here is the call graph for this function:

◆ useEMWithRateCriterion() [2/2]

INLINE void gum::learning::IBNLearner::useEMWithRateCriterion ( const double epsilon,
const double 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 437 of file IBNLearner_inl.h.

437 {
438 if (epsilon <= 0.0)
439 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be positive");
440 useEM(epsilon, noise);
441 }

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

Referenced by useEMWithRateCriterion().

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

◆ useExtendedGreedyHillClimbing()

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

indicate that we wish to use the extended greedy hill climbing algorithm

The extended greedy hill climbing adds to the classical operations (arc addition, arc reversal, arc deletion) two additional operations: arc triangle deletion1 and arc triangle deletion2. The former modifies a structure X1->X2->X3 + X1->X3 into a v-structure centered on X1, i.e., X2->X1<-X3. Arc triangle deletion2 modifies structure X1->X2->X3 + X1->X3 into a v-structure centered on X2, i.e., X1->X2<-X3.

In addition, the extended greedy hill climbing allows the user to select which operations among arc additions, arc reversals, arc deletions, arc triangle deletions, are allowed.

Definition at line 368 of file IBNLearner_inl.h.

References EXTENDED_GREEDY_HILL_CLIMBING, and selectedAlgo_.

◆ useFCI()

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

indicate that we wish to use FCI (Chi2 test by default)

Definition at line 229 of file IBNLearner_inl.h.

References FCI, and selectedAlgo_.

◆ useFCIChi2Test()

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

indicate that we wish to use Chi2 independence test for FCI

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 232 of file IBNLearner_inl.h.

232 {
234 GUM_ERROR(OperationNotAllowed, "useFCIChi2Test() is only valid when using the FCI algorithm")
235 }
237 }

References Chi2, FCI, GUM_ERROR, indepTestTypeFCI_, and selectedAlgo_.

◆ useFCIG2Test()

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

indicate that we wish to use G2 independence test for FCI

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 240 of file IBNLearner_inl.h.

240 {
242 GUM_ERROR(OperationNotAllowed, "useFCIG2Test() is only valid when using the FCI algorithm")
243 }
245 }

References FCI, G2, GUM_ERROR, indepTestTypeFCI_, and selectedAlgo_.

◆ useG2Test()

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

indicate that we wish to use G2 independence test for PC

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 289 of file IBNLearner_inl.h.

289 {
291 GUM_ERROR(OperationNotAllowed, "useG2Test() is only valid when using the PC algorithm")
292 }
294 }

References G2, GUM_ERROR, indepTestTypePC_, PC, and selectedAlgo_.

◆ useGreedyHillClimbing()

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

indicate that we wish to use a greedy hill climbing algorithm

Definition at line 363 of file IBNLearner_inl.h.

References GREEDY_HILL_CLIMBING, and selectedAlgo_.

◆ useGreedyThickThinning()

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

indicate that we wish to use greedy thick-thinning

Definition at line 373 of file IBNLearner_inl.h.

References GREEDY_THICK_THINNING, and selectedAlgo_.

◆ useK2() [1/2]

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

indicate that we wish to use K2

Definition at line 351 of file IBNLearner_inl.h.

351 {
353 algoK2_.setOrder(order);
354 }
void setOrder(const Sequence< NodeId > &order)
sets the order on the variables

References algoK2_, K2, selectedAlgo_, and gum::learning::K2::setOrder().

Here is the call 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 357 of file IBNLearner_inl.h.

357 {
359 algoK2_.setOrder(order);
360 }

References algoK2_, K2, selectedAlgo_, and gum::learning::K2::setOrder().

Here is the call graph for this function:

◆ useLocalSearchWithTabuList() [1/3]

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

indicate that we wish to use a local search with tabu list and the default parameters

The size of the tabu list and the max number of consecutive decreasing changes are given by the keys tabuListSize and tabuNbDecrease of the section learning of gum::Configuration

Definition at line 388 of file IBNLearner_inl.h.

388 {
390 static_cast< Size >(gum::config().typed< std::int64_t >("learning", "tabuListSize")),
391 static_cast< Size >(gum::config().typed< std::int64_t >("learning", "tabuNbDecrease")));
392 }
void useLocalSearchWithTabuList(Size tabu_size, Size nb_decrease)
indicate that we wish to use a local search with tabu list

References gum::config(), and useLocalSearchWithTabuList().

Here is the call graph for this function:

◆ useLocalSearchWithTabuList() [2/3]

INLINE void gum::learning::IBNLearner::useLocalSearchWithTabuList ( Size tabu_size)

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

Parameters
tabu_sizeindicate the size of the tabu list The max number of consecutive decreasing changes is the default one (key tabuNbDecrease of the section learning of gum::Configuration)

Definition at line 395 of file IBNLearner_inl.h.

395 {
397 tabu_size,
398 static_cast< Size >(gum::config().typed< std::int64_t >("learning", "tabuNbDecrease")));
399 }

References gum::config(), and useLocalSearchWithTabuList().

Here is the call graph for this function:

◆ useLocalSearchWithTabuList() [3/3]

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

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 402 of file IBNLearner_inl.h.

402 {
404 tabuListSize_ = tabu_size;
405 nbDecreasingChanges_ = nb_decrease;
408 }
void setMaxNbDecreasingChanges(Size nb)
set the max number of changes decreasing the score that we allow to apply
void setTabuListSize(Size new_size)
sets the size of the tabu list

References constraintTabuList_, LOCAL_SEARCH_WITH_TABU_LIST, localSearchWithTabuList_, nbDecreasingChanges_, selectedAlgo_, gum::learning::LocalSearchWithTabuList::setMaxNbDecreasingChanges(), gum::learning::StructuralConstraintTabuList::setTabuListSize(), and tabuListSize_.

Referenced by useLocalSearchWithTabuList(), and useLocalSearchWithTabuList().

Here is the call graph for this function:
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 336 of file IBNLearner_inl.h.

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

◆ useMIIC()

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

indicate that we wish to use MIIC

Definition at line 223 of file IBNLearner_inl.h.

References MIIC, and selectedAlgo_.

◆ 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 331 of file IBNLearner_inl.h.

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

◆ 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 341 of file IBNLearner_inl.h.

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

◆ useNoPrior()

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

use no prior

Definition at line 683 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), NO_prior, and priorType_.

Here is the call graph for this function:

◆ usePC()

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

indicate that we wish to use PC (Chi2 test by default)

Definition at line 226 of file IBNLearner_inl.h.

References PC, and selectedAlgo_.

◆ useScoreAIC()

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

indicate that we wish to use an AIC score

Definition at line 170 of file IBNLearner_inl.h.

References AIC, checkScorePriorCompatibility(), and scoreType_.

Here is the call graph for this function:

◆ useScoreBD()

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

indicate that we wish to use a BD score

Definition at line 176 of file IBNLearner_inl.h.

References BD, checkScorePriorCompatibility(), and scoreType_.

Here is the call graph for this function:

◆ useScoreBDeu()

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

indicate that we wish to use a BDeu score

Definition at line 182 of file IBNLearner_inl.h.

References BDeu, checkScorePriorCompatibility(), and scoreType_.

Here is the call graph for this function:

◆ useScoreBIC()

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

indicate that we wish to use a BIC score

Definition at line 188 of file IBNLearner_inl.h.

References BIC, checkScorePriorCompatibility(), and scoreType_.

Here is the call graph for this function:

◆ useScorefNML()

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

indicate that we wish to use a fNML score

Definition at line 194 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), fNML, and scoreType_.

Here is the call graph for this function:

◆ useScoreK2()

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

indicate that we wish to use a K2 score

Definition at line 200 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), K2, and scoreType_.

Here is the call graph for this function:

◆ useScoreLog2Likelihood()

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

indicate that we wish to use a Log2Likelihood score

Definition at line 206 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), LOG2LIKELIHOOD, and scoreType_.

Here is the call graph for this function:

◆ useScoreMDL()

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

indicate that we wish to use a MDL score

Definition at line 212 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), MDL, and scoreType_.

Here is the call graph for this function:

◆ useSmoothingPrior() [1/2]

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

use the prior smoothing with the default weight (key priorWeight of the section learning)

Definition at line 689 of file IBNLearner_inl.h.

689 {
690 useSmoothingPrior(gum::config().typed< double >("learning", "priorWeight"));
691 }
void useSmoothingPrior(double weight)
use the prior smoothing

References gum::config(), and useSmoothingPrior().

Here is the call graph for this function:

◆ useSmoothingPrior() [2/2]

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

use the prior smoothing

Parameters
weightthe weight assigned to the smoothing

Definition at line 694 of file IBNLearner_inl.h.

694 {
695 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
696
698 _setPriorWeight_(weight);
699
701 }

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

Referenced by useSmoothingPrior().

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

◆ verbosity()

INLINE bool gum::learning::IBNLearner::verbosity ( ) const
overridevirtual

verbosity

Implements gum::IApproximationSchemeConfiguration.

Definition at line 979 of file IBNLearner_inl.h.

979 {
980 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->verbosity();
981 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
982 }

References currentAlgorithm_, GUM_ERROR, and gum::ApproximationScheme::verbosity().

Referenced by createPrior_().

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

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.

◆ algoFCI_

gum::learning::FCI gum::learning::IBNLearner::algoFCI_
protected

the FCI algorithm

Definition at line 1263 of file IBNLearner.h.

Referenced by learnDag_(), learnPAG_(), learnPDAG_(), and prepareFCI_().

◆ algoK2_

◆ algoMiic_

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

the Constraint MIIC algorithm

Definition at line 1239 of file IBNLearner.h.

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

◆ algoPC_

gum::learning::PC gum::learning::IBNLearner::algoPC_
protected

the PC algorithm

Definition at line 1246 of file IBNLearner.h.

Referenced by learnDag_(), learnPDAG_(), and preparePC_().

◆ allowArcAdditions_

bool gum::learning::IBNLearner::allowArcAdditions_ {true}
protected

whether we allow or not arc additions during learning

Definition at line 1224 of file IBNLearner.h.

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

◆ allowArcDeletions_

bool gum::learning::IBNLearner::allowArcDeletions_ {true}
protected

whether we allow or not arc deletions during learning

Definition at line 1227 of file IBNLearner.h.

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

◆ allowArcReversals_

bool gum::learning::IBNLearner::allowArcReversals_ {true}
protected

whether we allow or not arc reversals during learning

Definition at line 1230 of file IBNLearner.h.

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

◆ allowArcTriangleDeletions_

bool gum::learning::IBNLearner::allowArcTriangleDeletions_ {true}
protected

whether we allow or not arc deletions during learning

Definition at line 1233 of file IBNLearner.h.

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

◆ alphaFci_

double gum::learning::IBNLearner::alphaFci_ {gum::config().typed< double >("learning", "alpha")}
protected

FCI parameters the threshold of the tests ; it is initialized from the key learning.alpha.

Definition at line 1273 of file IBNLearner.h.

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

◆ alphaPc_

double gum::learning::IBNLearner::alphaPc_ {gum::config().typed< double >("learning", "alpha")}
protected

PC parameters the threshold of the tests ; it is initialized from the key learning.alpha.

Definition at line 1257 of file IBNLearner.h.

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

◆ constraintForbiddenArcs_

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

◆ constraintIndegree_

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

the constraint for indegrees

Definition at line 1200 of file IBNLearner.h.

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

◆ constraintMandatoryArcs_

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

◆ constraintNoChildrenNodes_

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

the constraint on no children nodes

Definition at line 1218 of file IBNLearner.h.

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

◆ constraintNoParentNodes_

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

the constraint on no parent nodes

Definition at line 1215 of file IBNLearner.h.

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

◆ constraintPossibleEdges_

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

the constraint on possible Edges

Definition at line 1209 of file IBNLearner.h.

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

◆ constraintSliceOrder_

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

the constraint for 2TBNs

Definition at line 1194 of file IBNLearner.h.

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

◆ constraintTabuList_

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

the constraint for tabu lists

Definition at line 1203 of file IBNLearner.h.

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

◆ constraintTotalOrder_

StructuralConstraintTotalOrder gum::learning::IBNLearner::constraintTotalOrder_
protected

the total order ing constraint

Definition at line 1197 of file IBNLearner.h.

Referenced by learnDag_(), prepareFCI_(), prepareMiic_(), preparePC_(), and setTotalOrder().

◆ currentAlgorithm_

◆ dag2BN_

◆ exhaustiveSepSetFci_

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

◆ extendedGreedyHillClimbing_

GreedyHillClimbing gum::learning::IBNLearner::extendedGreedyHillClimbing_
protected

the extended greedy hill climbing

Definition at line 1284 of file IBNLearner.h.

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

◆ filename_

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

the filename database

Definition at line 1308 of file IBNLearner.h.

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

◆ greedyHillClimbing_

◆ greedyThickThinning_

GreedyThickThinning gum::learning::IBNLearner::greedyThickThinning_
protected

the greedy thick-thinning algorithm

Definition at line 1287 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), greedyThickThinningReversals(), learnDag_(), operator=(), operator=(), and setGreedyThickThinningReversals().

◆ indepTestFCI_

IndependenceTest* gum::learning::IBNLearner::indepTestFCI_ {nullptr}
protected

owned independence test object for FCI (rebuilt before each learn call)

Definition at line 1269 of file IBNLearner.h.

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

◆ indepTestPC_

IndependenceTest* gum::learning::IBNLearner::indepTestPC_ {nullptr}
protected

owned independence test object for PC (rebuilt before each learn call)

Definition at line 1253 of file IBNLearner.h.

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

◆ indepTestTypeFCI_

IndepTestType gum::learning::IBNLearner::indepTestTypeFCI_ {IndepTestType::Chi2}
protected

independence test type for FCI (reuses IndepTestType defined above)

Definition at line 1266 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), operator=(), operator=(), prepareFCI_(), useFCIChi2Test(), and useFCIG2Test().

◆ indepTestTypePC_

IndepTestType gum::learning::IBNLearner::indepTestTypePC_ {IndepTestType::Chi2}
protected

◆ inducedTypes_

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

the policy for typing variables

Definition at line 1164 of file IBNLearner.h.

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

◆ initialDag_

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

an initial DAG given to learners

Definition at line 1305 of file IBNLearner.h.

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

◆ kmodeMiic_

◆ localSearchWithTabuList_

◆ maxCondSetSizePc_

Size gum::learning::IBNLearner::maxCondSetSizePc_ {Size(-1)}
protected

◆ maxPathLengthFci_

Size gum::learning::IBNLearner::maxPathLengthFci_ {Size(-1)}
protected

◆ mutualInfo_

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

the selected correction for miic

Definition at line 1179 of file IBNLearner.h.

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

◆ nbDecreasingChanges_

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

◆ noPrior_

◆ onProgress

◆ onStop

Signaler< std::string_view > gum::IApproximationSchemeConfiguration::onStop
inherited

Criteria messageApproximationScheme.

Definition at line 84 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 1173 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 1299 of file IBNLearner.h.

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 1302 of file IBNLearner.h.

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

◆ priorType_

BNLearnerPriorType gum::learning::IBNLearner::priorType_ {BNLearnerPriorType::NO_prior}
protected

the a priorselected for the score and parameters

Definition at line 1182 of file IBNLearner.h.

Referenced by IBNLearner(), IBNLearner(), getPriorType_(), learnDag_(), operator=(), operator=(), useBDeuPrior(), useDirichletPrior(), useNoPrior(), and useSmoothingPrior().

◆ priorWeight_

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

the weight of the prior. It is always written by the useXxxPrior() methods, which read learning.priorWeight when no weight is given.

Definition at line 1191 of file IBNLearner.h.

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

◆ scoreDatabase_

◆ scoreType_

◆ selectedAlgo_

◆ sortedUCPc_

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

◆ stablePc_

bool gum::learning::IBNLearner::stablePc_ {true}
protected

Definition at line 1258 of file IBNLearner.h.

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

◆ tabuListSize_

Size gum::learning::IBNLearner::tabuListSize_ {100}
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 1176 of file IBNLearner.h.

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: