![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
The base class for all the scores used for learning (BIC, BDeu, etc). More...
#include <agrum/BN/learning/scores_and_tests/score.h>
Public Member Functions | |
Constructors / Destructors | |
| Score (const DBRowGeneratorParser &parser, const Prior &external_prior, const std::vector< std::pair< std::size_t, std::size_t > > &ranges, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >()) | |
| default constructor | |
| Score (const DBRowGeneratorParser &parser, const Prior &external_prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >()) | |
| default constructor | |
| virtual Score * | clone () const =0 |
| virtual copy constructor | |
| virtual | ~Score () |
| destructor | |
Accessors / Modifiers | |
| virtual void | setNumberOfThreads (Size nb) |
| sets the number max of threads that can be used | |
| virtual Size | getNumberOfThreads () const |
| returns the current max number of threads of the scheduler | |
| virtual bool | isGumNumberOfThreadsOverriden () const |
| indicates whether the user set herself the number of threads | |
| virtual void | setMinNbRowsPerThread (const std::size_t nb) const |
| changes the number min of rows a thread should process in a multithreading context | |
| virtual std::size_t | minNbRowsPerThread () const |
| returns the minimum of rows that each thread should process | |
| void | setRanges (const std::vector< std::pair< std::size_t, std::size_t > > &new_ranges) |
| sets new ranges to perform the counts used by the score | |
| void | clearRanges () |
| reset the ranges to the one range corresponding to the whole database | |
| const std::vector< std::pair< std::size_t, std::size_t > > & | ranges () const |
| returns the current ranges | |
| double | score (const NodeId var) |
| returns the score of a single node | |
| double | score (const NodeId var, const std::vector< NodeId > &rhs_ids) |
| returns the score of a single node given some other nodes | |
| void | clear () |
| clears all the data structures from memory, including the cache | |
| void | clearCache () |
| clears the current cache | |
| void | useCache (const bool on_off) |
| turn on/off the use of a cache of the previously computed score | |
| bool | isUsingCache () const |
| indicates whether the score uses a cache | |
| const Bijection< NodeId, std::size_t > & | nodeId2Columns () const |
| return the mapping between the columns of the database and the node ids | |
| const DatabaseTable & | database () const |
| return the database used by the score | |
| virtual std::string | isPriorCompatible () const =0 |
| indicates whether the prior is compatible (meaningful) with the score | |
| virtual const Prior & | internalPrior () const =0 |
| returns the internal prior of the score | |
Protected Member Functions | |
| Score (const Score &from) | |
| copy constructor | |
| Score (Score &&from) | |
| move constructor | |
| Score & | operator= (const Score &from) |
| copy operator | |
| Score & | operator= (Score &&from) |
| move operator | |
| virtual double | score_ (const IdCondSet &idset)=0 |
| returns the score for a given IdCondSet | |
| std::vector< double > | marginalize_ (const NodeId X_id, const std::vector< double > &N_xyz) const |
| returns a counting vector where variables are marginalized from N_xyz | |
Protected Attributes | |
| const double | one_log2_ {M_LOG2E} |
| 1 / log(2) | |
| Prior * | prior_ {nullptr} |
| the expert knowledge a priorwe add to the score | |
| RecordCounter | counter_ |
| the record counter used for the counts over discrete variables | |
| ScoringCache | cache_ |
| the scoring cache | |
| bool | use_cache_ {true} |
| a Boolean indicating whether we wish to use the cache | |
| const std::vector< NodeId > | empty_ids_ |
| an empty vector | |
The base class for all the scores used for learning (BIC, BDeu, etc).
| gum::learning::Score::Score | ( | const DBRowGeneratorParser & | parser, |
| const Prior & | external_prior, | ||
| const std::vector< std::pair< std::size_t, std::size_t > > & | ranges, | ||
| const Bijection< NodeId, std::size_t > & | nodeId2columns = Bijection< NodeId, std::size_t >() ) |
default constructor
| parser | the parser used to parse the database |
| external_prior | An prior that we add to the computation of the score (this should come from expert knowledge) |
| ranges | a set of pairs {(X1,Y1),...,(Xn,Yn)} of database's rows indices. The counts 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. |
References ranges().
Referenced by Score(), Score(), clone(), gum::learning::ScoreLog2Likelihood::internalPrior(), operator=(), and operator=().
| gum::learning::Score::Score | ( | const DBRowGeneratorParser & | parser, |
| const Prior & | external_prior, | ||
| const Bijection< NodeId, std::size_t > & | nodeId2columns = Bijection< NodeId, std::size_t >() ) |
default constructor
| parser | the parser used to parse the database |
| external_prior | An prior that we add to the computation of the score (this should come from expert knowledge) |
| 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. |
|
virtual |
destructor
|
protected |
|
protected |
| void gum::learning::Score::clear | ( | ) |
clears all the data structures from memory, including the cache
| void gum::learning::Score::clearCache | ( | ) |
clears the current cache
| void gum::learning::Score::clearRanges | ( | ) |
reset the ranges to the one range corresponding to the whole database
|
pure virtual |
virtual copy constructor
Implemented in gum::learning::ScoreAIC, gum::learning::ScoreBD, gum::learning::ScoreBDeu, gum::learning::ScoreBIC, gum::learning::ScorefNML, gum::learning::ScoreK2, and gum::learning::ScoreLog2Likelihood.
References Score().
| const DatabaseTable & gum::learning::Score::database | ( | ) | const |
return the database used by the score
|
virtual |
returns the current max number of threads of the scheduler
Implements gum::IThreadNumberManager.
|
pure virtual |
returns the internal prior of the score
Some scores include an prior. For instance, the K2 score is a BD score with a Laplace Prior ( smoothing(1) ). BDeu is a BD score with a N'/(r_i * q_i) prior, where N' is an effective sample size and r_i is the domain size of the target variable and q_i is the domain size of the Cartesian product of its parents. The goal of the score's internal prior classes is to enable to account for these priors outside the score, e.g., when performing parameter estimation. It is important to note that, to be meaningful, a structure + parameter learning requires that the same priors are taken into account during structure learning and parameter learning.
Implemented in gum::learning::ScoreAIC, gum::learning::ScoreBD, gum::learning::ScoreBDeu, gum::learning::ScoreBIC, gum::learning::ScorefNML, gum::learning::ScoreK2, and gum::learning::ScoreLog2Likelihood.
|
virtual |
indicates whether the user set herself the number of threads
Implements gum::IThreadNumberManager.
|
pure virtual |
indicates whether the prior is compatible (meaningful) with the score
The combination of some scores and priors can be meaningless. For instance, adding a Dirichlet prior to the K2 score is not very meaningful since K2 corresonds to a BD score with a 1-smoothing prior. aGrUM allows you to perform such combination, but you can check with method isPriorCompatible () whether the result the score will give you is meaningful or not.
Implemented in gum::learning::ScoreAIC, gum::learning::ScoreBD, gum::learning::ScoreBDeu, gum::learning::ScoreBIC, gum::learning::ScorefNML, gum::learning::ScoreK2, and gum::learning::ScoreLog2Likelihood.
| bool gum::learning::Score::isUsingCache | ( | ) | const |
indicates whether the score uses a cache
|
protected |
returns a counting vector where variables are marginalized from N_xyz
| X_id | the id of the variable to marginalize (this is the first variable in table N_xyz |
| N_xyz | a counting vector of dimension X * cond_vars (in this order) |
|
virtual |
returns the minimum of rows that each thread should process
return the mapping between the columns of the database and the node ids
| const std::vector< std::pair< std::size_t, std::size_t > > & gum::learning::Score::ranges | ( | ) | const |
returns the current ranges
Referenced by Score(), gum::learning::ScoreAIC::ScoreAIC(), gum::learning::ScoreBD::ScoreBD(), gum::learning::ScoreBDeu::ScoreBDeu(), gum::learning::ScoreBIC::ScoreBIC(), gum::learning::ScorefNML::ScorefNML(), gum::learning::ScoreK2::ScoreK2(), and gum::learning::ScoreLog2Likelihood::ScoreLog2Likelihood().
returns the score of a single node given some other nodes
| var | the variable on the left side of the conditioning bar |
| rhs_ids | the set of variables on the right side of the conditioning bar |
returns the score for a given IdCondSet
| OperationNotAllowed | is raised if the score does not support calling method score such an idset (due to too many/too few variables in the left hand side or the right hand side of the idset). |
Implemented in gum::learning::ScoreAIC, gum::learning::ScoreBD, gum::learning::ScoreBDeu, gum::learning::ScoreBIC, gum::learning::ScorefNML, gum::learning::ScoreK2, and gum::learning::ScoreLog2Likelihood.
|
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 counts 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.
|
virtual |
sets the number max of threads that can be used
| nb | the 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.
| void gum::learning::Score::setRanges | ( | const std::vector< std::pair< std::size_t, std::size_t > > & | new_ranges | ) |
sets new ranges to perform the counts used by the score
| ranges | a set of pairs {(X1,Y1),...,(Xn,Yn)} of database's rows indices. The counts 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. |
| void gum::learning::Score::useCache | ( | const bool | on_off | ) |
turn on/off the use of a cache of the previously computed score
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |