27 #ifndef GUM_LEARNING_PARAM_ESTIMATOR_H 28 #define GUM_LEARNING_PARAM_ESTIMATOR_H 30 #include <type_traits> 32 #include <agrum/agrum.h> 33 #include <agrum/tools/database/databaseTable.h> 34 #include <agrum/BN/learning/aprioris/apriori.h> 35 #include <agrum/tools/stattests/recordCounter.h> 36 #include <agrum/tools/multidim/potential.h> 48 template <
template <
typename >
class ALLOC =
std::
allocator >
84 const Apriori< ALLOC >& external_apriori,
85 const Apriori< ALLOC >& _score_internal_apriori,
111 const Apriori< ALLOC >& external_apriori,
112 const Apriori< ALLOC >& _score_internal_apriori,
121 ParamEstimator(
const ParamEstimator< ALLOC >& from,
const allocator_type& alloc);
127 ParamEstimator(ParamEstimator< ALLOC >&& from,
const allocator_type& alloc);
147 virtual void clear();
176 template <
template <
typename >
class XALLOC >
207 template <
typename GUM_SCALAR >
225 template <
typename GUM_SCALAR >
226 void setBayesNet(
const BayesNet< GUM_SCALAR >& new_bn);
255 #ifndef DOXYGEN_SHOULD_SKIP_THIS 259 template <
typename GUM_SCALAR >
260 void _checkParameters_(
const NodeId target_node,
261 const std::vector< NodeId, ALLOC< NodeId > >& conditioning_nodes,
262 Potential< GUM_SCALAR >& pot);
267 template <
typename GUM_SCALAR >
268 typename std::enable_if< !std::is_same< GUM_SCALAR,
double >::value,
void >::type
269 _setParameters_(
const NodeId target_node,
270 const std::vector< NodeId, ALLOC< NodeId > >& conditioning_nodes,
271 Potential< GUM_SCALAR >& pot);
276 template <
typename GUM_SCALAR >
277 typename std::enable_if< std::is_same< GUM_SCALAR,
double >::value,
void >::type
278 _setParameters_(
const NodeId target_node,
279 const std::vector< NodeId, ALLOC< NodeId > >& conditioning_nodes,
280 Potential< GUM_SCALAR >& pot);
290 #include <agrum/BN/learning/paramUtils/paramEstimator_tpl.h> ParamEstimator< ALLOC > & operator=(const ParamEstimator< ALLOC > &from)
copy operator
virtual std::vector< double, ALLOC< double > > parameters(const NodeId target_node, const std::vector< NodeId, ALLOC< NodeId > > &conditioning_nodes)=0
returns the CPT's parameters corresponding to a given nodeset
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > & nodeId2Columns() const
returns the mapping from ids to column positions in the database
void setParameters(const NodeId target_node, const std::vector< NodeId, ALLOC< NodeId > > &conditioning_nodes, Potential< GUM_SCALAR > &pot)
sets the CPT's parameters corresponding to a given Potential
ParamEstimator(const ParamEstimator< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
ParamEstimator(const ParamEstimator< ALLOC > &from)
copy constructor
void clearRanges()
reset the ranges to the one range corresponding to the whole database
void setRanges(const std::vector< std::pair< std::size_t, std::size_t >, XALLOC< std::pair< std::size_t, std::size_t > > > &new_ranges)
sets new ranges to perform the countings used by the parameter estimator
INLINE void emplace(Args &&... args)
ParamEstimator(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_apriori, const Apriori< ALLOC > &_score_internal_apriori, const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > &nodeId2columns=Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(), const allocator_type &alloc=allocator_type())
default constructor
ParamEstimator< ALLOC > & operator=(ParamEstimator< ALLOC > &&from)
move operator
ParamEstimator(ParamEstimator< ALLOC > &&from)
move constructor
void setBayesNet(const BayesNet< GUM_SCALAR > &new_bn)
assign a new Bayes net to all the counter's generators depending on a BN
Apriori< ALLOC > * score_internal_apriori_
if a score was used for learning the structure of the PGM, this is the a priori internal to the score...
allocator_type getAllocator() const
returns the allocator used by the score
virtual void setMinNbRowsPerThread(const std::size_t nb) const
changes the number min of rows a thread should process in a multithreading context ...
ParamEstimator(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_apriori, const Apriori< ALLOC > &_score_internal_apriori, const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > &ranges, const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > &nodeId2columns=Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(), const allocator_type &alloc=allocator_type())
default constructor
virtual ParamEstimator< ALLOC > * clone(const allocator_type &alloc) const =0
virtual copy constructor with a given allocator
virtual ~ParamEstimator()
destructor
const DatabaseTable< ALLOC > & database() const
returns the database on which we perform the counts
std::vector< double, ALLOC< double > > parameters(const NodeId target_node)
returns the CPT's parameters corresponding to a given target node
virtual void clear()
clears all the data structures from memory
virtual std::size_t nbThreads() const
returns the number of threads used to parse the database
virtual ParamEstimator< ALLOC > * clone() const =0
virtual copy constructor
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
virtual void setMaxNbThreads(std::size_t nb) const
changes the max number of threads used to parse the database
virtual std::size_t minNbRowsPerThread() const
returns the minimum of rows that each thread should process
RecordCounter< ALLOC > counter_
the record counter used to parse the database
Apriori< ALLOC > * external_apriori_
an external a priori
ParamEstimator(ParamEstimator< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator