aGrUM 3.0.0
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:

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
IBNLearneroperator= (const IBNLearner &)
 copy operator
IBNLearneroperator= (IBNLearner &&)
 move operator
Accessors / Modifiers
DAG learnDAG ()
 learn a structure from a file (must have read the db before)
PDAG learnPDAG ()
 learn a partial structure from a file (must have read the db before and must have selected miic)
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 DatabaseTabledatabase () const
 returns the database used by the BNLearner
void setDatabaseWeight (const double new_weight)
 assign a weight to all the rows of the learning database so that the sum of their weights is equal to new_weight
void setRecordWeight (const std::size_t i, const double weight)
 sets the weight of the ith record of the database
double recordWeight (const std::size_t i) const
 returns the weight of the ith record
double databaseWeight () const
 returns the weight of the whole database
const std::string & nameFromId (NodeId id) const
 returns the variable name corresponding to a given node id
void useDatabaseRanges (const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges)
 use a new set of database rows' ranges to perform learning
void clearDatabaseRanges ()
 reset the ranges to the one range corresponding to the whole database
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges () const
 returns the current database rows' ranges used for learning
std::pair< std::size_t, std::size_t > useCrossValidationFold (const std::size_t learning_fold, const std::size_t k_fold)
 sets the ranges of rows to be used for cross-validation learning
std::pair< double, doublechi2 (NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
 Return the <statistic,pvalue> pair for chi2 test in the database.
std::pair< double, doublechi2 (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, doubleG2 (NodeId id1, NodeId id2, const std::vector< NodeId > &knowing={})
 Return the <statistic,pvalue> pair for for G2 test in the database.
std::pair< double, doubleG2 (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< doublerawPseudoCount (const std::vector< NodeId > &vars)
 Return the pseudo-counts of NodeIds vars in the base in a raw array.
std::vector< doublerawPseudoCount (const std::vector< std::string > &vars)
 Return the pseudoconts of vars in the base in a raw array.
Size nbCols () const
Size nbRows () const
void useEM (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters
void useEMWithRateCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the rate stopping criterion
void useEMWithDiffCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the diff stopping criterion
void forbidEM ()
 prevent using the EM algorithm for parameter learning
bool isUsingEM () const
 indicates whether we use EM for parameter learning
EMApproximationSchemeEM ()
 returns the EM parameter learning approximation scheme if EM is enabled
ApproximationSchemeSTATE EMState () const
 returns the state of the last EM algorithm executed
std::string EMStateMessage () const
 returns the state of the EM algorithm
bool hasMissingValues () const
 returns true if the learner's database has missing values
Score selection
void useScoreAIC ()
 indicate that we wish to use an AIC score
void useScoreBD ()
 indicate that we wish to use a BD score
void useScoreBDeu ()
 indicate that we wish to use a BDeu score
void useScoreBIC ()
 indicate that we wish to use a BIC score
void 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=1.0)
 use the BDeu prior
void useSmoothingPrior (double weight=1)
 use the prior smoothing
void useDirichletPrior (std::string_view filename, double weight=1)
 use the Dirichlet prior from a database
std::string checkScorePriorCompatibility () const
 checks whether the current score and prior are compatible
Learning algorithm selection
void useGreedyHillClimbing ()
 indicate that we wish to use a greedy hill climbing algorithm
void useExtendedGreedyHillClimbing ()
 indicate that we wish to use the extended greedy hill climbing algorithm
void useLocalSearchWithTabuList (Size tabu_size=100, Size nb_decrease=2)
 indicate that we wish to use a local search with tabu list
void useK2 (const Sequence< NodeId > &order)
 indicate that we wish to use K2
void useK2 (const std::vector< NodeId > &order)
 indicate that we wish to use K2
void useMIIC ()
 indicate that we wish to use MIIC
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
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< ArclatentVariables () 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 (default 0.05)
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 (default 0.05)
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, doubleonProgress
 Progression, error and time.
Signaler< std::string_view > onStop
 Criteria messageApproximationScheme.

Static Public Attributes

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

Protected 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
ParamEstimatorcreateParamEstimator_ (const DBRowGeneratorParser &parser, bool take_into_account_score=true)
 create the parameter estimator used for learning
DAG learnDag_ ()
 returns the DAG learnt
MixedGraph prepareSimpleMiic_ ()
 prepares the initial graph for Simple Miic
MixedGraph prepareMiic_ ()
 prepares the initial graph for miic
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
Scorescore_ {nullptr}
 the score used
ParamEstimatorType paramEstimatorType_ {ParamEstimatorType::ML}
 the type of the parameter estimator
bool useEM_ {false}
 a Boolean indicating whether we should use EM for parameter learning or not
double noiseEM_ {0.1}
 the noise factor (in (0,1)) used by EM for perturbing the CPT during init
CorrectedMutualInformationmutualInfo_ {nullptr}
 the selected correction for miic
BNLearnerPriorType priorType_ {BNLearnerPriorType::NO_prior}
 the a priorselected for the score and parameters
Priorprior_ {nullptr}
 the prior used
NoPriornoPrior_ {nullptr}
double priorWeight_ {1.0f}
 the weight of the prior
StructuralConstraintSliceOrder constraintSliceOrder_
 the constraint for 2TBNs
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_ {AlgoType::MIIC}
 the selected learning algorithm
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
SimpleMiic algoSimpleMiic_
 the MIIC 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}
IndependenceTestindepTestPC_ {nullptr}
 owned independence test object for PC (rebuilt before each learn call)
double alphaPc_ {0.05}
 PC parameters.
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)
IndependenceTestindepTestFCI_ {nullptr}
 owned independence test object for FCI (rebuilt before each learn call)
double alphaFci_ {0.05}
 FCI parameters.
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
DatabasepriorDatabase_ {nullptr}
 the database used by the Dirichlet a priori
std::string priorDbname_
 the filename for the Dirichlet a priori, if any
DAG initialDag_
 an initial DAG given to learners
std::string filename_ {"-"}
 the filename database
Size nbDecreasingChanges_ {2}
const ApproximationSchemecurrentAlgorithm_ {nullptr}

Private Attributes

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

Detailed Description

A pack of learning algorithms that can easily be used.

The pack currently contains K2, GreedyHillClimbing and LocalSearchWithTabuList also miic

Definition at line 104 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 123 of file IBNLearner.h.

123 {
124 K2,
125 GREEDY_HILL_CLIMBING,
126 LOCAL_SEARCH_WITH_TABU_LIST,
127 MIIC,
128 PC,
129 FCI,
130 EXTENDED_GREEDY_HILL_CLIMBING,
131 GREEDY_THICK_THINNING
132 };

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

114 {
115 NO_prior,
116 SMOOTHING,
117 DIRICHLET_FROM_DATABASE,
118 DIRICHLET_FROM_BAYESNET,
119 BDEU
120 };

◆ IndepTestType

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

independence test type for PC

Enumerator
Chi2 
G2 

Definition at line 1209 of file IBNLearner.h.

1209{ Chi2, G2 };

◆ ParamEstimatorType

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

Enumerator
ML 

Definition at line 111 of file IBNLearner.h.

111{ 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 107 of file IBNLearner.h.

107{ 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 200 of file IBNLearner.cpp.

202 :
203 inducedTypes_(induceTypes), scoreDatabase_(filename, missing_symbols, induceTypes),
204 filename_(filename) {
205 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
206
207 GUM_CONSTRUCTOR(IBNLearner)
208 }
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

References IBNLearner(), 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 210 of file IBNLearner.cpp.

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

References IBNLearner(), 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;
106 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
107 inducedTypes_ = false;
108 GUM_CONSTRUCTOR(IBNLearner);
109 }

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

Here is the call graph for this function:

◆ IBNLearner() [4/5]

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

copy constructor

Definition at line 215 of file IBNLearner.cpp.

215 :
217 inducedTypes_(from.inducedTypes_), scoreType_(from.scoreType_),
218 paramEstimatorType_(from.paramEstimatorType_), useEM_(from.useEM_), noiseEM_(from.noiseEM_),
219 priorType_(from.priorType_), priorWeight_(from.priorWeight_),
220 constraintSliceOrder_(from.constraintSliceOrder_),
221 constraintIndegree_(from.constraintIndegree_), constraintTabuList_(from.constraintTabuList_),
222 constraintForbiddenArcs_(from.constraintForbiddenArcs_),
223 constraintMandatoryArcs_(from.constraintMandatoryArcs_),
224 constraintNoParentNodes_(from.constraintNoParentNodes_),
225 constraintNoChildrenNodes_(from.constraintNoChildrenNodes_),
226 selectedAlgo_(from.selectedAlgo_), algoK2_(from.algoK2_),
227 algoSimpleMiic_(from.algoSimpleMiic_), algoMiic_(from.algoMiic_), kmodeMiic_(from.kmodeMiic_),
228 dag2BN_(from.dag2BN_), greedyHillClimbing_(from.greedyHillClimbing_),
229 localSearchWithTabuList_(from.localSearchWithTabuList_), scoreDatabase_(from.scoreDatabase_),
230 ranges_(from.ranges_), priorDbname_(from.priorDbname_), initialDag_(from.initialDag_),
231 filename_(from.filename_), nbDecreasingChanges_(from.nbDecreasingChanges_) {
232 noPrior_ = new NoPrior(scoreDatabase_.databaseTable());
233
234 GUM_CONS_CPY(IBNLearner)
235 }
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
double noiseEM_
the noise factor (in (0,1)) used by EM for perturbing the CPT during init
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done
K2 algoK2_
the K2 algorithm
AlgoType selectedAlgo_
the selected learning algorithm
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
StructuralConstraintIndegree constraintIndegree_
the constraint for indegrees
SimpleMiic algoSimpleMiic_
the MIIC algorithm
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
Miic algoMiic_
the Constraint MIIC algorithm
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
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::ThreadNumberManager::ThreadNumberManager(), algoK2_, algoMiic_, algoSimpleMiic_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintSliceOrder_, constraintTabuList_, dag2BN_, filename_, greedyHillClimbing_, inducedTypes_, initialDag_, kmodeMiic_, localSearchWithTabuList_, nbDecreasingChanges_, noiseEM_, noPrior_, paramEstimatorType_, priorDbname_, priorType_, priorWeight_, ranges_, scoreDatabase_, scoreType_, selectedAlgo_, and useEM_.

Here is the call graph for this function:

◆ IBNLearner() [5/5]

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

move constructor

Definition at line 237 of file IBNLearner.cpp.

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

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

Here is the call graph for this function:

◆ ~IBNLearner()

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

destructor

Definition at line 262 of file IBNLearner.cpp.

262 {
263 if (score_) delete score_;
264
265 if (prior_) delete prior_;
266
267 if (noPrior_) delete noPrior_;
268
269 if (priorDatabase_) delete priorDatabase_;
270
271 if (mutualInfo_) delete mutualInfo_;
272
273 if (indepTestPC_) delete indepTestPC_;
274
275 if (indepTestFCI_) delete indepTestFCI_;
276
277 GUM_DESTRUCTOR(IBNLearner)
278 }
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 644 of file IBNLearner_inl.h.

644 {
645 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
646
647 priorWeight_ = weight;
649 }
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 517 of file IBNLearner_inl.h.

517{ constraintForbiddenArcs_.addArc(arc); }

References constraintForbiddenArcs_.

Referenced by addForbiddenArc(), and addForbiddenArc().

Here is the caller graph for this function:

◆ addForbiddenArc() [2/3]

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

Definition at line 525 of file IBNLearner_inl.h.

525 {
526 addForbiddenArc(Arc(tail, head));
527 }
void addForbiddenArc(const Arc &arc)

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

535 {
536 addForbiddenArc(Arc(idFromName(tail), idFromName(head)));
537 }
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name

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

550{ constraintMandatoryArcs_.addArc(arc); }

References constraintMandatoryArcs_.

Referenced by addMandatoryArc(), and addMandatoryArc().

Here is the caller graph for this function:

◆ addMandatoryArc() [2/3]

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

Definition at line 598 of file IBNLearner_inl.h.

598 {
599 addMandatoryArc(Arc(tail, head));
600 }
void addMandatoryArc(const Arc &arc)

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

588 {
589 addMandatoryArc(Arc(idFromName(tail), idFromName(head)));
590 }

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

571 {
572 constraintNoChildrenNodes_.addNode(node);
573 }

References constraintNoChildrenNodes_.

Referenced by addNoChildrenNode().

Here is the caller graph for this function:

◆ addNoChildrenNode() [2/2]

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

Definition at line 575 of file IBNLearner_inl.h.

575 {
577 }
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 557 of file IBNLearner_inl.h.

557{ constraintNoParentNodes_.addNode(node); }

References constraintNoParentNodes_.

Referenced by addNoParentNode().

Here is the caller graph for this function:

◆ addNoParentNode() [2/2]

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

Definition at line 559 of file IBNLearner_inl.h.

559 {
561 }
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 482 of file IBNLearner_inl.h.

482 {
483 constraintPossibleEdges_.addEdge(edge);
484 }
StructuralConstraintPossibleEdges constraintPossibleEdges_
the constraint on possible Edges

References constraintPossibleEdges_.

Referenced by addPossibleEdge(), and addPossibleEdge().

Here is the caller graph for this function:

◆ addPossibleEdge() [2/3]

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

Definition at line 492 of file IBNLearner_inl.h.

492 {
493 addPossibleEdge(Edge(tail, head));
494 }
void addPossibleEdge(const Edge &edge)

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

502 {
503 addPossibleEdge(Edge(idFromName(tail), idFromName(head)));
504 }

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

454{ allowArcAdditions_ = allow; }
bool allowArcAdditions_
whether we allow or not arc additions during learning

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

457{ allowArcDeletions_ = allow; }
bool allowArcDeletions_
whether we allow or not arc deletions during learning

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

460{ allowArcReversals_ = allow; }
bool allowArcReversals_
whether we allow or not arc reversals during learning

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

463 {
465 }
bool allowArcTriangleDeletions_
whether we allow or not arc deletions during learning

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

1270 {
1271 if (this->isConstraintBased()) return "";
1272
1273 const auto prior = getPriorType_();
1274
1275 switch (scoreType_) {
1277 case AIC : return ScoreAIC::isPriorCompatible(prior, priorWeight_);
1278
1279 case BD : return ScoreBD::isPriorCompatible(prior, priorWeight_);
1280
1281 case BDeu : return ScoreBDeu::isPriorCompatible(prior, priorWeight_);
1282
1283 case BIC : return ScoreBIC::isPriorCompatible(prior, priorWeight_);
1284
1285 case fNML : return ScorefNML::isPriorCompatible(prior, priorWeight_);
1286
1287 case K2 : return ScoreK2::isPriorCompatible(prior, priorWeight_);
1288
1290
1291 case MDL : return ScoreMDL::isPriorCompatible(prior, priorWeight_);
1292
1293 default : return "IBNLearner does not support yet this score";
1294 }
1295 }
ScoreType
an enumeration enabling to select easily the score we wish to use
Definition IBNLearner.h:107
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 AIC, BD, BDeu, BIC, fNML, 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(), LOG2LIKELIHOOD, MDL, 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 1338 of file IBNLearner.cpp.

1338 {
1339 createPrior_();
1340 gum::learning::IndepTestChi2 chi2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1341
1342 return chi2score.statistics(id1, id2, knowing);
1343 }
virtual void createPrior_()=0
create the prior used for learning
const std::vector< std::pair< std::size_t, std::size_t > > & databaseRanges() const
returns the current database rows' ranges used for learning

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

Referenced by chi2().

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

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

1347 {
1348 std::vector< NodeId > knowingIds;
1349 std::transform(knowing.begin(),
1350 knowing.end(),
1351 std::back_inserter(knowingIds),
1352 [this](const std::string& c) { return this->idFromName(c); });
1353 return chi2(idFromName(name1), idFromName(name2), knowingIds);
1354 }
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 729 of file IBNLearner_inl.h.

729{ 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 1403 of file IBNLearner.cpp.

1405 {
1406 createPrior_();
1407 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(),
1408 *prior_,
1409 databaseRanges());
1410
1411 switch (kmodeMiic_) {
1413 case MDL : cmi.useMDL(); break;
1414
1415 case NML : cmi.useNML(); break;
1416
1417 case NoCorr : cmi.useNoCorr(); break;
1418
1419 default :
1420 GUM_ERROR(NotImplementedYet,
1421 "The BNLearner's corrected mutual information class does "
1422 << "not implement yet this correction : " << int(kmodeMiic_))
1423 }
1424 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1425 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1426 }
KModeTypes
the description type for the complexity correction
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

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

Referenced by correctedMutualInformation().

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

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

1430 {
1431 std::vector< NodeId > knowingIds;
1432
1433 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1434
1435 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1436
1437 return correctedMutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1438 }
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 966 of file IBNLearner.cpp.

966 {
967 if (mutualInfo_ != nullptr) delete mutualInfo_;
968
969 mutualInfo_ = new CorrectedMutualInformation(scoreDatabase_.parser(),
970 *noPrior_,
971 ranges_,
972 scoreDatabase_.nodeId2Columns());
973 switch (kmodeMiic_) {
975 case MDL : mutualInfo_->useMDL(); break;
976 case NML : mutualInfo_->useNML(); break;
977 case NoCorr : mutualInfo_->useNoCorr(); break;
978 default :
979 GUM_ERROR(NotImplementedYet,
980 "The BNLearner's corrected mutual information class does "
981 << "not implement yet this correction : " << int(kmodeMiic_))
982 }
983 }

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

Referenced by prepareMiic_().

Here is the caller graph for this function:

◆ createParamEstimator_()

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

create the parameter estimator used for learning

Definition at line 544 of file IBNLearner.cpp.

545 {
546 ParamEstimator* param_estimator = nullptr;
547
548 // create the new estimator
549 switch (paramEstimatorType_) {
551 if (take_into_account_score && (score_ != nullptr)) {
552 param_estimator = new ParamEstimatorML(parser,
553 *prior_,
554 score_->internalPrior(),
555 ranges_,
556 scoreDatabase_.nodeId2Columns());
557 } else {
558 param_estimator = new ParamEstimatorML(parser,
559 *prior_,
560 *noPrior_,
561 ranges_,
562 scoreDatabase_.nodeId2Columns());
563 }
564
565 break;
566
567 default :
568 GUM_ERROR(OperationNotAllowed,
569 "IBNLearner does not support " << "yet this parameter estimator")
570 }
571
572 // assign the number of threads
573 param_estimator->setNumberOfThreads(
575
576 // assign the set of ranges
577 param_estimator->setRanges(ranges_);
578
579 return param_estimator;
580 }
bool isGumNumberOfThreadsOverriden() const override
indicates whether the class containing this ThreadNumberManager set its own number of threads
Size getNumberOfThreads() const override
returns the current max number of threads used by the class containing this ThreadNumberManager

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

Here is the call graph for this function:

◆ createPrior_()

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

create the prior used for learning

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

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

Here is the caller graph for this function:

◆ createScore_()

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

create the score used for learning

Definition at line 471 of file IBNLearner.cpp.

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

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

Referenced by learnDAG(), and score().

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

◆ currentTime()

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

get the current running time in second (double)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 890 of file IBNLearner_inl.h.

890 {
891 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->currentTime();
892 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
893 }
const ApproximationScheme * currentAlgorithm_

References currentAlgorithm_, and GUM_ERROR.

◆ database()

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

returns the database used by the BNLearner

Definition at line 732 of file IBNLearner_inl.h.

732 {
733 return scoreDatabase_.databaseTable();
734 }

References scoreDatabase_.

Referenced by readFile_().

Here is the caller graph for this function:

◆ databaseRanges()

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

returns the current database rows' ranges used for learning

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

Definition at line 724 of file IBNLearner_inl.h.

724 {
725 return ranges_;
726 }

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

161{ return scoreDatabase_.weight(); }

References scoreDatabase_.

◆ disableEpsilon()

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

Disable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 797 of file IBNLearner_inl.h.

797 {
798 algoK2_.approximationScheme().disableEpsilon();
799 greedyHillClimbing_.disableEpsilon();
800 localSearchWithTabuList_.disableEpsilon();
801 dag2BN_.disableEpsilon();
802 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMaxIter()

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

Disable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 859 of file IBNLearner_inl.h.

859 {
860 algoK2_.approximationScheme().disableMaxIter();
861 greedyHillClimbing_.disableMaxIter();
862 localSearchWithTabuList_.disableMaxIter();
863 dag2BN_.disableMaxIter();
864 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMaxTime()

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

Disable stopping criterion on timeout.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 895 of file IBNLearner_inl.h.

895 {
896 algoK2_.approximationScheme().disableMaxTime();
897 greedyHillClimbing_.disableMaxTime();
898 localSearchWithTabuList_.disableMaxTime();
899 dag2BN_.disableMaxTime();
900 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMinEpsilonRate()

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

Disable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 828 of file IBNLearner_inl.h.

828 {
829 algoK2_.approximationScheme().disableMinEpsilonRate();
830 greedyHillClimbing_.disableMinEpsilonRate();
831 localSearchWithTabuList_.disableMinEpsilonRate();
832 dag2BN_.disableMinEpsilonRate();
833 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ distributeProgress()

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

{@ /// distribute signals

Definition at line 771 of file IBNLearner_inl.h.

774 {
775 setCurrentApproximationScheme(approximationScheme);
776 if (onProgress.hasListener()) GUM_EMIT3(onProgress, pourcent, error, time);
777 }
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::IApproximationSchemeConfiguration::onProgress, and setCurrentApproximationScheme().

Here is the call graph for this function:

◆ distributeStop()

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

distribute signals

Definition at line 779 of file IBNLearner_inl.h.

780 {
781 setCurrentApproximationScheme(approximationScheme);
782 if (onStop.hasListener()) GUM_EMIT1(onStop, message);
783 }
Signaler< std::string_view > onStop
Criteria messageApproximationScheme.
#define GUM_EMIT1(signal, arg1)
Definition signaler.h:289

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

Here is the call graph for this function:

◆ domainSize() [1/2]

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

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

Definition at line 715 of file IBNLearner_inl.h.

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

References scoreDatabase_.

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

718 {
719 return scoreDatabase_.domainSizes()[idFromName(var)];
720 }

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

710 {
711 return scoreDatabase_.domainSizes();
712 }

References scoreDatabase_.

◆ EM()

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

returns the EM parameter learning approximation scheme if EM is enabled

returns the EM parameter learning approximation scheme

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

Definition at line 436 of file IBNLearner_inl.h.

436 {
437 if (useEM_) return dag2BN_;
438 else GUM_ERROR(NotFound, "EM is currently forbidden. Please enable it with useEM()")
439 }

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

992{ return dag2BN_.currentTime(); }

References dag2BN_.

◆ EMdisableEpsilon()

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

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

Definition at line 960 of file IBNLearner_inl.h.

960{ dag2BN_.disableEpsilon(); }

References dag2BN_.

◆ EMdisableMaxIter()

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

Disable stopping criterion on max iterations.

Definition at line 982 of file IBNLearner_inl.h.

982{ dag2BN_.disableMaxIter(); }

References dag2BN_.

◆ EMdisableMaxTime()

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

Disable EM's timeout stopping criterion.

Definition at line 994 of file IBNLearner_inl.h.

994{ dag2BN_.disableMaxTime(); }

References dag2BN_.

◆ EMdisableMinEpsilonRate()

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

Disable the log-likelihood evolution rate stopping criterion.

Definition at line 970 of file IBNLearner_inl.h.

970{ dag2BN_.disableMinEpsilonRate(); }

References dag2BN_.

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

962{ dag2BN_.enableEpsilon(); }

References dag2BN_.

◆ EMenableMaxIter()

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

Enable stopping criterion on max iterations.

Definition at line 984 of file IBNLearner_inl.h.

984{ dag2BN_.enableMaxIter(); }

References dag2BN_.

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

996{ dag2BN_.enableMaxTime(); }

References dag2BN_.

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

972{ dag2BN_.enableMinEpsilonRate(); }

References dag2BN_.

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

958{ return dag2BN_.epsilon(); }

References dag2BN_.

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

1015{ return dag2BN_.history(); }

References dag2BN_.

◆ EMisEnabledEpsilon()

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

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

Definition at line 964 of file IBNLearner_inl.h.

964{ return dag2BN_.isEnabledEpsilon(); }

References dag2BN_.

◆ EMisEnabledMaxIter()

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

Definition at line 986 of file IBNLearner_inl.h.

986{ return dag2BN_.isEnabledMaxIter(); }

References dag2BN_.

◆ EMisEnabledMaxTime()

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

Definition at line 998 of file IBNLearner_inl.h.

998{ return dag2BN_.isEnabledMaxTime(); }

References dag2BN_.

◆ EMisEnabledMinEpsilonRate()

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

Definition at line 974 of file IBNLearner_inl.h.

974 {
975 return dag2BN_.isEnabledMinEpsilonRate();
976 }

References dag2BN_.

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

980{ return dag2BN_.maxIter(); }

References dag2BN_.

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

990{ return dag2BN_.maxTime(); }

References dag2BN_.

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

968{ return dag2BN_.minEpsilonRate(); }

References dag2BN_.

◆ EMnbrIterations()

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

returns the number of iterations performed by the last EM execution

Definition at line 1013 of file IBNLearner_inl.h.

1013{ return dag2BN_.nbrIterations(); }

References dag2BN_.

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

1002{ return dag2BN_.periodSize(); }

References dag2BN_.

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

956{ dag2BN_.setEpsilon(eps); }

References dag2BN_.

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

978{ dag2BN_.setMaxIter(max); }

References dag2BN_.

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

988{ dag2BN_.setMaxTime(timeout); }

References dag2BN_.

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

966{ dag2BN_.setMinEpsilonRate(rate); }

References dag2BN_.

◆ EMsetPeriodSize()

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

how many samples between 2 stoppings isEnabled

Exceptions
OutOfBoundsif p<1

Definition at line 1000 of file IBNLearner_inl.h.

1000{ dag2BN_.setPeriodSize(p); }

References dag2BN_.

◆ EMsetVerbosity()

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

sets or unsets EM's verbosity

Definition at line 1004 of file IBNLearner_inl.h.

1004{ dag2BN_.setVerbosity(v); }

References dag2BN_.

◆ EMState()

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

returns the state of the last EM algorithm executed

Definition at line 442 of file IBNLearner_inl.h.

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

◆ EMStateApproximationScheme()

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

get the current state of EM

Definition at line 1009 of file IBNLearner_inl.h.

1009 {
1010 return dag2BN_.stateApproximationScheme();
1011 }

References dag2BN_.

◆ EMStateMessage()

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

returns the state of the EM algorithm

Definition at line 448 of file IBNLearner_inl.h.

448 {
449 if (useEM_) return dag2BN_.messageApproximationScheme();
450 else return "EM is currently forbidden. Please enable it with useEM()";
451 }

References dag2BN_, and useEM_.

◆ EMVerbosity()

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

returns the EM's verbosity status

Definition at line 1006 of file IBNLearner_inl.h.

1006{ return dag2BN_.verbosity(); }

References dag2BN_.

◆ enableEpsilon()

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

Enable stopping criterion on epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 804 of file IBNLearner_inl.h.

804 {
805 algoK2_.approximationScheme().enableEpsilon();
806 greedyHillClimbing_.enableEpsilon();
807 localSearchWithTabuList_.enableEpsilon();
808 dag2BN_.enableEpsilon();
809 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ enableMaxIter()

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

Enable stopping criterion on max iterations.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 866 of file IBNLearner_inl.h.

866 {
867 algoK2_.approximationScheme().enableMaxIter();
868 greedyHillClimbing_.enableMaxIter();
869 localSearchWithTabuList_.enableMaxIter();
870 dag2BN_.enableMaxIter();
871 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

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

902 {
903 algoK2_.approximationScheme().enableMaxTime();
904 greedyHillClimbing_.enableMaxTime();
905 localSearchWithTabuList_.enableMaxTime();
906 dag2BN_.enableMaxTime();
907 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ enableMinEpsilonRate()

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

Enable stopping criterion on epsilon rate.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 835 of file IBNLearner_inl.h.

835 {
836 algoK2_.approximationScheme().enableMinEpsilonRate();
837 greedyHillClimbing_.enableMinEpsilonRate();
838 localSearchWithTabuList_.enableMinEpsilonRate();
839 dag2BN_.enableMinEpsilonRate();
840 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ epsilon()

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

Get the value of epsilon.

Implements gum::IApproximationSchemeConfiguration.

Definition at line 792 of file IBNLearner_inl.h.

792 {
793 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->epsilon();
794 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
795 }

References currentAlgorithm_, and GUM_ERROR.

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

Here is the caller graph for this function:

◆ eraseForbiddenArc() [1/3]

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

Definition at line 520 of file IBNLearner_inl.h.

520 {
521 constraintForbiddenArcs_.eraseArc(arc);
522 }

References constraintForbiddenArcs_.

Referenced by eraseForbiddenArc(), and eraseForbiddenArc().

Here is the caller graph for this function:

◆ eraseForbiddenArc() [2/3]

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

Definition at line 530 of file IBNLearner_inl.h.

530 {
531 eraseForbiddenArc(Arc(tail, head));
532 }
void eraseForbiddenArc(const Arc &arc)

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

540 {
541 eraseForbiddenArc(Arc(idFromName(tail), idFromName(head)));
542 }

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

553 {
554 constraintMandatoryArcs_.eraseArc(arc);
555 }

References constraintMandatoryArcs_.

Referenced by eraseMandatoryArc(), and eraseMandatoryArc().

Here is the caller graph for this function:

◆ eraseMandatoryArc() [2/3]

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

Definition at line 603 of file IBNLearner_inl.h.

603 {
604 eraseMandatoryArc(Arc(tail, head));
605 }
void eraseMandatoryArc(const Arc &arc)

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

593 {
594 eraseMandatoryArc(Arc(idFromName(tail), idFromName(head)));
595 }

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

579 {
580 constraintNoChildrenNodes_.eraseNode(node);
581 }

References constraintNoChildrenNodes_.

Referenced by eraseNoChildrenNode().

Here is the caller graph for this function:

◆ eraseNoChildrenNode() [2/2]

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

Definition at line 583 of file IBNLearner_inl.h.

583 {
585 }
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 563 of file IBNLearner_inl.h.

563 {
564 constraintNoParentNodes_.eraseNode(node);
565 }

References constraintNoParentNodes_.

Referenced by eraseNoParentNode().

Here is the caller graph for this function:

◆ eraseNoParentNode() [2/2]

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

Definition at line 567 of file IBNLearner_inl.h.

567 {
569 }
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 487 of file IBNLearner_inl.h.

487 {
488 constraintPossibleEdges_.eraseEdge(edge);
489 }

References constraintPossibleEdges_.

Referenced by erasePossibleEdge(), and erasePossibleEdge().

Here is the caller graph for this function:

◆ erasePossibleEdge() [2/3]

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

Definition at line 497 of file IBNLearner_inl.h.

497 {
498 erasePossibleEdge(Edge(tail, head));
499 }
void erasePossibleEdge(const Edge &edge)

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

507 {
508 erasePossibleEdge(Edge(idFromName(tail), idFromName(head)));
509 }

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

271 {
273 GUM_ERROR(OperationNotAllowed,
274 "fciExhaustiveSepSet() is only valid when using the FCI algorithm")
275 }
277 }

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

430{ 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 1357 of file IBNLearner.cpp.

1357 {
1358 createPrior_();
1359 gum::learning::IndepTestG2 g2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1360 return g2score.statistics(id1, id2, knowing);
1361 }

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

Referenced by G2().

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

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

1365 {
1366 std::vector< NodeId > knowingIds;
1367 std::transform(knowing.begin(),
1368 knowing.end(),
1369 std::back_inserter(knowingIds),
1370 [this](const std::string& c) { return this->idFromName(c); });
1371 return G2(idFromName(name1), idFromName(name2), knowingIds);
1372 }
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()

Size gum::ThreadNumberManager::getNumberOfThreads ( ) const
nodiscardoverridevirtualinherited

◆ getPriorType_()

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

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

Definition at line 689 of file IBNLearner_inl.h.

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

Referenced by checkScorePriorCompatibility().

Here is the caller graph for this function:

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

382 {
383 return greedyThickThinning_.allowReversalsInThinPhase();
384 }
GreedyThickThinning greedyThickThinning_
the greedy thick-thinning algorithm

References greedyThickThinning_.

◆ hasMissingValues()

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

returns true if the learner's database has missing values

Definition at line 467 of file IBNLearner_inl.h.

467 {
468 return scoreDatabase_.databaseTable().hasMissingValues();
469 }

References scoreDatabase_.

Referenced by rawPseudoCount().

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

949 {
950 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->history();
951 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
952 }

References currentAlgorithm_, and GUM_ERROR.

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

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

References 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 caller graph for this function:

◆ initialDAG()

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

returns the initial DAG structure

Definition at line 166 of file IBNLearner_inl.h.

166{ return initialDag_; }

References initialDag_.

◆ isConstraintBased()

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

indicate if the selected algorithm is constraint-based

Definition at line 750 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 429 of file IBNLearner.cpp.

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

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

811 {
812 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledEpsilon();
813 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
814 }

References currentAlgorithm_, and GUM_ERROR.

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

873 {
874 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxIter();
875 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
876 }

References currentAlgorithm_, and GUM_ERROR.

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

909 {
910 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMaxTime();
911 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
912 }

References currentAlgorithm_, and GUM_ERROR.

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

842 {
843 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->isEnabledMinEpsilonRate();
844 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
845 }

References currentAlgorithm_, and GUM_ERROR.

◆ 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_(), and gum::learning::IBNLearner::createScore_().

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

764{ 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 433 of file IBNLearner_inl.h.

433{ 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 345 of file IBNLearner_inl.h.

345 {
346 return algoMiic_.latentVariables();
347 }

References algoMiic_.

◆ learnDAG()

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

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

Definition at line 956 of file IBNLearner.cpp.

956 {
957 createPrior_();
958 createScore_();
959 auto dag = learnDag_();
960 for (const auto i: dag) {
961 dag.setName(i, scoreDatabase_.databaseTable().variableName(i));
962 }
963 return dag;
964 }
DAG learnDag_()
returns the DAG learnt
void createScore_()
create the score used for learning

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

Here is the call graph for this function:

◆ learnDag_()

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

returns the DAG learnt

Definition at line 985 of file IBNLearner.cpp.

985 {
986 // check that the database does not contain any missing value
987 if (scoreDatabase_.databaseTable().hasMissingValues()
988 || ((priorDatabase_ != nullptr)
990 && priorDatabase_->databaseTable().hasMissingValues())) {
991 GUM_ERROR(MissingValueInDatabase,
992 "For the moment, the BNLearner is unable to cope "
993 "with missing values in databases")
994 }
995 // add the mandatory arcs to the initial dag and remove the forbidden ones
996 // from the initial graph
997 DAG init_graph = initialDag_;
998
999 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
1000 if (!init_graph.exists(arc.tail())) init_graph.addNodeWithId(arc.tail());
1001
1002 if (!init_graph.exists(arc.head())) init_graph.addNodeWithId(arc.head());
1003
1004 init_graph.addArc(arc.tail(), arc.head());
1005 }
1006
1007 for (const auto& arc: constraintForbiddenArcs_.arcs())
1008 init_graph.eraseArc(arc);
1009
1010
1011 switch (selectedAlgo_) {
1012 // ========================================================================
1013 case AlgoType::PC : {
1014 BNLearnerListener listener(this, algoPC_);
1015 MixedGraph mgraph = this->preparePC_();
1016 return algoPC_.learnDAG(mgraph);
1017 }
1018
1019 // ========================================================================
1020 case AlgoType::FCI : {
1021 BNLearnerListener listener(this, algoFCI_);
1022 MixedGraph mgraph = this->prepareFCI_();
1023 return algoFCI_.learnDAG(mgraph);
1024 }
1025
1026 // ========================================================================
1027 case AlgoType::MIIC : {
1028 BNLearnerListener listener(this, algoMiic_);
1029 // create the mixedGraph and the corrected mutual information
1030 MixedGraph mgraph = this->prepareMiic_();
1031
1032 algoMiic_.setMutualInformation(*mutualInfo_);
1033 return algoMiic_.learnDAG(mgraph);
1034 }
1035
1036 // ========================================================================
1038 BNLearnerListener listener(this, greedyHillClimbing_);
1039 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1040 StructuralConstraintForbiddenArcs,
1041 StructuralConstraintPossibleEdges,
1042 StructuralConstraintSliceOrder,
1043 StructuralConstraintNoParentNodes,
1044 StructuralConstraintNoChildrenNodes,
1045 StructuralConstraintTotalOrder >
1046 invariable_constraints;
1047 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1049 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1051 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1053 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1055 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1057 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1059 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1061
1062 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1063 variable_constraints;
1064 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1065
1066 GraphChangesSelector4DiGraph selector(*score_,
1067 invariable_constraints,
1068 variable_constraints);
1069
1070 // enforce that greedy hill climbing uses arc additions, deletions and reversals
1071 // and only these operations
1072 selector.useArcAdditions(true);
1073 selector.useArcDeletions(true);
1074 selector.useArcReversals(true);
1075 selector.useArcTriangleDeletions(false);
1076
1077 return greedyHillClimbing_.learnStructure(selector, init_graph);
1078 }
1079
1080 // ========================================================================
1082 BNLearnerListener listener(this, extendedGreedyHillClimbing_);
1083 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1084 StructuralConstraintForbiddenArcs,
1085 StructuralConstraintPossibleEdges,
1086 StructuralConstraintNoParentNodes,
1087 StructuralConstraintNoChildrenNodes,
1088 StructuralConstraintSliceOrder,
1089 StructuralConstraintTotalOrder >
1090 invariable_constraints;
1091 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1093 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1095 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1097 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1099 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1101 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1103 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1105
1106 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1107 variable_constraints;
1108 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1109
1110 GraphChangesSelector4DiGraph selector(*score_,
1111 invariable_constraints,
1112 variable_constraints);
1113
1114 selector.useArcAdditions(allowArcAdditions_);
1115 selector.useArcDeletions(allowArcDeletions_);
1116 selector.useArcReversals(allowArcReversals_);
1117 selector.useArcTriangleDeletions(allowArcTriangleDeletions_);
1118
1119 return greedyHillClimbing_.learnStructure(selector, init_graph);
1120 }
1121
1122 // ========================================================================
1124 BNLearnerListener listener(this, greedyThickThinning_);
1125 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1126 StructuralConstraintForbiddenArcs,
1127 StructuralConstraintPossibleEdges,
1128 StructuralConstraintSliceOrder,
1129 StructuralConstraintNoParentNodes,
1130 StructuralConstraintNoChildrenNodes,
1131 StructuralConstraintTotalOrder >
1132 invariable_constraints;
1133 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1135 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1137 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1139 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1141 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1143 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1145 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1147
1148 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1149 variable_constraints;
1150 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1151
1152 GraphChangesSelector4DiGraph selector(*score_,
1153 invariable_constraints,
1154 variable_constraints);
1155
1156 return greedyThickThinning_.learnStructure(selector, init_graph);
1157 }
1158
1159 // ========================================================================
1161 BNLearnerListener listener(this, localSearchWithTabuList_);
1162 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1163 StructuralConstraintForbiddenArcs,
1164 StructuralConstraintPossibleEdges,
1165 StructuralConstraintSliceOrder,
1166 StructuralConstraintNoParentNodes,
1167 StructuralConstraintNoChildrenNodes,
1168 StructuralConstraintTotalOrder >
1169 invariable_constraints;
1170 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1172 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1174 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1176 static_cast< StructuralConstraintSliceOrder& >(invariable_constraints)
1178 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1180 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1182 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1184
1185 StructuralConstraintSetStatic< StructuralConstraintTabuList,
1186 StructuralConstraintIndegree,
1187 StructuralConstraintDAG >
1188 variable_constraints;
1189 static_cast< StructuralConstraintTabuList& >(variable_constraints) = constraintTabuList_;
1190 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1191
1192 GraphChangesSelector4DiGraph selector(*score_,
1193 invariable_constraints,
1194 variable_constraints);
1195
1196 selector.useArcAdditions(allowArcAdditions_);
1197 selector.useArcDeletions(allowArcDeletions_);
1198 selector.useArcReversals(allowArcReversals_);
1199 selector.useArcTriangleDeletions(allowArcTriangleDeletions_);
1200
1201 return localSearchWithTabuList_.learnStructure(selector, init_graph);
1202 }
1203
1204 // ========================================================================
1205 case AlgoType::K2 : {
1206 BNLearnerListener listener(this, algoK2_.approximationScheme());
1207 StructuralConstraintSetStatic< StructuralConstraintMandatoryArcs,
1208 StructuralConstraintForbiddenArcs,
1209 StructuralConstraintPossibleEdges,
1210 StructuralConstraintNoParentNodes,
1211 StructuralConstraintNoChildrenNodes,
1212 StructuralConstraintTotalOrder >
1213 invariable_constraints;
1214 static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints)
1216 static_cast< StructuralConstraintForbiddenArcs& >(invariable_constraints)
1218 static_cast< StructuralConstraintPossibleEdges& >(invariable_constraints)
1220 static_cast< StructuralConstraintNoParentNodes& >(invariable_constraints)
1222 static_cast< StructuralConstraintNoChildrenNodes& >(invariable_constraints)
1224 static_cast< StructuralConstraintTotalOrder& >(invariable_constraints)
1226
1227 // if some mandatory arcs are incompatible with the order, use a DAG
1228 // constraint instead of a DiGraph constraint to avoid cycles
1229 const ArcSet& mandatory_arcs
1230 = static_cast< StructuralConstraintMandatoryArcs& >(invariable_constraints).arcs();
1231 const Sequence< NodeId >& order = algoK2_.order();
1232 bool order_compatible = true;
1233
1234 for (const auto& arc: mandatory_arcs) {
1235 if (order.pos(arc.tail()) >= order.pos(arc.head())) {
1236 order_compatible = false;
1237 break;
1238 }
1239 }
1240
1241 if (order_compatible) {
1242 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDiGraph >
1243 variable_constraints;
1244 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1245
1246 GraphChangesSelector4DiGraph selector(*score_,
1247 invariable_constraints,
1248 variable_constraints);
1249
1250 return algoK2_.learnStructure(selector, init_graph);
1251 } else {
1252 StructuralConstraintSetStatic< StructuralConstraintIndegree, StructuralConstraintDAG >
1253 variable_constraints;
1254 static_cast< StructuralConstraintIndegree& >(variable_constraints) = constraintIndegree_;
1255
1256 GraphChangesSelector4DiGraph selector(*score_,
1257 invariable_constraints,
1258 variable_constraints);
1259
1260 return algoK2_.learnStructure(selector, init_graph);
1261 }
1262 }
1263 }
1264
1265 GUM_ERROR(OperationNotAllowed,
1266 "the learnDAG method has not been implemented for this "
1267 "learning algorithm")
1268 }
MixedGraph preparePC_()
prepares the initial graph and independence test for PC
GreedyHillClimbing extendedGreedyHillClimbing_
the extended greedy hill climbing
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
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...

References gum::DAG::addArc(), gum::NodeGraphPart::addNodeWithId(), algoFCI_, algoK2_, algoMiic_, algoPC_, allowArcAdditions_, allowArcDeletions_, allowArcReversals_, allowArcTriangleDeletions_, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTabuList_, constraintTotalOrder_, 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, initialDag_, K2, LOCAL_SEARCH_WITH_TABU_LIST, localSearchWithTabuList_, MIIC, mutualInfo_, PC, gum::SequenceImplementation< Key, std::is_scalar< Key >::value >::pos(), prepareFCI_(), prepareMiic_(), preparePC_(), priorDatabase_, priorType_, score_, scoreDatabase_, selectedAlgo_, 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 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 948 of file IBNLearner.cpp.

948 {
949 auto pag = learnPAG_();
950 for (const auto i: pag) {
951 pag.setName(i, scoreDatabase_.databaseTable().variableName(i));
952 }
953 return pag;
954 }

References learnPAG_(), and scoreDatabase_.

Here is the call graph for this function:

◆ learnPAG_()

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

Definition at line 934 of file IBNLearner.cpp.

934 {
936 GUM_ERROR(OperationNotAllowed, "learnPAG() is only valid when using the FCI algorithm")
937 }
938 if (scoreDatabase_.databaseTable().hasMissingValues()) {
939 GUM_ERROR(MissingValueInDatabase,
940 "For the moment, the BNLearner is unable to learn "
941 << "structures with missing values in databases")
942 }
943 BNLearnerListener listener(this, algoFCI_);
944 MixedGraph mgraph = this->prepareFCI_();
945 return algoFCI_.learnPAG(mgraph);
946 }

References algoFCI_, FCI, GUM_ERROR, 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 926 of file IBNLearner.cpp.

926 {
927 auto pdag = learnPDAG_();
928 for (const auto i: pdag) {
929 pdag.setName(i, scoreDatabase_.databaseTable().variableName(i));
930 }
931 return pdag;
932 }

References learnPDAG_(), and scoreDatabase_.

Here is the call graph for this function:

◆ learnPDAG_()

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

Definition at line 893 of file IBNLearner.cpp.

893 {
896 GUM_ERROR(OperationNotAllowed,
897 "Score-based algorithms do not build PDAG. Please use a constraint-based "
898 "algorithm instead")
899 }
900 // check that the database does not contain any missing value
901 if (scoreDatabase_.databaseTable().hasMissingValues()) {
902 GUM_ERROR(MissingValueInDatabase,
903 "For the moment, the BNLearner is unable to learn "
904 << "structures with missing values in databases")
905 }
906
908 BNLearnerListener listener(this, algoPC_);
909 MixedGraph mgraph = this->preparePC_();
910 return algoPC_.learnPDAG(mgraph);
911 }
912
914 BNLearnerListener listener(this, algoFCI_);
915 MixedGraph mgraph = this->prepareFCI_();
916 return algoFCI_.learnPDAG(mgraph);
917 }
918
919 BNLearnerListener listener(this, algoMiic_);
920 // create the mixedGraph_constraint_MandatoryArcs.arcs
921 MixedGraph mgraph = this->prepareMiic_();
922 algoMiic_.setMutualInformation(*mutualInfo_);
923 return algoMiic_.learnPDAG(mgraph);
924 }

References algoFCI_, algoMiic_, algoPC_, FCI, GUM_ERROR, MIIC, mutualInfo_, PC, prepareFCI_(), prepareMiic_(), preparePC_(), scoreDatabase_, and selectedAlgo_.

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

1375 {
1376 createPrior_();
1377 gum::learning::ScoreLog2Likelihood ll2score(scoreDatabase_.parser(), *prior_, databaseRanges());
1378
1379 std::vector< NodeId > total(vars);
1380 total.insert(total.end(), knowing.begin(), knowing.end());
1381 double LLtotal = ll2score.score(IdCondSet(total, false, true));
1382 if (knowing.size() == (Size)0) {
1383 return LLtotal;
1384 } else {
1385 double LLknw = ll2score.score(IdCondSet(knowing, false, true));
1386 return LLtotal - LLknw;
1387 }
1388 }

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

Referenced by logLikelihood().

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

◆ logLikelihood() [2/2]

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

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

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

Definition at line 1390 of file IBNLearner.cpp.

1391 {
1392 std::vector< NodeId > ids;
1393 std::vector< NodeId > knowingIds;
1394
1395 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1396
1397 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1398 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1399
1400 return logLikelihood(ids, knowingIds);
1401 }
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 854 of file IBNLearner_inl.h.

854 {
855 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxIter();
856 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
857 }

References currentAlgorithm_, and GUM_ERROR.

◆ maxTime()

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

returns the timeout (in seconds)

Implements gum::IApproximationSchemeConfiguration.

Definition at line 885 of file IBNLearner_inl.h.

885 {
886 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->maxTime();
887 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
888 }

References currentAlgorithm_, and GUM_ERROR.

◆ 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::credal::InferenceEngine< GUM_SCALAR >::getApproximationSchemeMsg(), and gum::credal::MultipleInferenceEngine< GUM_SCALAR, LazyPropagation< GUM_SCALAR > >::isEnabledMaxIter().

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

823 {
824 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->minEpsilonRate();
825 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
826 }

References currentAlgorithm_, and GUM_ERROR.

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

1442 {
1443 const auto prior = NoPrior(scoreDatabase_.databaseTable(), scoreDatabase_.nodeId2Columns());
1444 gum::learning::CorrectedMutualInformation cmi(scoreDatabase_.parser(), prior, databaseRanges());
1445 cmi.useNoCorr();
1446
1447 if (knowing.size() == (Size)0) return cmi.score(id1, id2) / scoreDatabase_.weight();
1448 else return cmi.score(id1, id2, knowing) / scoreDatabase_.weight();
1449 }

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

Referenced by mutualInformation().

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

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

1453 {
1454 std::vector< NodeId > knowingIds;
1455
1456 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1457
1458 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1459
1460 return mutualInformation(this->idFromName(var1), this->idFromName(var2), knowingIds);
1461 }
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 141 of file IBNLearner_inl.h.

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

References scoreDatabase_.

◆ names()

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

returns the names of the variables in the database

Definition at line 705 of file IBNLearner_inl.h.

705 {
706 return scoreDatabase_.names();
707 }

References scoreDatabase_.

◆ nbCols()

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

Definition at line 736 of file IBNLearner_inl.h.

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

References scoreDatabase_.

◆ nbrIterations()

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

Implements gum::IApproximationSchemeConfiguration.

Definition at line 944 of file IBNLearner_inl.h.

944 {
945 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->nbrIterations();
946 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
947 }

References currentAlgorithm_, and GUM_ERROR.

◆ nbRows()

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

Definition at line 738 of file IBNLearner_inl.h.

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

References scoreDatabase_.

◆ operator=() [1/2]

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

copy operator

Definition at line 280 of file IBNLearner.cpp.

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

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

Here is the call graph for this function:

◆ operator=() [2/2]

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

move operator

Definition at line 336 of file IBNLearner.cpp.

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

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

Here is the call graph for this function:

◆ periodSize()

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

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

References currentAlgorithm_, and GUM_ERROR.

◆ prepareFCI_()

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

prepares the initial graph and independence test for FCI

Definition at line 803 of file IBNLearner.cpp.

803 {
804 MixedGraph mgraph;
805 DiGraph forbiddenGraph;
806 DAG mandatoryGraph;
807
808 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
809 mgraph.addNodeWithId(i);
810 forbiddenGraph.addNodeWithId(i);
811 mandatoryGraph.addNodeWithId(i);
812 }
813
814 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
815 if (possible_edges.empty()) {
816 for (const NodeId i: mgraph.nodes()) {
817 for (NodeId j = 0; j < i; ++j) {
818 mgraph.addEdge(j, i);
819 }
820 }
821 } else {
822 for (const auto& edge: possible_edges) {
823 mgraph.addEdge(edge.first(), edge.second());
824 }
825 }
826
827 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
828 mandatoryGraph.addArc(arc.tail(), arc.head());
829 forbiddenGraph.addArc(arc.head(), arc.tail());
830 }
831 for (const auto& arc: constraintForbiddenArcs_.arcs()) {
832 forbiddenGraph.addArc(arc.tail(), arc.head());
833 }
834
835 const gum::NodeProperty< gum::Size > sliceOrder = constraintSliceOrder_.sliceOrder();
836 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
837 for (const auto& [n1, r1]: sliceOrder) {
838 for (const auto& [n2, r2]: copyOrder) {
839 if (r1 > r2) {
840 forbiddenGraph.addArc(n1, n2);
841 } else if (r2 > r1) {
842 forbiddenGraph.addArc(n2, n1);
843 }
844 }
845 copyOrder.erase(n1);
846 }
847
848 const auto& totalOrder = constraintTotalOrder_.totalOrder();
849 for (auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
850 for (auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
851 forbiddenGraph.addArc(*iter2, *iter1);
852 }
853 }
854
855 for (const auto node: constraintNoParentNodes_.nodes()) {
856 for (const auto node2: mgraph.nodes()) {
857 if (node != node2) { forbiddenGraph.addArc(node2, node); }
858 }
859 }
860 for (const auto node: constraintNoChildrenNodes_.nodes()) {
861 for (const auto node2: mgraph.nodes()) {
862 if (node != node2) { forbiddenGraph.addArc(node, node2); }
863 }
864 }
865
866 if (indepTestFCI_) {
867 delete indepTestFCI_;
868 indepTestFCI_ = nullptr;
869 }
871 indepTestFCI_ = new IndepTestChi2(scoreDatabase_.parser(),
872 *noPrior_,
873 ranges_,
874 scoreDatabase_.nodeId2Columns());
875 } else {
876 indepTestFCI_ = new IndepTestG2(scoreDatabase_.parser(),
877 *noPrior_,
878 ranges_,
879 scoreDatabase_.nodeId2Columns());
880 }
881
882 algoFCI_.setMaxIndegree(constraintIndegree_.maxIndegree());
883 algoFCI_.setMandatoryGraph(mandatoryGraph);
884 algoFCI_.setForbiddenGraph(forbiddenGraph);
885 algoFCI_.setIndependenceTest(*indepTestFCI_);
886 algoFCI_.setAlpha(alphaFci_);
887 algoFCI_.setMaxPathLength(maxPathLengthFci_);
888 algoFCI_.setExhaustiveSepSet(exhaustiveSepSetFci_);
889
890 return mgraph;
891 }
IndepTestType indepTestTypeFCI_
independence test type for FCI (reuses IndepTestType defined above)
double alphaFci_
FCI parameters.
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

References gum::DAG::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoFCI_, alphaFci_, Chi2, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTotalOrder_, gum::Set< Key >::empty(), exhaustiveSepSetFci_, indepTestFCI_, indepTestTypeFCI_, maxPathLengthFci_, gum::NodeGraphPart::nodes(), noPrior_, ranges_, and scoreDatabase_.

Referenced by 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 611 of file IBNLearner.cpp.

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

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

Referenced by learnDag_(), and learnPDAG_().

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

◆ preparePC_()

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

prepares the initial graph and independence test for PC

Definition at line 710 of file IBNLearner.cpp.

710 {
711 MixedGraph mgraph;
712 DiGraph forbiddenGraph;
713 DAG mandatoryGraph;
714
715 for (Size i = 0; i < scoreDatabase_.databaseTable().nbVariables(); ++i) {
716 mgraph.addNodeWithId(i);
717 forbiddenGraph.addNodeWithId(i);
718 mandatoryGraph.addNodeWithId(i);
719 }
720
721 const EdgeSet& possible_edges = constraintPossibleEdges_.edges();
722 if (possible_edges.empty()) {
723 for (const NodeId i: mgraph.nodes()) {
724 for (NodeId j = 0; j < i; ++j) {
725 mgraph.addEdge(j, i);
726 }
727 }
728 } else {
729 for (const auto& edge: possible_edges) {
730 mgraph.addEdge(edge.first(), edge.second());
731 }
732 }
733
734 for (const auto& arc: constraintMandatoryArcs_.arcs()) {
735 mandatoryGraph.addArc(arc.tail(), arc.head());
736 forbiddenGraph.addArc(arc.head(), arc.tail());
737 }
738 for (const auto& arc: constraintForbiddenArcs_.arcs()) {
739 forbiddenGraph.addArc(arc.tail(), arc.head());
740 }
741
742 const gum::NodeProperty< gum::Size > sliceOrder = constraintSliceOrder_.sliceOrder();
743 gum::NodeProperty< gum::Size > copyOrder = gum::HashTable(sliceOrder);
744 for (const auto& [n1, r1]: sliceOrder) {
745 for (const auto& [n2, r2]: copyOrder) {
746 if (r1 > r2) {
747 forbiddenGraph.addArc(n1, n2);
748 } else if (r2 > r1) {
749 forbiddenGraph.addArc(n2, n1);
750 }
751 }
752 copyOrder.erase(n1);
753 }
754
755 const auto& totalOrder = constraintTotalOrder_.totalOrder();
756 for (auto iter1 = totalOrder.begin(); iter1 != totalOrder.end(); ++iter1) {
757 for (auto iter2 = iter1 + 1; iter2 != totalOrder.end(); ++iter2) {
758 forbiddenGraph.addArc(*iter2, *iter1);
759 }
760 }
761
762 for (const auto node: constraintNoParentNodes_.nodes()) {
763 for (const auto node2: mgraph.nodes()) {
764 if (node != node2) { forbiddenGraph.addArc(node2, node); }
765 }
766 }
767 for (const auto node: constraintNoChildrenNodes_.nodes()) {
768 for (const auto node2: mgraph.nodes()) {
769 if (node != node2) { forbiddenGraph.addArc(node, node2); }
770 }
771 }
772
773 // build the independence test (owned by IBNLearner)
774 if (indepTestPC_) {
775 delete indepTestPC_;
776 indepTestPC_ = nullptr;
777 }
779 indepTestPC_ = new IndepTestChi2(scoreDatabase_.parser(),
780 *noPrior_,
781 ranges_,
782 scoreDatabase_.nodeId2Columns());
783 } else {
784 indepTestPC_ = new IndepTestG2(scoreDatabase_.parser(),
785 *noPrior_,
786 ranges_,
787 scoreDatabase_.nodeId2Columns());
788 }
789
790 algoPC_.setMaxIndegree(constraintIndegree_.maxIndegree());
791 algoPC_.setMandatoryGraph(mandatoryGraph);
792 algoPC_.setForbiddenGraph(forbiddenGraph);
793 algoPC_.setIndependenceTest(*indepTestPC_);
794 algoPC_.setAlpha(alphaPc_);
795 algoPC_.setStable(stablePc_);
796 algoPC_.setMaxCondSetSize(maxCondSetSizePc_);
799
800 return mgraph;
801 }
@ Sorted
descending p-value order (strongest evidence first)
@ Standard
process triples in natural traversal order
double alphaPc_
PC parameters.
IndepTestType indepTestTypePC_

References gum::DAG::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), algoPC_, alphaPc_, Chi2, constraintForbiddenArcs_, constraintIndegree_, constraintMandatoryArcs_, constraintNoChildrenNodes_, constraintNoParentNodes_, constraintPossibleEdges_, constraintSliceOrder_, constraintTotalOrder_, gum::Set< Key >::empty(), indepTestPC_, indepTestTypePC_, maxCondSetSizePc_, gum::NodeGraphPart::nodes(), noPrior_, ranges_, scoreDatabase_, gum::learning::CIBasedLearning::Sorted, sortedUCPc_, stablePc_, and gum::learning::CIBasedLearning::Standard.

Referenced by learnDag_(), and learnPDAG_().

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

◆ prepareSimpleMiic_()

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

prepares the initial graph for Simple Miic

◆ rawPseudoCount() [1/2]

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

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

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

Definition at line 1481 of file IBNLearner.cpp.

1481 {
1482 if (this->hasMissingValues()) {
1483 GUM_ERROR(MissingValueInDatabase,
1484 "BNLearner cannot compute pseudo-counts with missing values in the database")
1485 }
1486 if (vars.empty()) {
1487 GUM_ERROR(OutOfBounds, "BNLearner::rawPseudoCount called with an empty vector of variables")
1488 }
1489 Tensor< double > res;
1490
1491 createPrior_();
1492 gum::learning::PseudoCount count(scoreDatabase_.parser(), *prior_, databaseRanges());
1493 return count.get(vars);
1494 }
bool hasMissingValues() const
returns true if the learner's database has missing values

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

Referenced by rawPseudoCount().

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

◆ rawPseudoCount() [2/2]

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

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

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

Definition at line 1496 of file IBNLearner.cpp.

1496 {
1497 std::vector< NodeId > ids;
1498
1499 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1500
1501 std::transform(vars.begin(), vars.end(), std::back_inserter(ids), mapper);
1502 return rawPseudoCount(ids);
1503 }
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 446 of file IBNLearner.cpp.

447 {
448 // get the extension of the file
449 isCSVFileName_(filename);
450
451 DBInitializerFromCSV initializer{std::string(filename)};
452
453 const auto& var_names = initializer.variableNames();
454 const std::size_t nb_vars = var_names.size();
455
456 DBTranslatorSet translator_set;
457 DBTranslator4LabelizedVariable translator(missing_symbols);
458 for (std::size_t i = 0; i < nb_vars; ++i) {
459 translator_set.insertTranslator(translator, i);
460 }
461
462 DatabaseTable database(missing_symbols, translator_set);
463 database.setVariableNames(initializer.variableNames());
464 initializer.fillDatabase(database);
465
466 database.reorder();
467
468 return database;
469 }
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_(), 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 156 of file IBNLearner_inl.h.

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

References scoreDatabase_.

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

1463 {
1464 createPrior_();
1465 createScore_();
1466
1467 return score_->score(var, knowing);
1468 }

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

Referenced by score(), and useDatabaseRanges().

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

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

1470 {
1471 auto mapper = [this](const std::string& c) { return this->idFromName(c); };
1472
1473 const NodeId id = this->idFromName(var);
1474 std::vector< NodeId > knowingIds;
1475 knowingIds.reserve(knowing.size());
1476 std::transform(knowing.begin(), knowing.end(), std::back_inserter(knowingIds), mapper);
1477
1478 return score(id, knowingIds);
1479 }
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 767 of file IBNLearner_inl.h.

767 {
768 currentAlgorithm_ = approximationScheme;
769 }

References currentAlgorithm_.

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

Here is the caller graph for this function:

◆ setDatabaseWeight()

INLINE void gum::learning::IBNLearner::setDatabaseWeight ( const double new_weight)

assign a weight to all the rows of the learning database so that the sum of their weights is equal to new_weight

assign new weight to the rows of the learning database

Definition at line 146 of file IBNLearner_inl.h.

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

References scoreDatabase_.

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

785 {
786 algoK2_.approximationScheme().setEpsilon(eps);
787 greedyHillClimbing_.setEpsilon(eps);
788 localSearchWithTabuList_.setEpsilon(eps);
789 dag2BN_.setEpsilon(eps);
790 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setFCIAlpha()

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

set the significance threshold alpha for FCI (default 0.05)

Exceptions
OperationNotAllowedwhen FCI is not the selected algorithm

Definition at line 247 of file IBNLearner_inl.h.

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

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

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

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

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

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

512 {
513 constraintForbiddenArcs_.setArcs(set);
514 }

References constraintForbiddenArcs_.

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

377 {
378 greedyThickThinning_.setAllowReversalsInThinPhase(allow);
379 }

References greedyThickThinning_.

◆ setInitialDAG()

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

sets an initial DAG structure

Definition at line 164 of file IBNLearner_inl.h.

164{ initialDag_ = dag; }

References initialDag_.

◆ setMandatoryArcs()

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

assign a set of mandatory arcs

Definition at line 545 of file IBNLearner_inl.h.

545 {
546 constraintMandatoryArcs_.setArcs(set);
547 }

References constraintMandatoryArcs_.

◆ setMaxIndegree()

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

sets the max indegree

Definition at line 217 of file IBNLearner_inl.h.

217 {
218 constraintIndegree_.setMaxIndegree(max_indegree);
219 }

References constraintIndegree_.

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

847 {
848 algoK2_.approximationScheme().setMaxIter(max);
849 greedyHillClimbing_.setMaxIter(max);
850 localSearchWithTabuList_.setMaxIter(max);
851 dag2BN_.setMaxIter(max);
852 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

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

878 {
879 algoK2_.approximationScheme().setMaxTime(timeout);
880 greedyHillClimbing_.setMaxTime(timeout);
881 localSearchWithTabuList_.setMaxTime(timeout);
882 dag2BN_.setMaxTime(timeout);
883 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

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

816 {
817 algoK2_.approximationScheme().setMinEpsilonRate(rate);
818 greedyHillClimbing_.setMinEpsilonRate(rate);
819 localSearchWithTabuList_.setMinEpsilonRate(rate);
820 dag2BN_.setMinEpsilonRate(rate);
821 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setNumberOfThreads()

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

sets the number max of threads that can be used

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

Implements gum::IThreadNumberManager.

Definition at line 741 of file IBNLearner_inl.h.

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

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

Here is the call graph for this function:

◆ setPCAlpha()

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

set the significance threshold alpha for PC (default 0.05)

Exceptions
OperationNotAllowedwhen PC is not the selected algorithm

Definition at line 296 of file IBNLearner_inl.h.

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

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

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

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

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

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

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

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

914 {
915 algoK2_.approximationScheme().setPeriodSize(p);
916 greedyHillClimbing_.setPeriodSize(p);
917 localSearchWithTabuList_.setPeriodSize(p);
918 dag2BN_.setPeriodSize(p);
919 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ setPossibleEdges()

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

assign a set of possible edges

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

Definition at line 472 of file IBNLearner_inl.h.

472 {
473 constraintPossibleEdges_.setEdges(set);
474 }

References constraintPossibleEdges_.

Referenced by setPossibleSkeleton().

Here is the caller graph for this function:

◆ setPossibleSkeleton()

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

assign a set of possible edges

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

Definition at line 477 of file IBNLearner_inl.h.

477 {
478 setPossibleEdges(g.edges());
479 }
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 151 of file IBNLearner_inl.h.

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

References scoreDatabase_.

◆ setSliceOrder() [1/2]

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

sets a partial order on the nodes

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

Definition at line 608 of file IBNLearner_inl.h.

608 {
609 constraintSliceOrder_ = StructuralConstraintSliceOrder(slice_order);
610 }

References constraintSliceOrder_.

Referenced by setSliceOrder(), and unsetSliceOrder().

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

612 {
613 NodeProperty< NodeId > slice_order;
614 NodeId rank = 0;
615 for (const auto& slice: slices) {
616 for (const auto& name: slice) {
617 slice_order.insert(idFromName(name), rank);
618 }
619 rank++;
620 }
621 setSliceOrder(slice_order);
622 }
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 627 of file IBNLearner_inl.h.

627 {
628 constraintTotalOrder_ = StructuralConstraintTotalOrder(order);
629 }

References constraintTotalOrder_.

Referenced by setTotalOrder(), and unsetTotalOrder().

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

632 {
633 Sequence< NodeId > sequence;
634 for (const auto& name: order) {
635 sequence.insert(idFromName(name));
636 }
637 setTotalOrder(sequence);
638 }
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 926 of file IBNLearner_inl.h.

926 {
927 algoK2_.approximationScheme().setVerbosity(v);
928 greedyHillClimbing_.setVerbosity(v);
929 localSearchWithTabuList_.setVerbosity(v);
930 dag2BN_.setVerbosity(v);
931 }

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ stateApproximationScheme()

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

history

Implements gum::IApproximationSchemeConfiguration.

Definition at line 939 of file IBNLearner_inl.h.

939 {
940 if (currentAlgorithm_ != nullptr) return currentAlgorithm_->stateApproximationScheme();
941 else GUM_ERROR(FatalError, "No chosen algorithm for learning")
942 }

References currentAlgorithm_, and GUM_ERROR.

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

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

References setTotalOrder().

Here is the call graph for this function:

◆ useBDeuPrior()

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

use the BDeu prior

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

Definition at line 679 of file IBNLearner_inl.h.

679 {
680 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
681
683 _setPriorWeight_(weight);
684
686 }
void _setPriorWeight_(double weight)
sets the prior weight

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

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

280 {
282 GUM_ERROR(OperationNotAllowed, "useChi2Test() is only valid when using the PC algorithm")
283 }
285 }

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

1300 {
1301 if (k_fold == 0) { GUM_ERROR(OutOfBounds, "K-fold cross validation with k=0 is forbidden") }
1302
1303 if (learning_fold >= k_fold) {
1304 GUM_ERROR(OutOfBounds,
1305 "In " << k_fold << "-fold cross validation, the learning "
1306 << "fold should be strictly lower than " << k_fold
1307 << " but, here, it is equal to " << learning_fold)
1308 }
1309
1310 const std::size_t db_size = scoreDatabase_.databaseTable().nbRows();
1311 if (k_fold >= db_size) {
1312 GUM_ERROR(OutOfBounds,
1313 "In " << k_fold << "-fold cross validation, the database's "
1314 << "size should be strictly greater than " << k_fold
1315 << " but, here, the database has only " << db_size << "rows")
1316 }
1317
1318 // create the ranges of rows of the test database
1319 const std::size_t foldSize = db_size / k_fold;
1320 const std::size_t unfold_deb = learning_fold * foldSize;
1321 const std::size_t unfold_end = unfold_deb + foldSize;
1322
1323 ranges_.clear();
1324 if (learning_fold == std::size_t(0)) {
1325 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1326 } else {
1327 ranges_.push_back(std::pair< std::size_t, std::size_t >(std::size_t(0), unfold_deb));
1328
1329 if (learning_fold != k_fold - 1) {
1330 ranges_.push_back(std::pair< std::size_t, std::size_t >(unfold_end, db_size));
1331 }
1332 }
1333
1334 return std::pair< std::size_t, std::size_t >(unfold_deb, unfold_end);
1335 }

References GUM_ERROR, ranges_, and scoreDatabase_.

◆ useDatabaseRanges()

void gum::learning::IBNLearner::useDatabaseRanges ( const std::vector< std::pair< std::size_t, std::size_t > > & new_ranges)

use a new set of database rows' ranges to perform learning

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

Definition at line 1506 of file IBNLearner.cpp.

1507 {
1508 // use a score to detect whether the ranges are ok
1509 ScoreLog2Likelihood score(scoreDatabase_.parser(), *noPrior_);
1510 score.setRanges(new_ranges);
1511 ranges_ = score.ranges();
1512 }

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

Here is the call graph for this function:

◆ useDirichletPrior()

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

use the Dirichlet prior from a database

Definition at line 668 of file IBNLearner_inl.h.

668 {
669 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
670
671 priorDbname_ = filename;
673 _setPriorWeight_(weight);
674
676 }

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

Here is the call graph for this function:

◆ useEM()

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

use The EM algorithm to learn parameters

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

Definition at line 395 of file IBNLearner_inl.h.

395 {
396 if (epsilon < 0.0)
397 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be non-negative");
398 if ((noise < 0.0) || (noise > 1.0))
399 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
400 if (epsilon > 0) {
401 useEM_ = true;
402 dag2BN_.setMinEpsilonRate(epsilon);
403 dag2BN_.setNoise(noise);
404 noiseEM_ = noise;
405 } else {
406 useEM_ = false; // epsilon == 0
407 }
408 }
double epsilon() const override
Get the value of epsilon.

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

Referenced by useEMWithRateCriterion().

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

◆ useEMWithDiffCriterion()

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

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

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

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

Definition at line 418 of file IBNLearner_inl.h.

418 {
419 if (epsilon <= 0.0)
420 GUM_ERROR(OutOfBounds, "EM's min log-likelihood differences must be positive");
421 if ((noise < 0.0) || (noise > 1.0))
422 GUM_ERROR(OutOfBounds, "EM's noise must belong to interval [0,1]");
423 useEM_ = true;
424 dag2BN_.setEpsilon(epsilon);
425 dag2BN_.setNoise(noise);
426 noiseEM_ = noise;
427 }

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

Here is the call graph for this function:

◆ useEMWithRateCriterion()

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

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

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

Definition at line 411 of file IBNLearner_inl.h.

411 {
412 if (epsilon <= 0.0)
413 GUM_ERROR(OutOfBounds, "EM's min log-likelihood evolution rate must be positive");
414 useEM(epsilon, noise);
415 }
void useEM(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters

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

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

231 {
233 GUM_ERROR(OperationNotAllowed, "useFCIChi2Test() is only valid when using the FCI algorithm")
234 }
236 }

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

239 {
241 GUM_ERROR(OperationNotAllowed, "useFCIG2Test() is only valid when using the FCI algorithm")
242 }
244 }

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

288 {
290 GUM_ERROR(OperationNotAllowed, "useG2Test() is only valid when using the PC algorithm")
291 }
293 }

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 362 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 372 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 350 of file IBNLearner_inl.h.

350 {
352 algoK2_.setOrder(order);
353 }

References algoK2_, K2, and selectedAlgo_.

◆ useK2() [2/2]

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

indicate that we wish to use K2

Definition at line 356 of file IBNLearner_inl.h.

356 {
358 algoK2_.setOrder(order);
359 }

References algoK2_, K2, and selectedAlgo_.

◆ useLocalSearchWithTabuList()

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

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

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

Definition at line 387 of file IBNLearner_inl.h.

387 {
389 nbDecreasingChanges_ = nb_decrease;
390 constraintTabuList_.setTabuListSize(tabu_size);
391 localSearchWithTabuList_.setMaxNbDecreasingChanges(nb_decrease);
392 }

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

◆ 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 335 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 222 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 330 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 340 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 652 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 225 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 169 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 175 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 181 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 187 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 193 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 199 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 205 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 211 of file IBNLearner_inl.h.

References checkScorePriorCompatibility(), MDL, and scoreType_.

Here is the call graph for this function:

◆ useSmoothingPrior()

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

use the prior smoothing

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

Definition at line 658 of file IBNLearner_inl.h.

658 {
659 if (weight < 0) { GUM_ERROR(OutOfBounds, "the weight of the prior must be positive") }
660
662 _setPriorWeight_(weight);
663
665 }

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

Here is the call graph for this function:

◆ verbosity()

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

verbosity

Implements gum::IApproximationSchemeConfiguration.

Definition at line 933 of file IBNLearner_inl.h.

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

References currentAlgorithm_, and GUM_ERROR.

Member Data Documentation

◆ _nb_threads_

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

the max number of threads used by the class

Definition at line 126 of file threadNumberManager.h.

126{0};

◆ algoFCI_

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

the FCI algorithm

Definition at line 1222 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 1199 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 1206 of file IBNLearner.h.

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

◆ algoSimpleMiic_

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

the MIIC algorithm

Definition at line 1196 of file IBNLearner.h.

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

◆ allowArcAdditions_

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

whether we allow or not arc additions during learning

Definition at line 1181 of file IBNLearner.h.

1181{true};

Referenced by allowArcAdditions(), and learnDag_().

◆ allowArcDeletions_

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

whether we allow or not arc deletions during learning

Definition at line 1184 of file IBNLearner.h.

1184{true};

Referenced by allowArcDeletions(), and learnDag_().

◆ allowArcReversals_

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

whether we allow or not arc reversals during learning

Definition at line 1187 of file IBNLearner.h.

1187{true};

Referenced by allowArcReversals(), and learnDag_().

◆ allowArcTriangleDeletions_

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

whether we allow or not arc deletions during learning

Definition at line 1190 of file IBNLearner.h.

1190{true};

Referenced by allowArcTriangleDeletions(), and learnDag_().

◆ alphaFci_

double gum::learning::IBNLearner::alphaFci_ {0.05}
protected

FCI parameters.

Definition at line 1231 of file IBNLearner.h.

1231{0.05};

Referenced by prepareFCI_(), and setFCIAlpha().

◆ alphaPc_

double gum::learning::IBNLearner::alphaPc_ {0.05}
protected

PC parameters.

Definition at line 1216 of file IBNLearner.h.

1216{0.05};

Referenced by preparePC_(), and setPCAlpha().

◆ constraintForbiddenArcs_

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

◆ constraintIndegree_

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

the constraint for indegrees

Definition at line 1157 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 1175 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 1172 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 1166 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 1151 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 1160 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 1154 of file IBNLearner.h.

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

◆ currentAlgorithm_

◆ dag2BN_

◆ default_EM_noise

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

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

Definition at line 135 of file IBNLearner.h.

135{0.1};

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

◆ exhaustiveSepSetFci_

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

Definition at line 1233 of file IBNLearner.h.

1233{false};

Referenced by fciExhaustiveSepSet(), prepareFCI_(), and setFCIExhaustiveSepSet().

◆ extendedGreedyHillClimbing_

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

the extended greedy hill climbing

Definition at line 1242 of file IBNLearner.h.

Referenced by learnDag_().

◆ filename_

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

the filename database

Definition at line 1266 of file IBNLearner.h.

1266{"-"};

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

Referenced by greedyThickThinningReversals(), learnDag_(), and setGreedyThickThinningReversals().

◆ indepTestFCI_

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

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

Definition at line 1228 of file IBNLearner.h.

1228{nullptr};

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

1213{nullptr};

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

Referenced by prepareFCI_(), useFCIChi2Test(), and useFCIG2Test().

◆ indepTestTypePC_

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

Definition at line 1210 of file IBNLearner.h.

Referenced by preparePC_(), useChi2Test(), and useG2Test().

◆ inducedTypes_

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

the policy for typing variables

Definition at line 1119 of file IBNLearner.h.

1119{false};

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

◆ initialDag_

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

an initial DAG given to learners

Definition at line 1263 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

Definition at line 1218 of file IBNLearner.h.

1218{Size(-1)};

Referenced by preparePC_(), and setPCMaxCondSetSize().

◆ maxPathLengthFci_

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

Definition at line 1232 of file IBNLearner.h.

1232{Size(-1)};

Referenced by prepareFCI_(), and setFCIMaxPathLength().

◆ mutualInfo_

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

the selected correction for miic

Definition at line 1137 of file IBNLearner.h.

1137{nullptr};

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

◆ nbDecreasingChanges_

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

Definition at line 1269 of file IBNLearner.h.

1269{2};

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

◆ noiseEM_

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

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

Definition at line 1134 of file IBNLearner.h.

1134{0.1};

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

◆ noPrior_

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

◆ 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 1128 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 1257 of file IBNLearner.h.

1257{nullptr};

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

◆ priorDbname_

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

the filename for the Dirichlet a priori, if any

Definition at line 1260 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 1140 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

Definition at line 1148 of file IBNLearner.h.

1148{1.0f};

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

◆ ranges_

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

◆ score_

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

the score used

Definition at line 1125 of file IBNLearner.h.

1125{nullptr};

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

◆ scoreDatabase_

◆ scoreType_

◆ selectedAlgo_

◆ sortedUCPc_

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

Definition at line 1219 of file IBNLearner.h.

1219{false};

Referenced by preparePC_(), and setPCUnshieldedColliderSorted().

◆ stablePc_

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

Definition at line 1217 of file IBNLearner.h.

1217{true};

Referenced by preparePC_(), and setPCStable().

◆ useEM_

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

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

Definition at line 1131 of file IBNLearner.h.

1131{false};

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


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