50#ifndef GUM_LEARNING_BN_LEARNER_H
51#define GUM_LEARNING_BN_LEARNER_H
73 template <
typename GUM_SCALAR >
96 const std::vector< std::string >& missingSymbols = {
"?"},
97 const bool induceTypes =
true);
114 const std::vector< std::string >& missing_symbols = {
"?"});
197 bool takeIntoAccountScore = true);
503 Size nb_decrease = 2) {
717 const BayesNet< GUM_SCALAR >& src);
766 std::pair< std::shared_ptr< ParamEstimator >, std::shared_ptr< ParamEstimator > >
818 bool takeIntoAccountScore);
822 template <
typename GUM_SCALAR >
A pack of learning algorithms that can easily be used.
A dirichlet priori: computes its N'_ijk from a bayesian network.
A class for generic framework of learning algorithms that can easily be used.
The base class for all directed edges.
Class representing a Bayesian network.
The base class for all undirected edges.
Exception : out of bound.
Base class for undirected graphs.
A class that redirects gum_signal from algorithms to the listeners of BNLearn.
A pack of learning algorithms that can easily be used.
BNLearner< GUM_SCALAR > & useNoPrior()
BNLearner< GUM_SCALAR > & EMdisableMaxIter()
Disable stopping criterion on max iterations.
BNLearner< GUM_SCALAR > & EMenableMinEpsilonRate()
Enable the log-likelihood evolution rate stopping criterion.
BNLearner< GUM_SCALAR > & addForbiddenArc(const Arc &arc)
BNLearner< GUM_SCALAR > & useScoreAIC()
BNLearner< GUM_SCALAR > & eraseMandatoryArc(const Arc &arc)
BNLearner< GUM_SCALAR > & EMdisableEpsilon()
Disable the min log-likelihood diff stopping criterion.
BNLearner< GUM_SCALAR > & addPossibleEdge(const Edge &edge)
BNLearner< GUM_SCALAR > & useScoreBD()
std::vector< std::tuple< std::string, std::string, std::string > > state() const
NodeProperty< Sequence< std::string > > _labelsFromBN_(const std::string &filename, const BayesNet< GUM_SCALAR > &src)
read the first line of a file to find column names
BNLearner< GUM_SCALAR > & addPossibleEdge(NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & addMandatoryArc(const Arc &arc)
BNLearner< GUM_SCALAR > & useBDeuPrior(double weight=1.0)
BNLearner< GUM_SCALAR > & useScoreBIC()
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...
BNLearner< GUM_SCALAR > & addForbiddenArc(const std::string &tail, const std::string &head)
BNLearner< GUM_SCALAR > & useNoCorrection()
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,...
BNLearner< GUM_SCALAR > & useSmoothingPrior(double weight=1)
BNLearner< GUM_SCALAR > & EMdisableMinEpsilonRate()
Disable the log-likelihood evolution rate stopping criterion.
BNLearner< GUM_SCALAR > & erasePossibleEdge(const std::string &tail, const std::string &head)
BNLearner(const BNLearner &)
copy constructor
BNLearner< GUM_SCALAR > & erasePossibleEdge(const Edge &edge)
BNLearner< GUM_SCALAR > & addNoChildrenNode(const std::string &name)
BNLearner< GUM_SCALAR > & useK2(const std::vector< NodeId > &order)
BNLearner & operator=(BNLearner &&) noexcept
move operator
BNLearner< GUM_SCALAR > & setPossibleSkeleton(const UndiGraph &skeleton)
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 (no...
BNLearner(BNLearner &&)
move constructor
BNLearner< GUM_SCALAR > & EMenableEpsilon()
Enable the log-likelihood min diff stopping criterion in EM.
virtual ~BNLearner()
destructor
BNLearner< GUM_SCALAR > & eraseNoChildrenNode(const std::string &name)
BNLearner< GUM_SCALAR > & setPossibleEdges(const EdgeSet &set)
BNLearner< GUM_SCALAR > & addMandatoryArc(NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & eraseForbiddenArc(const std::string &tail, const std::string &head)
BNLearner< GUM_SCALAR > & EMenableMaxTime()
enable EM's timeout stopping criterion
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...
BNLearner< GUM_SCALAR > & addNoChildrenNode(NodeId node)
BNLearner< GUM_SCALAR > & EMsetEpsilon(const double eps)
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
BNLearner< GUM_SCALAR > & EMdisableMaxTime()
Disable EM's timeout stopping criterion.
BNLearner< GUM_SCALAR > & addPossibleEdge(const std::string &tail, const std::string &head)
BNLearner & operator=(const BNLearner &)
copy operator
BNLearner< GUM_SCALAR > & erasePossibleEdge(NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & useGreedyHillClimbing()
BNLearner< GUM_SCALAR > & forbidEM()
prevent using the EM algorithm for parameter learning
BNLearner< GUM_SCALAR > & useK2(const Sequence< NodeId > &order)
BNLearner< GUM_SCALAR > & useScoreK2()
BNLearner< GUM_SCALAR > & setMandatoryArcs(const ArcSet &set)
BNLearner< GUM_SCALAR > & eraseNoChildrenNode(NodeId node)
BNLearner< GUM_SCALAR > & useMIIC()
BNLearner< GUM_SCALAR > & EMsetPeriodSize(const Size p)
how many samples between 2 stoppings isEnabled
BayesNet< GUM_SCALAR > learnBN()
learn a Bayes Net from a file (must have read the db before)
BNLearner< GUM_SCALAR > & setForbiddenArcs(const ArcSet &set)
bool isConstraintBased() const
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 > & setInitialDAG(const DAG &dag)
BNLearner< GUM_SCALAR > & addNoParentNode(NodeId node)
BNLearner< GUM_SCALAR > & addForbiddenArc(NodeId tail, NodeId head)
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 > & useScoreLog2Likelihood()
BNLearner< GUM_SCALAR > & addMandatoryArc(const std::string &tail, const std::string &head)
BayesNet< GUM_SCALAR > _prior_bn_
BNLearner< GUM_SCALAR > & EMsetMaxIter(const Size max)
add a max iteration stopping criterion
BNLearner< GUM_SCALAR > & useEM(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters
BNLearner< GUM_SCALAR > & setSliceOrder(const std::vector< std::vector< std::string > > &slices)
bool isScoreBased() const
BNLearner< GUM_SCALAR > & useLocalSearchWithTabuList(Size tabu_size=100, Size nb_decrease=2)
BNLearner(const DatabaseTable &db)
default constructor
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 > & useDirichletPrior(const std::string &filename, double weight=1)
BNLearner< GUM_SCALAR > & useMDLCorrection()
BNLearner< GUM_SCALAR > & eraseNoParentNode(NodeId node)
BNLearner< GUM_SCALAR > & EMsetVerbosity(const bool v)
sets or unsets EM's verbosity
BNLearner< GUM_SCALAR > & eraseForbiddenArc(const Arc &arc)
BayesNet< GUM_SCALAR > learnParameters(const DAG &dag, bool takeIntoAccountScore=true)
learns a BN (its parameters) with the structure passed in argument
void _checkDAGCompatibility_(const DAG &dag)
check that the database contains the nodes of the dag, else raise an exception
BNLearner< GUM_SCALAR > & useNMLCorrection()
BNLearner< GUM_SCALAR > & eraseMandatoryArc(NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & setSliceOrder(const NodeProperty< NodeId > &slice_order)
BNLearner< GUM_SCALAR > & useDirichletPrior(const gum::BayesNet< GUM_SCALAR > &bn, double weight=1)
std::string toString() const
BNLearner(const std::string &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 no...
BNLearner< GUM_SCALAR > & EMsetMaxTime(const double timeout)
add a stopping criterion on timeout
void copyState(const BNLearner< GUM_SCALAR > &learner)
copy the states of the BNLearner
BNLearner< GUM_SCALAR > & eraseMandatoryArc(const std::string &tail, const std::string &head)
BNLearner< GUM_SCALAR > & eraseForbiddenArc(NodeId tail, NodeId head)
BNLearner< GUM_SCALAR > & eraseNoParentNode(const std::string &name)
BNLearner< GUM_SCALAR > & EMenableMaxIter()
Enable stopping criterion on max iterations.
BNLearner(const std::string &filename, const std::vector< std::string > &missingSymbols={"?"}, const bool induceTypes=true)
default constructor
BNLearner< GUM_SCALAR > & addNoParentNode(const std::string &name)
BNLearner< GUM_SCALAR > & useScoreBDeu()
void createPrior_()
create the prior used for learning
BNLearner< GUM_SCALAR > & setMaxIndegree(Size max_indegree)
The class representing a tabular database as used by learning tasks.
void eraseNoChildrenNode(NodeId node)
BNLearnerPriorType priorType_
the a priorselected for the score and parameters
void EMenableEpsilon()
Enable the log-likelihood min diff stopping criterion in EM.
void useGreedyHillClimbing()
indicate that we wish to use a greedy hill climbing algorithm
void useScoreBDeu()
indicate that we wish to use a BDeu score
void addNoParentNode(NodeId node)
void setSliceOrder(const NodeProperty< NodeId > &slice_order)
sets a partial order on the nodes
IBNLearner(const std::string &filename, const std::vector< std::string > &missingSymbols, bool induceTypes=true)
read the database file for the score / parameter estimation and var names
void setForbiddenArcs(const ArcSet &set)
assign a set of forbidden arcs
Size EMPeriodSize() const
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
void EMdisableMaxTime()
Disable EM's timeout stopping criterion.
void EMsetMaxIter(Size max)
add a max iteration stopping criterion
std::string checkScorePriorCompatibility() const
checks whether the current score and prior are compatible
void useBDeuPrior(double weight=1.0)
use the BDeu prior
void setMandatoryArcs(const ArcSet &set)
assign a set of mandatory arcs
void EMdisableMaxIter()
Disable stopping criterion on max iterations.
void EMsetVerbosity(bool v)
sets or unsets EM's verbosity
void EMdisableEpsilon()
Disable the min log-likelihood diff stopping criterion for EM.
void addMandatoryArc(const Arc &arc)
void setMaxIndegree(Size max_indegree)
sets the max indegree
void addPossibleEdge(const Edge &edge)
void setInitialDAG(const DAG &)
sets an initial DAG structure
void useK2(const Sequence< NodeId > &order)
indicate that we wish to use K2
bool isScoreBased() const
indicate if the selected algorithm is score-based
void EMenableMinEpsilonRate()
Enable the log-likelihood evolution rate stopping criterion.
void EMsetMaxTime(double timeout)
add a stopping criterion on timeout
void EMdisableMinEpsilonRate()
Disable the log-likelihood evolution rate stopping criterion.
@ DIRICHLET_FROM_BAYESNET
void erasePossibleEdge(const Edge &edge)
bool isConstraintBased() const
indicate if the selected algorithm is constraint-based
void useScoreBIC()
indicate that we wish to use a BIC score
void setPossibleEdges(const EdgeSet &set)
assign a set of possible edges
void useNoPrior()
use no prior
void eraseForbiddenArc(const Arc &arc)
void EMenableMaxIter()
Enable stopping criterion on max iterations.
void useSmoothingPrior(double weight=1)
use the prior smoothing
void EMsetMinEpsilonRate(double rate)
sets the stopping criterion of EM as being the minimal log-likelihood's evolution rate
void useLocalSearchWithTabuList(Size tabu_size=100, Size nb_decrease=2)
indicate that we wish to use a local search with tabu list
void useScoreK2()
indicate that we wish to use a K2 score
void _setPriorWeight_(double weight)
sets the prior weight
void setPossibleSkeleton(const UndiGraph &skeleton)
assign a set of possible edges
void useEMWithRateCriterion(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters with the rate stopping criterion
void useNMLCorrection()
indicate that we wish to use the NML correction for and MIIC
void useEM(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters
void useEMWithDiffCriterion(const double epsilon, const double noise=default_EM_noise)
use The EM algorithm to learn parameters with the diff stopping criterion
void forbidEM()
prevent using the EM algorithm for parameter learning
double epsilon() const override
Get the value of epsilon.
void EMsetPeriodSize(Size p)
how many samples between 2 stoppings isEnabled
void useNoCorrection()
indicate that we wish to use the NoCorr correction for MIIC
void useScoreLog2Likelihood()
indicate that we wish to use a Log2Likelihood score
void useMDLCorrection()
indicate that we wish to use the MDL correction for MIIC
void useDirichletPrior(const std::string &filename, double weight=1)
use the Dirichlet prior from a database
void addForbiddenArc(const Arc &arc)
void addNoChildrenNode(NodeId node)
void useScoreAIC()
indicate that we wish to use an AIC score
void eraseMandatoryArc(const Arc &arc)
void useMIIC()
indicate that we wish to use MIIC
static constexpr double default_EM_noise
the default noise amount added to CPTs during EM's initialization (see method useEM())
void eraseNoParentNode(NodeId node)
void EMsetEpsilon(double eps)
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
void useScoreBD()
indicate that we wish to use a BD score
void EMenableMaxTime()
sets the stopping criterion of EM as being the minimal difference between two consecutive log-likelih...
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
include the inlined functions if necessary
std::ostream & operator<<(std::ostream &stream, const IdCondSet &idset)
the display operator
gum is the global namespace for all aGrUM entities