aGrUM  0.14.1
gum::learning::ParamEstimator< ALLOC > Class Template Referenceabstract

The base class for estimating parameters of CPTs. More...

#include <agrum/learning/paramUtils/paramEstimator.h>

+ Inheritance diagram for gum::learning::ParamEstimator< ALLOC >:

Public Member Functions

Constructors / Destructors
 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 More...
 
 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 More...
 
 ParamEstimator (const ParamEstimator< ALLOC > &from)
 copy constructor More...
 
 ParamEstimator (const ParamEstimator< ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 ParamEstimator (ParamEstimator< ALLOC > &&from)
 move constructor More...
 
 ParamEstimator (ParamEstimator< ALLOC > &&from, const allocator_type &alloc)
 move constructor with a given allocator More...
 
virtual ParamEstimator< ALLOC > * clone () const =0
 virtual copy constructor More...
 
virtual ParamEstimator< ALLOC > * clone (const allocator_type &alloc) const =0
 virtual copy constructor with a given allocator More...
 
virtual ~ParamEstimator ()
 destructor 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...
 
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 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...
 

Protected Member Functions

ParamEstimator< ALLOC > & operator= (const ParamEstimator< ALLOC > &from)
 copy operator More...
 
ParamEstimator< ALLOC > & operator= (ParamEstimator< ALLOC > &&from)
 move operator More...
 

Detailed Description

template<template< typename > class ALLOC = std::allocator>
class gum::learning::ParamEstimator< ALLOC >

The base class for estimating parameters of CPTs.

Definition at line 47 of file paramEstimator.h.

Member Typedef Documentation

◆ allocator_type

template<template< typename > class ALLOC = std::allocator>
using gum::learning::ParamEstimator< ALLOC >::allocator_type = ALLOC< NodeId >

type for the allocators passed in arguments of methods

Definition at line 50 of file paramEstimator.h.

Constructor & Destructor Documentation

◆ ParamEstimator() [1/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::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 = BijectionNodeId, std::size_t, ALLOC< std::size_t > >(),
const allocator_type alloc = allocator_type() 
)

default constructor

Parameters
parserthe parser used to parse the database
external_aprioriAn apriori that we add to the computation of the score
score_internal_aprioriThe apriori within the score used to learn the data structure (might be a NoApriori)
rangesa 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.
nodeId2Columnsa 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.
allocthe allocator used to allocate the structures within the Score.
Warning
If nodeId2columns is not empty, then only the scores over the ids belonging to this bijection can be computed: applying method score() over other ids will raise exception NotFound.

◆ ParamEstimator() [2/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::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 = BijectionNodeId, std::size_t, ALLOC< std::size_t > >(),
const allocator_type alloc = allocator_type() 
)

default constructor

Parameters
parserthe parser used to parse the database
external_aprioriAn apriori that we add to the computation of the score
score_internal_aprioriThe apriori within the score used to learn the data structure (might be a NoApriori)
nodeId2Columnsa 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.
allocthe allocator used to allocate the structures within the Score.
Warning
If nodeId2columns is not empty, then only the scores over the ids belonging to this bijection can be computed: applying method score() over other ids will raise exception NotFound.

◆ ParamEstimator() [3/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::ParamEstimator ( const ParamEstimator< ALLOC > &  from)

copy constructor

◆ ParamEstimator() [4/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::ParamEstimator ( const ParamEstimator< ALLOC > &  from,
const allocator_type alloc 
)

copy constructor with a given allocator

◆ ParamEstimator() [5/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::ParamEstimator ( ParamEstimator< ALLOC > &&  from)

move constructor

◆ ParamEstimator() [6/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::ParamEstimator< ALLOC >::ParamEstimator ( ParamEstimator< ALLOC > &&  from,
const allocator_type alloc 
)

move constructor with a given allocator

◆ ~ParamEstimator()

template<template< typename > class ALLOC = std::allocator>
virtual gum::learning::ParamEstimator< ALLOC >::~ParamEstimator ( )
virtual

destructor

Member Function Documentation

◆ clear()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::ParamEstimator< ALLOC >::clear ( )
virtual

clears all the data structures from memory

◆ clearRanges()

template<template< typename > class ALLOC = std::allocator>
void gum::learning::ParamEstimator< ALLOC >::clearRanges ( )

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

◆ clone() [1/2]

template<template< typename > class ALLOC = std::allocator>
virtual ParamEstimator< ALLOC >* gum::learning::ParamEstimator< ALLOC >::clone ( ) const
pure virtual

virtual copy constructor

Implemented in gum::learning::ParamEstimatorML< ALLOC >.

◆ clone() [2/2]

template<template< typename > class ALLOC = std::allocator>
virtual ParamEstimator< ALLOC >* gum::learning::ParamEstimator< ALLOC >::clone ( const allocator_type alloc) const
pure virtual

virtual copy constructor with a given allocator

Implemented in gum::learning::ParamEstimatorML< ALLOC >.

◆ database()

template<template< typename > class ALLOC = std::allocator>
const DatabaseTable< ALLOC >& gum::learning::ParamEstimator< ALLOC >::database ( ) const

returns the database on which we perform the counts

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN().

+ Here is the caller graph for this function:

◆ getAllocator()

template<template< typename > class ALLOC = std::allocator>
allocator_type gum::learning::ParamEstimator< ALLOC >::getAllocator ( ) const

returns the allocator used by the score

◆ minNbRowsPerThread()

template<template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::ParamEstimator< ALLOC >::minNbRowsPerThread ( ) const
virtual

returns the minimum of rows that each thread should process

◆ nbThreads()

template<template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::ParamEstimator< ALLOC >::nbThreads ( ) const
virtual

returns the number of threads used to parse the database

◆ nodeId2Columns()

template<template< typename > class ALLOC = std::allocator>
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >& gum::learning::ParamEstimator< ALLOC >::nodeId2Columns ( ) const

returns the mapping from ids to column positions in the database

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

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

template<template< typename > class ALLOC = std::allocator>
ParamEstimator< ALLOC >& gum::learning::ParamEstimator< ALLOC >::operator= ( const ParamEstimator< ALLOC > &  from)
protected

copy operator

◆ operator=() [2/2]

template<template< typename > class ALLOC = std::allocator>
ParamEstimator< ALLOC >& gum::learning::ParamEstimator< ALLOC >::operator= ( ParamEstimator< ALLOC > &&  from)
protected

move operator

◆ parameters() [1/2]

template<template< typename > class ALLOC = std::allocator>
std::vector< double, ALLOC< double > > gum::learning::ParamEstimator< ALLOC >::parameters ( const NodeId  target_node)

returns the CPT's parameters corresponding to a given target node

◆ parameters() [2/2]

template<template< typename > class ALLOC = std::allocator>
virtual std::vector< double, ALLOC< double > > gum::learning::ParamEstimator< ALLOC >::parameters ( const NodeId  target_node,
const std::vector< NodeId, ALLOC< NodeId > > &  conditioning_nodes 
)
pure 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).

Implemented in gum::learning::ParamEstimatorML< ALLOC >.

◆ ranges()

template<template< typename > class ALLOC = std::allocator>
const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > >& gum::learning::ParamEstimator< ALLOC >::ranges ( ) const

returns the current ranges

◆ setBayesNet()

template<template< typename > class ALLOC = std::allocator>
template<typename GUM_SCALAR >
void gum::learning::ParamEstimator< ALLOC >::setBayesNet ( const BayesNet< GUM_SCALAR > &  new_bn)

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.

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN().

+ Here is the caller graph for this function:

◆ setMaxNbThreads()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::ParamEstimator< ALLOC >::setMaxNbThreads ( std::size_t  nb) const
virtual

changes the max number of threads used to parse the database

◆ setMinNbRowsPerThread()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::ParamEstimator< ALLOC >::setMinNbRowsPerThread ( const std::size_t  nb) const
virtual

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.

◆ setParameters()

template<template< typename > class ALLOC = std::allocator>
template<typename GUM_SCALAR >
void gum::learning::ParamEstimator< ALLOC >::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

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.

Referenced by gum::learning::DAG2BNLearner< ALLOC >::createBN().

+ Here is the caller graph for this function:

◆ setRanges()

template<template< typename > class ALLOC = std::allocator>
template<template< typename > class XALLOC>
void gum::learning::ParamEstimator< ALLOC >::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

Parameters
rangesa 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.

Referenced by gum::learning::genericBNLearner::__createParamEstimator().

+ Here is the caller graph for this function:

Member Data Documentation

◆ _counter

template<template< typename > class ALLOC = std::allocator>
RecordCounter< ALLOC > gum::learning::ParamEstimator< ALLOC >::_counter
protected

the record counter used to parse the database

Definition at line 249 of file paramEstimator.h.

◆ _empty_nodevect

template<template< typename > class ALLOC = std::allocator>
const std::vector< NodeId, ALLOC< NodeId > > gum::learning::ParamEstimator< ALLOC >::_empty_nodevect
protected

an empty vector of nodes, used for empty conditioning

Definition at line 252 of file paramEstimator.h.

◆ _external_apriori

template<template< typename > class ALLOC = std::allocator>
Apriori< ALLOC >* gum::learning::ParamEstimator< ALLOC >::_external_apriori {nullptr}
protected

an external a priori

Definition at line 242 of file paramEstimator.h.

◆ _score_internal_apriori

template<template< typename > class ALLOC = std::allocator>
Apriori< ALLOC >* gum::learning::ParamEstimator< ALLOC >::_score_internal_apriori {nullptr}
protected

if a score was used for learning the structure of the PGM, this is the a priori internal to the score

Definition at line 246 of file paramEstimator.h.


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