![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
The class for estimating parameters of CPTs using Maximum Likelihood. More...
#include <agrum/BN/learning/paramUtils/paramEstimatorML.h>
Public Member Functions | |
Constructors / Destructors | |
ParamEstimatorML (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 More... | |
ParamEstimatorML (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 More... | |
ParamEstimatorML (const ParamEstimatorML< ALLOC > &from) | |
copy constructor More... | |
ParamEstimatorML (const ParamEstimatorML< ALLOC > &from, const allocator_type &alloc) | |
copy constructor with a given allocator More... | |
ParamEstimatorML (ParamEstimatorML< ALLOC > &&from) | |
move constructor More... | |
ParamEstimatorML (ParamEstimatorML< ALLOC > &&from, const allocator_type &alloc) | |
move constructor with a given allocator More... | |
virtual ParamEstimatorML< ALLOC > * | clone () const |
virtual copy constructor More... | |
virtual ParamEstimatorML< ALLOC > * | clone (const allocator_type &alloc) const |
virtual copy constructor with a given allocator More... | |
virtual | ~ParamEstimatorML () |
destructor More... | |
Operators | |
ParamEstimatorML< ALLOC > & | operator= (const ParamEstimatorML< ALLOC > &from) |
copy operator More... | |
ParamEstimatorML< ALLOC > & | operator= (ParamEstimatorML< ALLOC > &&from) |
move operator More... | |
Accessors / Modifiers | |
virtual std::vector< double, ALLOC< double > > | parameters (const NodeId target_node, const std::vector< NodeId, ALLOC< NodeId > > &conditioning_nodes) |
returns the CPT's parameters corresponding to a given nodeset More... | |
Accessors / Modifiers | |
virtual void | clear () |
clears all the data structures from memory More... | |
virtual void | setMaxNbThreads (std::size_t nb) const |
changes the max number of threads used to parse the database More... | |
virtual std::size_t | nbThreads () const |
returns the number of threads used to parse the database More... | |
virtual void | setMinNbRowsPerThread (const std::size_t nb) const |
changes the number min of rows a thread should process in a multithreading context More... | |
virtual std::size_t | minNbRowsPerThread () const |
returns the minimum of rows that each thread should process More... | |
template<template< typename > class XALLOC> | |
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 More... | |
void | clearRanges () |
reset the ranges to the one range corresponding to the whole database More... | |
const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > & | ranges () const |
returns the current ranges More... | |
std::vector< double, ALLOC< double > > | parameters (const NodeId target_node) |
returns the CPT's parameters corresponding to a given target node More... | |
template<typename GUM_SCALAR > | |
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 More... | |
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > & | nodeId2Columns () const |
returns the mapping from ids to column positions in the database More... | |
const DatabaseTable< ALLOC > & | database () const |
returns the database on which we perform the counts More... | |
template<typename GUM_SCALAR > | |
void | setBayesNet (const BayesNet< GUM_SCALAR > &new_bn) |
assign a new Bayes net to all the counter's generators depending on a BN More... | |
allocator_type | getAllocator () const |
returns the allocator used by the score More... | |
Public Types | |
using | allocator_type = ALLOC< NodeId > |
type for the allocators passed in arguments of methods More... | |
Protected Attributes | |
Apriori< ALLOC > * | external_apriori_ {nullptr} |
an external a priori More... | |
Apriori< ALLOC > * | score_internal_apriori_ {nullptr} |
if a score was used for learning the structure of the PGM, this is the a priori internal to the score More... | |
RecordCounter< ALLOC > | counter_ |
the record counter used to parse the database More... | |
const std::vector< NodeId, ALLOC< NodeId > > | empty_nodevect_ |
an empty vector of nodes, used for empty conditioning More... | |
The class for estimating parameters of CPTs using Maximum Likelihood.
Definition at line 45 of file paramEstimatorML.h.
using gum::learning::ParamEstimatorML< ALLOC >::allocator_type = ALLOC< NodeId > |
type for the allocators passed in arguments of methods
Definition at line 48 of file paramEstimatorML.h.
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | 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
parser | the parser used to parse the database |
external_apriori | An apriori that we add to the computation of the score |
score_internal_apriori | The apriori within the score used to learn the data structure (might be a NoApriori) |
ranges | a set of pairs {(X1,Y1),...,(Xn,Yn)} of database's rows indices. The countings 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. |
nodeId2Columns | a mapping from the ids of the nodes in the graphical model to the corresponding column in the DatabaseTable parsed by the parser. This enables estimating from a database in which variable A corresponds to the 2nd column the parameters of a BN in which variable A has a NodeId of 5. An empty nodeId2Columns bijection means that the mapping is an identity, i.e., the value of a NodeId is equal to the index of the column in the DatabaseTable. |
alloc | the allocator used to allocate the structures within the Score. |
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | 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
parser | the parser used to parse the database |
external_apriori | An apriori that we add to the computation of the score |
score_internal_apriori | The apriori within the score used to learn the data structure (might be a NoApriori) |
nodeId2Columns | a mapping from the ids of the nodes in the graphical model to the corresponding column in the DatabaseTable parsed by the parser. This enables estimating from a database in which variable A corresponds to the 2nd column the parameters of a BN in which variable A has a NodeId of 5. An empty nodeId2Columns bijection means that the mapping is an identity, i.e., the value of a NodeId is equal to the index of the column in the DatabaseTable. |
alloc | the allocator used to allocate the structures within the Score. |
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | const ParamEstimatorML< ALLOC > & | from | ) |
copy constructor
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | const ParamEstimatorML< ALLOC > & | from, |
const allocator_type & | alloc | ||
) |
copy constructor with a given allocator
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | ParamEstimatorML< ALLOC > && | from | ) |
move constructor
gum::learning::ParamEstimatorML< ALLOC >::ParamEstimatorML | ( | ParamEstimatorML< ALLOC > && | from, |
const allocator_type & | alloc | ||
) |
move constructor with a given allocator
|
virtual |
destructor
|
virtualinherited |
clears all the data structures from memory
|
inherited |
reset the ranges to the one range corresponding to the whole database
|
virtual |
virtual copy constructor
Implements gum::learning::ParamEstimator< ALLOC >.
|
virtual |
virtual copy constructor with a given allocator
Implements gum::learning::ParamEstimator< ALLOC >.
|
inherited |
returns the database on which we perform the counts
|
inherited |
returns the allocator used by the score
|
virtualinherited |
returns the minimum of rows that each thread should process
|
virtualinherited |
returns the number of threads used to parse the database
|
inherited |
returns the mapping from ids to column positions in the database
ParamEstimatorML< ALLOC >& gum::learning::ParamEstimatorML< ALLOC >::operator= | ( | const ParamEstimatorML< ALLOC > & | from | ) |
copy operator
ParamEstimatorML< ALLOC >& gum::learning::ParamEstimatorML< ALLOC >::operator= | ( | ParamEstimatorML< ALLOC > && | from | ) |
move operator
|
virtual |
returns the CPT's parameters corresponding to a given nodeset
The vector contains the parameters of an n-dimensional CPT. The distribution of the dimensions of the CPT within the vector is as follows: first, there is the target node, then the conditioning nodes (in the order in which they were specified).
DatabaseError | is raised if some values of the conditioning sets were not observed in the database. |
Implements gum::learning::ParamEstimator< ALLOC >.
|
inherited |
returns the CPT's parameters corresponding to a given target node
|
inherited |
returns the current ranges
|
inherited |
assign a new Bayes net to all the counter's generators depending on a BN
Typically, generators based on EM or K-means depend on a model to compute correctly their outputs. Method setBayesNet enables to update their BN model.
|
virtualinherited |
changes the max number of threads used to parse the database
|
virtualinherited |
changes the number min of rows a thread should process in a multithreading context
When computing score, several threads are used by record counters to perform countings on the rows of the database, the MinNbRowsPerThread method indicates how many rows each thread should at least process. This is used to compute the number of threads actually run. This number is equal to the min between the max number of threads allowed and the number of records in the database divided by nb.
|
inherited |
sets the CPT's parameters corresponding to a given Potential
The potential is assumed to be a conditional probability, the first variable of its variablesSequence() being the target variable, the other ones being on the right side of the conditioning bar.
|
inherited |
sets new ranges to perform the countings used by the parameter estimator
ranges | a set of pairs {(X1,Y1),...,(Xn,Yn)} of database's rows indices. The countings 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. |
|
protectedinherited |
the record counter used to parse the database
Definition at line 242 of file paramEstimator.h.
|
protectedinherited |
an empty vector of nodes, used for empty conditioning
Definition at line 245 of file paramEstimator.h.
|
protectedinherited |
an external a priori
Definition at line 235 of file paramEstimator.h.
|
protectedinherited |
if a score was used for learning the structure of the PGM, this is the a priori internal to the score
Definition at line 239 of file paramEstimator.h.