aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::learning::BNLearner< GUM_SCALAR > Class Template Referencefinal

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

#include <BNLearner.h>

Inheritance diagram for gum::learning::BNLearner< GUM_SCALAR >:
Collaboration diagram for gum::learning::BNLearner< GUM_SCALAR >:

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

BayesNet< GUM_SCALAR > learnBN ()
 learn a Bayes Net from a file (must have read the db before)
BayesNet< GUM_SCALAR > learnParameters (const DAG &dag, bool takeIntoAccountScore=true)
 learns a BN (its parameters) with the structure passed in argument
BayesNet< GUM_SCALAR > learnParameters (const BayesNet< GUM_SCALAR > &bn, bool takeIntoAccountScore=true)
 learns a BN (its parameters) with the BN structure passed in argument, EM being initialized by this argument
BayesNet< GUM_SCALAR > learnParameters (bool take_into_account_score=true)
 learns a BN (its parameters) when its structure is known
std::string toString () const
std::vector< std::tuple< std::string, std::string, std::string > > state () const
void copyState (const BNLearner< GUM_SCALAR > &learner)
 copy the states of the BNLearner
BNLearner< GUM_SCALAR > & setInitialDAG (const DAG &dag)
BNLearner< GUM_SCALAR > & useEM (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters
BNLearner< GUM_SCALAR > & useEMWithRateCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the rate stopping criterion
BNLearner< GUM_SCALAR > & useEMWithDiffCriterion (const double epsilon, const double noise=default_EM_noise)
 use The EM algorithm to learn parameters with the diff stopping criterion
BNLearner< GUM_SCALAR > & forbidEM ()
 prevent using the EM algorithm for parameter learning
BNLearner< GUM_SCALAR > & EMsetEpsilon (const double eps)
 sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelihoods
BNLearner< GUM_SCALAR > & EMdisableEpsilon ()
 Disable the min log-likelihood diff stopping criterion.
BNLearner< GUM_SCALAR > & EMenableEpsilon ()
 Enable the log-likelihood min diff stopping criterion in EM.
BNLearner< GUM_SCALAR > & EMsetMinEpsilonRate (const double rate)
 sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate
BNLearner< GUM_SCALAR > & EMdisableMinEpsilonRate ()
 Disable the log-likelihood evolution rate stopping criterion.
BNLearner< GUM_SCALAR > & EMenableMinEpsilonRate ()
 Enable the log-likelihood evolution rate stopping criterion.
BNLearner< GUM_SCALAR > & EMsetMaxIter (const Size max)
 add a max iteration stopping criterion
BNLearner< GUM_SCALAR > & EMdisableMaxIter ()
 Disable stopping criterion on max iterations.
BNLearner< GUM_SCALAR > & EMenableMaxIter ()
 Enable stopping criterion on max iterations.
BNLearner< GUM_SCALAR > & EMsetMaxTime (const double timeout)
 add a stopping criterion on timeout
BNLearner< GUM_SCALAR > & EMdisableMaxTime ()
 Disable EM's timeout stopping criterion.
BNLearner< GUM_SCALAR > & EMenableMaxTime ()
 enable EM's timeout stopping criterion
BNLearner< GUM_SCALAR > & EMsetPeriodSize (const Size p)
 how many samples between 2 stoppings isEnabled
BNLearner< GUM_SCALAR > & EMsetVerbosity (const bool v)
 sets or unsets EM's verbosity
BNLearner< GUM_SCALAR > & useScoreAIC ()
BNLearner< GUM_SCALAR > & useScoreBD ()
BNLearner< GUM_SCALAR > & useScoreBDeu ()
BNLearner< GUM_SCALAR > & useScoreBIC ()
BNLearner< GUM_SCALAR > & useScoreK2 ()
BNLearner< GUM_SCALAR > & useScoreLog2Likelihood ()
BNLearner< GUM_SCALAR > & useNoPrior ()
BNLearner< GUM_SCALAR > & useBDeuPrior (double weight=1.0)
BNLearner< GUM_SCALAR > & useSmoothingPrior (double weight=1)
BNLearner< GUM_SCALAR > & useDirichletPrior (std::string_view filename, double weight=1)
BNLearner< GUM_SCALAR > & useDirichletPrior (const gum::BayesNet< GUM_SCALAR > &bn, double weight=1)
BNLearner< GUM_SCALAR > & useGreedyHillClimbing ()
BNLearner< GUM_SCALAR > & useExtendedGreedyHillClimbing ()
BNLearner< GUM_SCALAR > & useGreedyThickThinning ()
BNLearner< GUM_SCALAR > & setGreedyThickThinningReversals (bool allow)
bool greedyThickThinningReversals () const
BNLearner< GUM_SCALAR > & useLocalSearchWithTabuList (Size tabu_size=100, Size nb_decrease=2)
BNLearner< GUM_SCALAR > & useK2 (const Sequence< NodeId > &order)
BNLearner< GUM_SCALAR > & useK2 (const std::vector< NodeId > &order)
BNLearner< GUM_SCALAR > & useMIIC ()
BNLearner< GUM_SCALAR > & usePC ()
BNLearner< GUM_SCALAR > & useFCI ()
BNLearner< GUM_SCALAR > & useFCIChi2Test ()
BNLearner< GUM_SCALAR > & useFCIG2Test ()
BNLearner< GUM_SCALAR > & setFCIAlpha (double alpha)
BNLearner< GUM_SCALAR > & setFCIMaxPathLength (Size max_len)
BNLearner< GUM_SCALAR > & setFCIExhaustiveSepSet (bool exhaustive)
bool fciExhaustiveSepSet () const
BNLearner< GUM_SCALAR > & useChi2Test ()
BNLearner< GUM_SCALAR > & useG2Test ()
BNLearner< GUM_SCALAR > & setPCAlpha (double alpha)
BNLearner< GUM_SCALAR > & setPCStable (bool stable)
BNLearner< GUM_SCALAR > & setPCMaxCondSetSize (Size max_k)
BNLearner< GUM_SCALAR > & setPCUnshieldedColliderSorted (bool sorted)
BNLearner< GUM_SCALAR > & useNMLCorrection ()
BNLearner< GUM_SCALAR > & useMDLCorrection ()
BNLearner< GUM_SCALAR > & useNoCorrection ()
BNLearner< GUM_SCALAR > & setMaxIndegree (Size max_indegree)
BNLearner< GUM_SCALAR > & setSliceOrder (const NodeProperty< NodeId > &slice_order)
BNLearner< GUM_SCALAR > & setSliceOrder (const std::vector< std::vector< std::string > > &slices)
BNLearner< GUM_SCALAR > & setTotalOrder (const std::vector< std::string > &order)
BNLearner< GUM_SCALAR > & setTotalOrder (const Sequence< NodeId > &order)
BNLearner< GUM_SCALAR > & setForbiddenArcs (const ArcSet &set)
BNLearner< GUM_SCALAR > & addForbiddenArc (const Arc &arc)
BNLearner< GUM_SCALAR > & addForbiddenArc (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & addForbiddenArc (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & eraseForbiddenArc (const Arc &arc)
BNLearner< GUM_SCALAR > & eraseForbiddenArc (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & eraseForbiddenArc (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & addMandatoryArc (const Arc &arc)
BNLearner< GUM_SCALAR > & addMandatoryArc (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & addMandatoryArc (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & eraseMandatoryArc (const Arc &arc)
BNLearner< GUM_SCALAR > & eraseMandatoryArc (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & eraseMandatoryArc (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & addPossibleEdge (const Edge &edge)
BNLearner< GUM_SCALAR > & addPossibleEdge (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & addPossibleEdge (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & erasePossibleEdge (const Edge &edge)
BNLearner< GUM_SCALAR > & erasePossibleEdge (NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & erasePossibleEdge (std::string_view tail, std::string_view head)
BNLearner< GUM_SCALAR > & setMandatoryArcs (const ArcSet &set)
BNLearner< GUM_SCALAR > & setPossibleEdges (const EdgeSet &set)
BNLearner< GUM_SCALAR > & setPossibleSkeleton (const UndiGraph &skeleton)
BNLearner< GUM_SCALAR > & addNoParentNode (NodeId node)
BNLearner< GUM_SCALAR > & addNoParentNode (std::string_view name)
BNLearner< GUM_SCALAR > & eraseNoParentNode (NodeId node)
BNLearner< GUM_SCALAR > & eraseNoParentNode (std::string_view name)
BNLearner< GUM_SCALAR > & addNoChildrenNode (NodeId node)
BNLearner< GUM_SCALAR > & addNoChildrenNode (std::string_view name)
BNLearner< GUM_SCALAR > & eraseNoChildrenNode (NodeId node)
BNLearner< GUM_SCALAR > & eraseNoChildrenNode (std::string_view name)
BNLearner< GUM_SCALAR > & allowArcAdditions (bool allow)
BNLearner< GUM_SCALAR > & allowArcDeletions (bool allow)
BNLearner< GUM_SCALAR > & allowArcReversals (bool allow)
BNLearner< GUM_SCALAR > & allowArcTriangleDeletions (bool allow)
bool isConstraintBased () const
bool isScoreBased () const
Size EMPeriodSize () const
void unsetTotalOrder ()
 removes the current total ordering constraint, if any
Constructors / Destructors
 BNLearner (std::string_view filename, const std::vector< std::string > &missingSymbols={"?"}, const bool induceTypes=true)
 default constructor
 BNLearner (const DatabaseTable &db)
 default constructor
 BNLearner (std::string_view filename, const gum::BayesNet< GUM_SCALAR > &src, const std::vector< std::string > &missing_symbols={"?"})
 Wrapper for BNLearner (filename,modalities,parse_database) using a bn to find those modalities and nodeids.
 BNLearner (const BNLearner &)
 copy constructor
 BNLearner (BNLearner &&)
 move constructor
 ~BNLearner () override
 destructor
Operators
BNLearneroperator= (const BNLearner &)
 copy operator
BNLearneroperator= (BNLearner &&) noexcept
 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
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
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 useScorefNML ()
 indicate that we wish to use a fNML score
void useScoreMDL ()
 indicate that we wish to use a MDL score
a prior selection / parameterization
std::string checkScorePriorCompatibility () const
 checks whether the current score and prior are compatible
MIIC parameterization and specific results
std::vector< ArclatentVariables () const
 get the list of arcs hiding latent variables
Accessors / Modifiers for adding constraints on learning
void unsetSliceOrder ()
 removes the slice order constraint
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
double EMEpsilon () const
 Get the value of EM's min diff epsilon.
bool EMisEnabledEpsilon () const
 return true if EM's stopping criterion is the log-likelihood min diff
double EMMinEpsilonRate () const
 Get the value of the minimal log-likelihood evolution rate of EM.
bool EMisEnabledMinEpsilonRate () const
Size EMMaxIter () const
 return the max number of iterations criterion
bool EMisEnabledMaxIter () const
double EMMaxTime () const
 @brief returns EM's timeout (in milliseconds)
double EMCurrentTime () const
 get the current running time in second (double)
bool EMisEnabledMaxTime () const
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

void createPrior_ () override
 create the prior used for learning
PAG learnPAG_ ()
PDAG learnPDAG_ ()
void _setPriorWeight_ (double weight)
 sets the prior weight
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 Member Functions

NodeProperty< Sequence< std::string > > _labelsFromBN_ (std::string_view filename, const BayesNet< GUM_SCALAR > &src)
 read the first line of a file to find column names
void _checkDAGCompatibility_ (const DAG &dag)
 check that the database contains the nodes of the dag, else raise an exception
BayesNet< GUM_SCALAR > _learnParameters_ (const DAG &dag, bool takeIntoAccountScore)
 learns a BN (its parameters) with the structure passed in argument using a single pass estimation (not EM)
std::pair< std::shared_ptr< ParamEstimator >, std::shared_ptr< ParamEstimator > > _initializeEMParameterLearning_ (const DAG &dag, bool takeIntoAccountScore)
 initializes EM and returns a pair containing, first, a bootstrap estimator and, second, the EM estimator
BayesNet< GUM_SCALAR > _learnParametersWithEM_ (const DAG &dag, bool takeIntoAccountScore)
 learns a BN (its parameters) with the structure passed in argument using the EM algorithm initialized by the BNLearner
BayesNet< GUM_SCALAR > _learnParametersWithEM_ (const BayesNet< GUM_SCALAR > &bn, bool takeIntoAccountScore)
 learns a BN (its parameters) with the structure passed in argument using the EM algorithm initialized by the Bayes net passed in argument

Private Attributes

BayesNet< GUM_SCALAR > _prior_bn_
Size _nb_threads_ {0}
 the max number of threads used by the class

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::learning::BNLearner< GUM_SCALAR >

A pack of learning algorithms that can easily be used.

The pack currently contains K2, GreedyHillClimbing and LocalSearchWithTabuList

Definition at line 74 of file BNLearner.h.

Member Enumeration Documentation

◆ AlgoType

enum class gum::learning::IBNLearner::AlgoType
stronginherited

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
strongprotectedinherited

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

enum class gum::learning::IBNLearner::ScoreType
stronginherited

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

◆ BNLearner() [1/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::BNLearner ( std::string_view filename,
const std::vector< std::string > & missingSymbols = {"?"},
const bool induceTypes = true )

default constructor

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

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

Referenced by BNLearner(), BNLearner(), addForbiddenArc(), addForbiddenArc(), addForbiddenArc(), addMandatoryArc(), addMandatoryArc(), addMandatoryArc(), addNoChildrenNode(), addNoChildrenNode(), addNoParentNode(), addNoParentNode(), addPossibleEdge(), addPossibleEdge(), addPossibleEdge(), allowArcAdditions(), allowArcDeletions(), allowArcReversals(), allowArcTriangleDeletions(), copyState(), EMdisableEpsilon(), EMdisableMaxIter(), EMdisableMaxTime(), EMdisableMinEpsilonRate(), EMenableEpsilon(), EMenableMaxIter(), EMenableMaxTime(), EMenableMinEpsilonRate(), EMsetEpsilon(), EMsetMaxIter(), EMsetMaxTime(), EMsetMinEpsilonRate(), EMsetPeriodSize(), EMsetVerbosity(), eraseForbiddenArc(), eraseForbiddenArc(), eraseForbiddenArc(), eraseMandatoryArc(), eraseMandatoryArc(), eraseMandatoryArc(), eraseNoChildrenNode(), eraseNoChildrenNode(), eraseNoParentNode(), eraseNoParentNode(), erasePossibleEdge(), erasePossibleEdge(), erasePossibleEdge(), forbidEM(), operator=(), operator=(), setFCIAlpha(), setFCIExhaustiveSepSet(), setFCIMaxPathLength(), setForbiddenArcs(), setGreedyThickThinningReversals(), setInitialDAG(), setMandatoryArcs(), setMaxIndegree(), setPCAlpha(), setPCMaxCondSetSize(), setPCStable(), setPCUnshieldedColliderSorted(), setPossibleEdges(), setPossibleSkeleton(), setSliceOrder(), setTotalOrder(), setTotalOrder(), useBDeuPrior(), useChi2Test(), useDirichletPrior(), useDirichletPrior(), useEM(), useEMWithDiffCriterion(), useEMWithRateCriterion(), useExtendedGreedyHillClimbing(), useFCI(), useFCIChi2Test(), useFCIG2Test(), useG2Test(), useGreedyHillClimbing(), useGreedyThickThinning(), useK2(), useK2(), useLocalSearchWithTabuList(), useMDLCorrection(), useMIIC(), useNMLCorrection(), useNoCorrection(), useNoPrior(), usePC(), useScoreAIC(), useScoreBD(), useScoreBDeu(), useScoreBIC(), useScoreK2(), useScoreLog2Likelihood(), and useSmoothingPrior().

◆ BNLearner() [2/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::BNLearner ( const DatabaseTable & db)

default constructor

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

Parameters
dban already initialized database table that is used to fill the Database

◆ BNLearner() [3/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::BNLearner ( std::string_view filename,
const gum::BayesNet< GUM_SCALAR > & src,
const std::vector< std::string > & missing_symbols = {"?"} )

Wrapper for BNLearner (filename,modalities,parse_database) using a bn to find those modalities and nodeids.

◆ BNLearner() [4/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::BNLearner ( const BNLearner< GUM_SCALAR > & )

copy constructor

References BNLearner().

Here is the call graph for this function:

◆ BNLearner() [5/5]

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::BNLearner ( BNLearner< GUM_SCALAR > && )

move constructor

References BNLearner().

Here is the call graph for this function:

◆ ~BNLearner()

template<GUM_Numeric GUM_SCALAR>
gum::learning::BNLearner< GUM_SCALAR >::~BNLearner ( )
override

destructor

Member Function Documentation

◆ _checkDAGCompatibility_()

template<GUM_Numeric GUM_SCALAR>
void gum::learning::BNLearner< GUM_SCALAR >::_checkDAGCompatibility_ ( const DAG & dag)
private

check that the database contains the nodes of the dag, else raise an exception

Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
Returns
nothing if all the nodes of the dag belong to the dataset

References _checkDAGCompatibility_().

Referenced by _checkDAGCompatibility_().

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

◆ _initializeEMParameterLearning_()

template<GUM_Numeric GUM_SCALAR>
std::pair< std::shared_ptr< ParamEstimator >, std::shared_ptr< ParamEstimator > > gum::learning::BNLearner< GUM_SCALAR >::_initializeEMParameterLearning_ ( const DAG & dag,
bool takeIntoAccountScore )
private

initializes EM and returns a pair containing, first, a bootstrap estimator and, second, the EM estimator

Parameters
dagthe graphical structure of the BN learnt by EM
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Returns
a pair of estimators. The first one is used to fill the CPTs of the returned BN in order to initialize EM. It fills them using the database records without taking into account the missing values. The second estimator is the one used by all the subsequent iterations of the EM algorithm.

References _initializeEMParameterLearning_().

Referenced by _initializeEMParameterLearning_().

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

◆ _labelsFromBN_()

template<GUM_Numeric GUM_SCALAR>
NodeProperty< Sequence< std::string > > gum::learning::BNLearner< GUM_SCALAR >::_labelsFromBN_ ( std::string_view filename,
const BayesNet< GUM_SCALAR > & src )
private

read the first line of a file to find column names

References _labelsFromBN_().

Referenced by _labelsFromBN_().

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

◆ _learnParameters_()

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::_learnParameters_ ( const DAG & dag,
bool takeIntoAccountScore )
private

learns a BN (its parameters) with the structure passed in argument using a single pass estimation (not EM)

Parameters
dagthe structure of the Bayesian network
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
MissingValueInDatabaseif the database contains some missing values

References _learnParameters_().

Referenced by _learnParameters_().

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

◆ _learnParametersWithEM_() [1/2]

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::_learnParametersWithEM_ ( const BayesNet< GUM_SCALAR > & bn,
bool takeIntoAccountScore )
private

learns a BN (its parameters) with the structure passed in argument using the EM algorithm initialized by the Bayes net passed in argument

Parameters
bnthe Bayesian network used to specify the graphical structure of the returned Bayes net and to initialize its CPTs before running EM. When a CPT is filled exclusively with only zeroes, then this one is initialized by the BNLearner using a specific estimator that does not take into account the missing values in the database
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
Warning
the EM algorithm initializes the parameters of the CPTs using those of the Bayes net passed in argument whenever those are not fully filled with zeroes, else the BNLearner initializes them using an estimator that does not take into account the missing values. If you wish the BNLearner to automatically initialize all the CPTs, use the method in which a DAG is passed in argument rather than a Bayes net.

References _learnParametersWithEM_().

Here is the call graph for this function:

◆ _learnParametersWithEM_() [2/2]

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::_learnParametersWithEM_ ( const DAG & dag,
bool takeIntoAccountScore )
private

learns a BN (its parameters) with the structure passed in argument using the EM algorithm initialized by the BNLearner

Parameters
dagthe structure of the Bayesian network
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
Warning
the EM algorithm initializes the parameters of the CPTs by running a first estimator that does not take into account missing values. If you wish to initialize them yourself, use the method in which a Bayes net is passed in argument rather than a DAG.

References _learnParametersWithEM_().

Referenced by _learnParametersWithEM_(), and _learnParametersWithEM_().

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

◆ _setPriorWeight_()

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

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 }
double priorWeight_
the weight of the prior
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]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc ( const Arc & arc)

References BNLearner(), and addForbiddenArc().

Referenced by addForbiddenArc(), addForbiddenArc(), and addForbiddenArc().

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

◆ addForbiddenArc() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc ( NodeId tail,
NodeId head )

References BNLearner(), and addForbiddenArc().

Here is the call graph for this function:

◆ addForbiddenArc() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addForbiddenArc ( std::string_view tail,
std::string_view head )

References BNLearner(), and addForbiddenArc().

Here is the call graph for this function:

◆ addMandatoryArc() [1/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc ( const Arc & arc)

References BNLearner(), and addMandatoryArc().

Referenced by addMandatoryArc(), addMandatoryArc(), and addMandatoryArc().

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

◆ addMandatoryArc() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc ( NodeId tail,
NodeId head )

References BNLearner(), and addMandatoryArc().

Here is the call graph for this function:

◆ addMandatoryArc() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addMandatoryArc ( std::string_view tail,
std::string_view head )

References BNLearner(), and addMandatoryArc().

Here is the call graph for this function:

◆ addNoChildrenNode() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addNoChildrenNode ( NodeId node)

References BNLearner(), and addNoChildrenNode().

Referenced by addNoChildrenNode(), and addNoChildrenNode().

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

◆ addNoChildrenNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addNoChildrenNode ( std::string_view name)

References BNLearner(), and addNoChildrenNode().

Here is the call graph for this function:

◆ addNoParentNode() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addNoParentNode ( NodeId node)

References BNLearner(), and addNoParentNode().

Referenced by addNoParentNode(), and addNoParentNode().

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

◆ addNoParentNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addNoParentNode ( std::string_view name)

References BNLearner(), and addNoParentNode().

Here is the call graph for this function:

◆ addPossibleEdge() [1/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge ( const Edge & edge)

References BNLearner(), and addPossibleEdge().

Referenced by addPossibleEdge(), addPossibleEdge(), and addPossibleEdge().

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

◆ addPossibleEdge() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge ( NodeId tail,
NodeId head )

References BNLearner(), and addPossibleEdge().

Here is the call graph for this function:

◆ addPossibleEdge() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::addPossibleEdge ( std::string_view tail,
std::string_view head )

References BNLearner(), and addPossibleEdge().

Here is the call graph for this function:

◆ allowArcAdditions()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::allowArcAdditions ( bool allow)

References BNLearner(), and allowArcAdditions().

Referenced by allowArcAdditions().

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

◆ allowArcDeletions()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::allowArcDeletions ( bool allow)

References BNLearner(), and allowArcDeletions().

Referenced by allowArcDeletions().

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

◆ allowArcReversals()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::allowArcReversals ( bool allow)

References BNLearner(), and allowArcReversals().

Referenced by allowArcReversals().

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

◆ allowArcTriangleDeletions()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::allowArcTriangleDeletions ( bool allow)

References BNLearner(), and allowArcTriangleDeletions().

Referenced by allowArcTriangleDeletions().

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

◆ checkScorePriorCompatibility()

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

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
ScoreType scoreType_
the score selected for learning
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 = {} )
inherited

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
Database scoreDatabase_
the database to be used by the scores and parameter estimators
Prior * prior_
the prior used

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 = {} )
inherited

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.
NodeId idFromName(std::string_view var_name) const
returns the node id corresponding to a variable name

References chi2(), and idFromName().

Here is the call graph for this function:

◆ clearDatabaseRanges()

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

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

Definition at line 729 of file IBNLearner_inl.h.

729{ ranges_.clear(); }
std::vector< std::pair< std::size_t, std::size_t > > ranges_
the set of rows' ranges within the database in which learning is done

References ranges_.

◆ copyState()

template<GUM_Numeric GUM_SCALAR>
void gum::learning::BNLearner< GUM_SCALAR >::copyState ( const BNLearner< GUM_SCALAR > & learner)

copy the states of the BNLearner

Warning
except the database ! just the configurations of the learner

References BNLearner(), and copyState().

Referenced by copyState().

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

◆ correctedMutualInformation() [1/2]

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

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
CorrectedMutualInformation::KModeTypes kmodeMiic_
the penalty used in MIIC
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 = {} )
inherited

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

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 }
CorrectedMutualInformation * mutualInfo_
the selected correction for miic

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

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
ParamEstimatorType paramEstimatorType_
the type of the parameter estimator
Score * score_
the score used

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

template<GUM_Numeric GUM_SCALAR>
void gum::learning::BNLearner< GUM_SCALAR >::createPrior_ ( )
overrideprotectedvirtual

create the prior used for learning

Implements gum::learning::IBNLearner.

References createPrior_().

Referenced by createPrior_().

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

◆ createScore_()

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

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
overridevirtualinherited

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
inherited

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
inherited

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
inherited

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

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 }
K2 algoK2_
the K2 algorithm
DAG2BNLearner dag2BN_
the parametric EM
GreedyHillClimbing greedyHillClimbing_
the greedy hill climbing algorithm
LocalSearchWithTabuList localSearchWithTabuList_
the local search with tabu list algorithm

References algoK2_, dag2BN_, greedyHillClimbing_, and localSearchWithTabuList_.

◆ disableMaxIter()

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

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

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

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

{@ /// 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 )
inherited

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
inherited

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
inherited

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
inherited

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

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 }
bool useEM_
a Boolean indicating whether we should use EM for parameter learning or not

References dag2BN_, GUM_ERROR, and useEM_.

◆ EMCurrentTime()

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

get the current running time in second (double)

Definition at line 992 of file IBNLearner_inl.h.

992{ return dag2BN_.currentTime(); }

References dag2BN_.

◆ EMdisableEpsilon()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMdisableEpsilon ( )

Disable the min log-likelihood diff stopping criterion.

References BNLearner(), and EMdisableEpsilon().

Referenced by EMdisableEpsilon().

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

◆ EMdisableMaxIter()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMdisableMaxIter ( )

Disable stopping criterion on max iterations.

References BNLearner(), and EMdisableMaxIter().

Referenced by EMdisableMaxIter().

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

◆ EMdisableMaxTime()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMdisableMaxTime ( )

Disable EM's timeout stopping criterion.

References BNLearner(), and EMdisableMaxTime().

Referenced by EMdisableMaxTime().

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

◆ EMdisableMinEpsilonRate()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMdisableMinEpsilonRate ( )

Disable the log-likelihood evolution rate stopping criterion.

References BNLearner(), and EMdisableMinEpsilonRate().

Referenced by EMdisableMinEpsilonRate().

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

◆ EMenableEpsilon()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::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)

References BNLearner(), and EMenableEpsilon().

Referenced by EMenableEpsilon().

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

◆ EMenableMaxIter()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMenableMaxIter ( )

Enable stopping criterion on max iterations.

References BNLearner(), and EMenableMaxIter().

Referenced by EMenableMaxIter().

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

◆ EMenableMaxTime()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMenableMaxTime ( )

enable EM's timeout stopping criterion

References BNLearner(), and EMenableMaxTime().

Referenced by EMenableMaxTime().

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

◆ EMenableMinEpsilonRate()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMenableMinEpsilonRate ( )

Enable the log-likelihood evolution rate stopping criterion.

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

References BNLearner(), and EMenableMinEpsilonRate().

Referenced by EMenableMinEpsilonRate().

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

◆ EMEpsilon()

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

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
inherited

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
inherited

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
inherited
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
inherited
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
inherited
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
inherited

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
inherited

@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
inherited

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
inherited

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

template<GUM_Numeric GUM_SCALAR>
INLINE Size gum::learning::IBNLearner::EMPeriodSize ( ) const

Definition at line 1569 of file IBNLearner_inl.h.

1002{ return dag2BN_.periodSize(); }

Referenced by EMsetPeriodSize().

Here is the caller graph for this function:

◆ EMsetEpsilon()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetEpsilon ( const 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

References BNLearner(), and EMsetEpsilon().

Referenced by EMsetEpsilon().

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

◆ EMsetMaxIter()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetMaxIter ( const Size max)

add a max iteration stopping criterion

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

References BNLearner(), and EMsetMaxIter().

Referenced by EMsetMaxIter().

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

◆ EMsetMaxTime()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetMaxTime ( const double timeout)

add a stopping criterion on timeout

Parameters
timeoutthe timeout in milliseconds
Exceptions
OutOfBoundsif timeout<=0.0

References BNLearner(), and EMsetMaxTime().

Referenced by EMsetMaxTime().

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

◆ EMsetMinEpsilonRate()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetMinEpsilonRate ( const 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

References BNLearner(), and EMsetMinEpsilonRate().

Referenced by EMsetMinEpsilonRate().

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

◆ EMsetPeriodSize()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetPeriodSize ( const Size p)

how many samples between 2 stoppings isEnabled

Exceptions
OutOfBoundsif p<1

References BNLearner(), gum::learning::IBNLearner::IBNLearner(), EMPeriodSize(), and EMsetPeriodSize().

Referenced by EMsetPeriodSize().

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

◆ EMsetVerbosity()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::EMsetVerbosity ( const bool v)

sets or unsets EM's verbosity

References BNLearner(), and EMsetVerbosity().

Referenced by EMsetVerbosity().

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

◆ EMState()

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

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
inherited

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
inherited

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
inherited

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

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

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

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

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
overridevirtualinherited

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]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc ( const Arc & arc)

References BNLearner(), and eraseForbiddenArc().

Referenced by eraseForbiddenArc(), eraseForbiddenArc(), and eraseForbiddenArc().

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

◆ eraseForbiddenArc() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc ( NodeId tail,
NodeId head )

References BNLearner(), and eraseForbiddenArc().

Here is the call graph for this function:

◆ eraseForbiddenArc() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseForbiddenArc ( std::string_view tail,
std::string_view head )

References BNLearner(), and eraseForbiddenArc().

Here is the call graph for this function:

◆ eraseMandatoryArc() [1/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc ( const Arc & arc)

References BNLearner(), and eraseMandatoryArc().

Referenced by eraseMandatoryArc(), eraseMandatoryArc(), and eraseMandatoryArc().

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

◆ eraseMandatoryArc() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc ( NodeId tail,
NodeId head )

References BNLearner(), and eraseMandatoryArc().

Here is the call graph for this function:

◆ eraseMandatoryArc() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseMandatoryArc ( std::string_view tail,
std::string_view head )

References BNLearner(), and eraseMandatoryArc().

Here is the call graph for this function:

◆ eraseNoChildrenNode() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseNoChildrenNode ( NodeId node)

References BNLearner(), and eraseNoChildrenNode().

Referenced by eraseNoChildrenNode(), and eraseNoChildrenNode().

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

◆ eraseNoChildrenNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseNoChildrenNode ( std::string_view name)

References BNLearner(), and eraseNoChildrenNode().

Here is the call graph for this function:

◆ eraseNoParentNode() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseNoParentNode ( NodeId node)

References BNLearner(), and eraseNoParentNode().

Referenced by eraseNoParentNode(), and eraseNoParentNode().

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

◆ eraseNoParentNode() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::eraseNoParentNode ( std::string_view name)

References BNLearner(), and eraseNoParentNode().

Here is the call graph for this function:

◆ erasePossibleEdge() [1/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge ( const Edge & edge)

References BNLearner(), and erasePossibleEdge().

Referenced by erasePossibleEdge(), erasePossibleEdge(), and erasePossibleEdge().

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

◆ erasePossibleEdge() [2/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge ( NodeId tail,
NodeId head )

References BNLearner(), and erasePossibleEdge().

Here is the call graph for this function:

◆ erasePossibleEdge() [3/3]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::erasePossibleEdge ( std::string_view tail,
std::string_view head )

References BNLearner(), and erasePossibleEdge().

Here is the call graph for this function:

◆ fciExhaustiveSepSet()

template<GUM_Numeric GUM_SCALAR>
bool gum::learning::BNLearner< GUM_SCALAR >::fciExhaustiveSepSet ( ) const

References fciExhaustiveSepSet().

Referenced by fciExhaustiveSepSet().

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

◆ forbidEM()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::forbidEM ( )

prevent using the EM algorithm for parameter learning

References BNLearner(), and forbidEM().

Referenced by forbidEM().

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

◆ G2() [1/2]

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

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 = {} )
inherited

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
protectedinherited

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

Definition at line 689 of file IBNLearner_inl.h.

689 {
690 switch (priorType_) {
692 case NO_prior : return PriorType::NoPriorType;
696 case BDEU : return PriorType::BDeuPriorType;
697 default :
698 GUM_ERROR(OperationNotAllowed,
699 "IBNLearner getPriorType does "
700 "not support yet this prior")
701 }
702 }
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
BNLearnerPriorType
an enumeration to select the prior
Definition IBNLearner.h:114

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

template<GUM_Numeric GUM_SCALAR>
bool gum::learning::BNLearner< GUM_SCALAR >::greedyThickThinningReversals ( ) const

References greedyThickThinningReversals().

Referenced by greedyThickThinningReversals().

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

◆ hasMissingValues()

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

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
overridevirtualinherited
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
inherited

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

returns the initial DAG structure

Definition at line 166 of file IBNLearner_inl.h.

166{ return initialDag_; }
DAG initialDag_
an initial DAG given to learners

References initialDag_.

◆ isConstraintBased()

template<GUM_Numeric GUM_SCALAR>
bool gum::learning::BNLearner< GUM_SCALAR >::isConstraintBased ( ) const

References isConstraintBased().

Referenced by isConstraintBased().

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

◆ isCSVFileName_()

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

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

template<GUM_Numeric GUM_SCALAR>
bool gum::learning::BNLearner< GUM_SCALAR >::isScoreBased ( ) const

References isScoreBased().

Referenced by isScoreBased().

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

◆ isUsingEM()

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

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
inherited

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 }
Miic algoMiic_
the Constraint MIIC algorithm

References algoMiic_.

◆ learnBN()

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::learnBN ( )

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

References learnBN().

Referenced by learnBN().

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

◆ learnDAG()

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

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

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 }
StructuralConstraintPossibleEdges constraintPossibleEdges_
the constraint on possible Edges
MixedGraph preparePC_()
prepares the initial graph and independence test for PC
StructuralConstraintNoParentNodes constraintNoParentNodes_
the constraint on no parent nodes
GreedyHillClimbing extendedGreedyHillClimbing_
the extended greedy hill climbing
bool allowArcTriangleDeletions_
whether we allow or not arc deletions during learning
AlgoType selectedAlgo_
the selected learning algorithm
bool allowArcAdditions_
whether we allow or not arc additions during learning
StructuralConstraintNoChildrenNodes constraintNoChildrenNodes_
the constraint on no children nodes
gum::learning::FCI algoFCI_
the FCI algorithm
Database * priorDatabase_
the database used by the Dirichlet a priori
StructuralConstraintIndegree constraintIndegree_
the constraint for indegrees
bool allowArcDeletions_
whether we allow or not arc deletions during learning
StructuralConstraintMandatoryArcs constraintMandatoryArcs_
the constraint on mandatory arcs
StructuralConstraintForbiddenArcs constraintForbiddenArcs_
the constraint on forbidden arcs
StructuralConstraintTotalOrder constraintTotalOrder_
the total order ing constraint
StructuralConstraintTabuList constraintTabuList_
the constraint for tabu lists
GreedyThickThinning greedyThickThinning_
the greedy thick-thinning algorithm
MixedGraph prepareFCI_()
prepares the initial graph and independence test for FCI
gum::learning::PC algoPC_
the PC algorithm
bool allowArcReversals_
whether we allow or not arc reversals during learning
MixedGraph prepareMiic_()
prepares the initial graph for miic
StructuralConstraintSliceOrder constraintSliceOrder_
the constraint for 2TBNs
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 ( )
inherited

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

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:

◆ learnParameters() [1/3]

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::learnParameters ( bool take_into_account_score = true)

learns a BN (its parameters) when its structure is known

Parameters
take_into_account_scoreThe dag of the BN which was passed in argument to the BNLearner may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Warning
if method useEM() has been executed, then the learning is performed using EM, else this is a standard (e.g. ML/MAP) learning
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
UnknownLabelInDatabaseif a label is found in the databast that do not correpond to the variable.
OperationNotAllowedif EM is used but neither the min log-likelihood difference nor the min log-likelihood evolution rate have been selected as stopping criteria

References learnParameters().

Here is the call graph for this function:

◆ learnParameters() [2/3]

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::learnParameters ( const BayesNet< GUM_SCALAR > & bn,
bool takeIntoAccountScore = true )

learns a BN (its parameters) with the BN structure passed in argument, EM being initialized by this argument

Parameters
bnthe Bayesian network used to specify the graphical structure of the returned Bayes net and to initialize its CPTs before running EM. When a CPT is filled exclusively with only zeroes, then this one is initialized by the BNLearner using a specific estimator that does not take into account the missing values in the database
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
OperationNotAllowedif EM is used but no EM stopping criterion has been selected.
Warning
if method useEM() has been executed, then the learning is performed using EM, else this is a standard (e.g. ML/MAP) learning
the EM algorithm initializes the parameters of the CPTs using those of the Bayes net passed in argument whenever those are not fully filled with zeroes, else the BNLearner initializes them using an estimator that does not take into account the missing values. If you wish the BNLearner to automatically initialize all the CPTs, use the method in which a DAG is passed in argument rather than a Bayes net.

References learnParameters().

Here is the call graph for this function:

◆ learnParameters() [3/3]

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::learnParameters ( const DAG & dag,
bool takeIntoAccountScore = true )

learns a BN (its parameters) with the structure passed in argument

Parameters
dagthe structure of the Bayesian network
takeIntoAccountScoreThe dag passed in argument may have been learnt from a structure learning. In this case, if the score used to learn the structure has an implicit prior (like K2 which has a 1-smoothing prior), it is important to also take into account this implicit prior for parameter learning. By default, if a score exists, we will learn parameters by taking into account the prior specified by methods usePriorXXX () + the implicit prior of the score, else we just take into account the prior specified by usePriorXXX ()
Exceptions
MissingVariableInDatabaseif a variable of the BN is not found in the database.
MissingValueInDatabaseif the database contains some missing values and EM is not used for the learning.
OperationNotAllowedif EM is used but no EM stopping criterion has been selected.
Warning
if method useEM() has been executed, then the learning is performed using EM, else this is a standard (e.g. ML/MAP) learning

References learnParameters().

Referenced by learnParameters(), learnParameters(), and learnParameters().

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

◆ learnPDAG()

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

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

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 = {} )
inherited

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 = {} )
inherited

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
overridevirtualinherited
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
overridevirtualinherited

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
overridevirtualinherited

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 = {} )
inherited

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 = {} )
inherited

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
inherited

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
inherited

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
inherited
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
overridevirtualinherited
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
inherited
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]

template<GUM_Numeric GUM_SCALAR>
BNLearner & gum::learning::BNLearner< GUM_SCALAR >::operator= ( BNLearner< GUM_SCALAR > && )
noexcept

move operator

References BNLearner().

Here is the call graph for this function:

◆ operator=() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner & gum::learning::BNLearner< GUM_SCALAR >::operator= ( const BNLearner< GUM_SCALAR > & )

copy operator

References BNLearner().

Here is the call graph for this function:

◆ periodSize()

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

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

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.
IndependenceTest * indepTestFCI_
owned independence test object for FCI (rebuilt before each learn call)
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_ ( )
protectedinherited

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

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
IndependenceTest * indepTestPC_
owned independence test object for PC (rebuilt before each learn call)
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_ ( )
protectedinherited

prepares the initial graph for Simple Miic

◆ rawPseudoCount() [1/2]

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

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

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

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
inherited

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 = {} )
inherited

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 = {} )
inherited

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

{@ /// 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)
inherited

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

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

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setFCIAlpha ( double alpha)

References BNLearner(), and setFCIAlpha().

Referenced by setFCIAlpha().

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

◆ setFCIExhaustiveSepSet()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setFCIExhaustiveSepSet ( bool exhaustive)

References BNLearner(), and setFCIExhaustiveSepSet().

Referenced by setFCIExhaustiveSepSet().

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

◆ setFCIMaxPathLength()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setFCIMaxPathLength ( Size max_len)

References BNLearner(), and setFCIMaxPathLength().

Referenced by setFCIMaxPathLength().

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

◆ setForbiddenArcs()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setForbiddenArcs ( const ArcSet & set)

References BNLearner(), and setForbiddenArcs().

Referenced by setForbiddenArcs().

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

◆ setGreedyThickThinningReversals()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setGreedyThickThinningReversals ( bool allow)

References BNLearner(), and setGreedyThickThinningReversals().

Referenced by setGreedyThickThinningReversals().

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

◆ setInitialDAG()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setInitialDAG ( const DAG & dag)

References BNLearner(), and setInitialDAG().

Referenced by setInitialDAG().

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

◆ setMandatoryArcs()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setMandatoryArcs ( const ArcSet & set)

References BNLearner(), and setMandatoryArcs().

Referenced by setMandatoryArcs().

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

◆ setMaxIndegree()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setMaxIndegree ( Size max_indegree)

References BNLearner(), and setMaxIndegree().

Referenced by setMaxIndegree().

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

◆ setMaxIter()

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

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

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

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

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

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPCAlpha ( double alpha)

References BNLearner(), and setPCAlpha().

Referenced by setPCAlpha().

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

◆ setPCMaxCondSetSize()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPCMaxCondSetSize ( Size max_k)

References BNLearner(), and setPCMaxCondSetSize().

Referenced by setPCMaxCondSetSize().

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

◆ setPCStable()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPCStable ( bool stable)

References BNLearner(), and setPCStable().

Referenced by setPCStable().

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

◆ setPCUnshieldedColliderSorted()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPCUnshieldedColliderSorted ( bool sorted)

References BNLearner(), and setPCUnshieldedColliderSorted().

Referenced by setPCUnshieldedColliderSorted().

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

◆ setPeriodSize()

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

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

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPossibleEdges ( const EdgeSet & set)

References BNLearner(), and setPossibleEdges().

Referenced by setPossibleEdges().

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

◆ setPossibleSkeleton()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setPossibleSkeleton ( const UndiGraph & skeleton)

References BNLearner(), and setPossibleSkeleton().

Referenced by setPossibleSkeleton().

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

◆ setRecordWeight()

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

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]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setSliceOrder ( const NodeProperty< NodeId > & slice_order)

References BNLearner(), and setSliceOrder().

Referenced by setSliceOrder(), and setSliceOrder().

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

◆ setSliceOrder() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setSliceOrder ( const std::vector< std::vector< std::string > > & slices)

References setSliceOrder().

Here is the call graph for this function:

◆ setTotalOrder() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setTotalOrder ( const Sequence< NodeId > & order)

References BNLearner(), and setTotalOrder().

Here is the call graph for this function:

◆ setTotalOrder() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::setTotalOrder ( const std::vector< std::string > & order)

References BNLearner(), and setTotalOrder().

Referenced by setTotalOrder(), and setTotalOrder().

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

◆ setVerbosity()

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

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_.

◆ state()

template<GUM_Numeric GUM_SCALAR>
std::vector< std::tuple< std::string, std::string, std::string > > gum::learning::BNLearner< GUM_SCALAR >::state ( ) const
Returns
a representation of the state of the learner in the form vector<key,value,comment>

References state().

Referenced by state().

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

◆ stateApproximationScheme()

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

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.

◆ toString()

template<GUM_Numeric GUM_SCALAR>
std::string gum::learning::BNLearner< GUM_SCALAR >::toString ( ) const
Returns
Returns a string representation of this BNLearner's current features.

References toString().

Referenced by toString().

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

◆ unsetSliceOrder()

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

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.

void setSliceOrder(const NodeProperty< NodeId > &slice_order)
sets a partial order on the nodes

References setSliceOrder().

Here is the call graph for this function:

◆ unsetTotalOrder()

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

removes the current total ordering constraint, if any

Definition at line 641 of file IBNLearner_inl.h.

641{ setTotalOrder(Sequence< NodeId >()); }
void setTotalOrder(const Sequence< NodeId > &order)
sets a total order over some nodes

References setTotalOrder().

Here is the call graph for this function:

◆ useBDeuPrior()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useBDeuPrior ( double weight = 1.0)

References BNLearner(), and useBDeuPrior().

Referenced by useBDeuPrior().

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

◆ useChi2Test()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useChi2Test ( )

References BNLearner(), and useChi2Test().

Referenced by useChi2Test().

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

◆ useCrossValidationFold()

std::pair< std::size_t, std::size_t > gum::learning::IBNLearner::useCrossValidationFold ( const std::size_t learning_fold,
const std::size_t k_fold )
inherited

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

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() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useDirichletPrior ( const gum::BayesNet< GUM_SCALAR > & bn,
double weight = 1 )

References BNLearner(), and useDirichletPrior().

Here is the call graph for this function:

◆ useDirichletPrior() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useDirichletPrior ( std::string_view filename,
double weight = 1 )

References BNLearner(), and useDirichletPrior().

Referenced by useDirichletPrior(), and useDirichletPrior().

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

◆ useEM()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useEM ( const double epsilon,
const double noise = default_EM_noise )

use The EM algorithm to learn parameters

This is essentially an alias for Method useEMWithRateCriterion().

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].
Returns
the BNLearner (so that we can chains the calls to useXXX() methods)
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].

References BNLearner(), gum::learning::IBNLearner::default_EM_noise, gum::learning::IBNLearner::epsilon(), and useEM().

Referenced by useEM().

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

◆ useEMWithDiffCriterion()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useEMWithDiffCriterion ( const double epsilon,
const double noise = default_EM_noise )

use The EM algorithm to learn parameters with the diff stopping 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].
Returns
the BNLearner (so that we can chains the calls to useXXX() methods)
Exceptions
OutOfBoundsis raised if epsilon is not strictly positive or if noise does not belong to interval [0,1].

References BNLearner(), gum::learning::IBNLearner::default_EM_noise, gum::learning::IBNLearner::epsilon(), and useEMWithDiffCriterion().

Referenced by useEMWithDiffCriterion().

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

◆ useEMWithRateCriterion()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::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.
max_nb_iterthe maximum number of EM iterations allowed. If equal to 0, this stopping criterion is unused.
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].
Returns
the BNLearner (so that we can chains the calls to useXXX() methods)
Exceptions
OutOfBoundsis raised if epsilon is not strictly positive or if noise does not belong to interval [0,1].

References BNLearner(), gum::learning::IBNLearner::default_EM_noise, gum::learning::IBNLearner::epsilon(), and useEMWithRateCriterion().

Referenced by useEMWithRateCriterion().

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

◆ useExtendedGreedyHillClimbing()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useExtendedGreedyHillClimbing ( )

References BNLearner(), and useExtendedGreedyHillClimbing().

Referenced by useExtendedGreedyHillClimbing().

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

◆ useFCI()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useFCI ( )

References BNLearner(), and useFCI().

Referenced by useFCI().

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

◆ useFCIChi2Test()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useFCIChi2Test ( )

References BNLearner(), and useFCIChi2Test().

Referenced by useFCIChi2Test().

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

◆ useFCIG2Test()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useFCIG2Test ( )

References BNLearner(), and useFCIG2Test().

Referenced by useFCIG2Test().

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

◆ useG2Test()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useG2Test ( )

References BNLearner(), and useG2Test().

Referenced by useG2Test().

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

◆ useGreedyHillClimbing()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useGreedyHillClimbing ( )

References BNLearner(), and useGreedyHillClimbing().

Referenced by useGreedyHillClimbing().

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

◆ useGreedyThickThinning()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useGreedyThickThinning ( )

References BNLearner(), and useGreedyThickThinning().

Referenced by useGreedyThickThinning().

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

◆ useK2() [1/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useK2 ( const Sequence< NodeId > & order)

References BNLearner(), and useK2().

Referenced by useK2(), and useK2().

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

◆ useK2() [2/2]

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useK2 ( const std::vector< NodeId > & order)

References BNLearner(), and useK2().

Here is the call graph for this function:

◆ useLocalSearchWithTabuList()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useLocalSearchWithTabuList ( Size tabu_size = 100,
Size nb_decrease = 2 )

References BNLearner(), and useLocalSearchWithTabuList().

Referenced by useLocalSearchWithTabuList().

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

◆ useMDLCorrection()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useMDLCorrection ( )

References BNLearner(), and useMDLCorrection().

Referenced by useMDLCorrection().

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

◆ useMIIC()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useMIIC ( )

References BNLearner(), and useMIIC().

Referenced by useMIIC().

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

◆ useNMLCorrection()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useNMLCorrection ( )

References BNLearner(), and useNMLCorrection().

Referenced by useNMLCorrection().

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

◆ useNoCorrection()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useNoCorrection ( )

References BNLearner(), and useNoCorrection().

Referenced by useNoCorrection().

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

◆ useNoPrior()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useNoPrior ( )

References BNLearner(), and useNoPrior().

Referenced by useNoPrior().

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

◆ usePC()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::usePC ( )

References BNLearner(), and usePC().

Referenced by usePC().

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

◆ useScoreAIC()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreAIC ( )

References BNLearner(), and useScoreAIC().

Referenced by useScoreAIC().

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

◆ useScoreBD()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreBD ( )

References BNLearner(), and useScoreBD().

Referenced by useScoreBD().

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

◆ useScoreBDeu()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreBDeu ( )

References BNLearner(), and useScoreBDeu().

Referenced by useScoreBDeu().

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

◆ useScoreBIC()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreBIC ( )

References BNLearner(), and useScoreBIC().

Referenced by useScoreBIC().

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

◆ useScorefNML()

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

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

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreK2 ( )

References BNLearner(), and useScoreK2().

Referenced by useScoreK2().

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

◆ useScoreLog2Likelihood()

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useScoreLog2Likelihood ( )

References BNLearner(), and useScoreLog2Likelihood().

Referenced by useScoreLog2Likelihood().

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

◆ useScoreMDL()

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

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

template<GUM_Numeric GUM_SCALAR>
BNLearner< GUM_SCALAR > & gum::learning::BNLearner< GUM_SCALAR >::useSmoothingPrior ( double weight = 1)

References BNLearner(), and useSmoothingPrior().

Referenced by useSmoothingPrior().

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

◆ verbosity()

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

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};

◆ _prior_bn_

template<GUM_Numeric GUM_SCALAR>
BayesNet< GUM_SCALAR > gum::learning::BNLearner< GUM_SCALAR >::_prior_bn_
private

Definition at line 542 of file BNLearner.h.

◆ algoFCI_

gum::learning::FCI gum::learning::IBNLearner::algoFCI_
protectedinherited

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_
protectedinherited

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_
protectedinherited

the PC algorithm

Definition at line 1206 of file IBNLearner.h.

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

◆ algoSimpleMiic_

SimpleMiic gum::learning::IBNLearner::algoSimpleMiic_
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

PC parameters.

Definition at line 1216 of file IBNLearner.h.

1216{0.05};

Referenced by preparePC_(), and setPCAlpha().

◆ constraintForbiddenArcs_

StructuralConstraintForbiddenArcs gum::learning::IBNLearner::constraintForbiddenArcs_
protectedinherited

◆ constraintIndegree_

StructuralConstraintIndegree gum::learning::IBNLearner::constraintIndegree_
protectedinherited

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_
protectedinherited

◆ constraintNoChildrenNodes_

StructuralConstraintNoChildrenNodes gum::learning::IBNLearner::constraintNoChildrenNodes_
protectedinherited

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_
protectedinherited

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_
protectedinherited

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_
protectedinherited

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_
protectedinherited

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_
protectedinherited

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}
staticconstexprinherited

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}
protectedinherited

Definition at line 1233 of file IBNLearner.h.

1233{false};

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

◆ extendedGreedyHillClimbing_

GreedyHillClimbing gum::learning::IBNLearner::extendedGreedyHillClimbing_
protectedinherited

the extended greedy hill climbing

Definition at line 1242 of file IBNLearner.h.

Referenced by learnDag_().

◆ filename_

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

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_
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

Definition at line 1210 of file IBNLearner.h.

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

◆ inducedTypes_

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

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_
protectedinherited

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)}
protectedinherited

Definition at line 1218 of file IBNLearner.h.

1218{Size(-1)};

Referenced by preparePC_(), and setPCMaxCondSetSize().

◆ maxPathLengthFci_

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

Definition at line 1232 of file IBNLearner.h.

1232{Size(-1)};

Referenced by prepareFCI_(), and setFCIMaxPathLength().

◆ mutualInfo_

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

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}
protectedinherited

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}
protectedinherited

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}
protectedinherited

◆ 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}
protectedinherited

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}
protectedinherited

◆ priorDatabase_

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

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_
protectedinherited

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}
protectedinherited

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}
protectedinherited

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_
protectedinherited

◆ score_

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

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_

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

◆ selectedAlgo_

◆ sortedUCPc_

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

Definition at line 1219 of file IBNLearner.h.

1219{false};

Referenced by preparePC_(), and setPCUnshieldedColliderSorted().

◆ stablePc_

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

Definition at line 1217 of file IBNLearner.h.

1217{true};

Referenced by preparePC_(), and setPCStable().

◆ useEM_

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

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 file: