![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
the class for computing Log2-likelihood scores More...
#include <agrum/BN/learning/scores_and_tests/scoreLog2Likelihood.h>
Public Member Functions | |
Constructors / Destructors | |
ScoreLog2Likelihood (const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &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... | |
ScoreLog2Likelihood (const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &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... | |
ScoreLog2Likelihood (const ScoreLog2Likelihood< ALLOC > &from) | |
copy constructor More... | |
ScoreLog2Likelihood (const ScoreLog2Likelihood< ALLOC > &from, const allocator_type &alloc) | |
copy constructor with a given allocator More... | |
ScoreLog2Likelihood (ScoreLog2Likelihood< ALLOC > &&from) | |
move constructor More... | |
ScoreLog2Likelihood (ScoreLog2Likelihood< ALLOC > &&from, const allocator_type &alloc) | |
move constructor with a given allocator More... | |
virtual ScoreLog2Likelihood< ALLOC > * | clone () const |
virtual copy constructor More... | |
virtual ScoreLog2Likelihood< ALLOC > * | clone (const allocator_type &alloc) const |
virtual copy constructor with a given allocator More... | |
virtual | ~ScoreLog2Likelihood () |
destructor More... | |
Operators | |
ScoreLog2Likelihood< ALLOC > & | operator= (const ScoreLog2Likelihood< ALLOC > &from) |
copy operator More... | |
ScoreLog2Likelihood< ALLOC > & | operator= (ScoreLog2Likelihood< ALLOC > &&from) |
move operator More... | |
Accessors / Modifiers | |
virtual std::string | isAprioriCompatible () const final |
indicates whether the apriori is compatible (meaningful) with the score More... | |
virtual const Apriori< ALLOC > & | internalApriori () const final |
returns the internal apriori of the score More... | |
double | score (const IdCondSet< ALLOC > &idset) |
returns the score for a given IdCondSet More... | |
Accessors / Modifiers | |
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 score 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... | |
double | score (const NodeId var) |
returns the score of a single node More... | |
double | score (const NodeId var, const std::vector< NodeId, ALLOC< NodeId > > &rhs_ids) |
returns the score of a single node given some other nodes More... | |
void | clear () |
clears all the data structures from memory, including the cache More... | |
void | clearCache () |
clears the current cache More... | |
void | useCache (const bool on_off) |
turn on/off the use of a cache of the previously computed score More... | |
bool | isUsingCache () const |
indicates whether the score uses a cache More... | |
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > & | nodeId2Columns () const |
return the mapping between the columns of the database and the node ids More... | |
const DatabaseTable< ALLOC > & | database () const |
return the database used by the score More... | |
allocator_type | getAllocator () const |
returns the allocator used by the score More... | |
Static Public Member Functions | |
static std::string | isAprioriCompatible (const std::string &apriori_type, double weight=1.0f) |
indicates whether the apriori is compatible (meaningful) with the score More... | |
static std::string | isAprioriCompatible (const Apriori< ALLOC > &apriori) |
indicates whether the apriori is compatible (meaningful) with the score More... | |
Public Types | |
using | allocator_type = ALLOC< NodeId > |
type for the allocators passed in arguments of methods More... | |
Protected Attributes | |
const double | one_log2_ {M_LOG2E} |
1 / log(2) More... | |
Apriori< ALLOC > * | apriori_ {nullptr} |
the expert knowledge a priori we add to the score More... | |
RecordCounter< ALLOC > | counter_ |
the record counter used for the countings over discrete variables More... | |
ScoringCache< ALLOC > | cache_ |
the scoring cache More... | |
bool | use_cache_ {true} |
a Boolean indicating whether we wish to use the cache More... | |
const std::vector< NodeId, ALLOC< NodeId > > | empty_ids_ |
an empty vector More... | |
Protected Member Functions | |
virtual double | score_ (const IdCondSet< ALLOC > &idset) final |
returns the score for a given IdCondSet More... | |
std::vector< double, ALLOC< double > > | marginalize_ (const NodeId X_id, const std::vector< double, ALLOC< double > > &N_xyz) const |
returns a counting vector where variables are marginalized from N_xyz More... | |
the class for computing Log2-likelihood scores
Definition at line 51 of file scoreLog2Likelihood.h.
using gum::learning::ScoreLog2Likelihood< ALLOC >::allocator_type = ALLOC< NodeId > |
type for the allocators passed in arguments of methods
Definition at line 54 of file scoreLog2Likelihood.h.
gum::learning::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | const DBRowGeneratorParser< ALLOC > & | parser, |
const Apriori< ALLOC > & | 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 |
apriori | An apriori that we add to the computation of the score |
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::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | const DBRowGeneratorParser< ALLOC > & | parser, |
const Apriori< ALLOC > & | 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 |
apriori | An apriori that we add to the computation of the score |
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::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | const ScoreLog2Likelihood< ALLOC > & | from | ) |
copy constructor
gum::learning::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | const ScoreLog2Likelihood< ALLOC > & | from, |
const allocator_type & | alloc | ||
) |
copy constructor with a given allocator
gum::learning::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | ScoreLog2Likelihood< ALLOC > && | from | ) |
move constructor
gum::learning::ScoreLog2Likelihood< ALLOC >::ScoreLog2Likelihood | ( | ScoreLog2Likelihood< ALLOC > && | from, |
const allocator_type & | alloc | ||
) |
move constructor with a given allocator
|
virtual |
destructor
|
inherited |
clears all the data structures from memory, including the cache
|
inherited |
clears the current cache
|
inherited |
reset the ranges to the one range corresponding to the whole database
|
virtual |
virtual copy constructor
Implements gum::learning::Score< ALLOC >.
|
virtual |
virtual copy constructor with a given allocator
Implements gum::learning::Score< ALLOC >.
|
inherited |
return the database used by the score
|
inherited |
returns the allocator used by the score
|
finalvirtual |
returns the internal apriori of the score
Some scores include an apriori. For instance, the K2 score is a BD score with a Laplace Apriori ( smoothing(1) ). BDeu is a BD score with a N'/(r_i * q_i) apriori, 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 apriori classes is to enable to account for these aprioris 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 aprioris are taken into account during structure learning and parameter learning.
Implements gum::learning::Score< ALLOC >.
|
finalvirtual |
indicates whether the apriori is compatible (meaningful) with the score
The combination of some scores and aprioris can be meaningless. For instance, adding a Dirichlet apriori to the K2 score is not very meaningful since K2 corresonds to a BD score with a 1-smoothing apriori. aGrUM allows you to perform such combination, but you can check with method isAprioriCompatible () whether the result the score will give you is meaningful or not.
Implements gum::learning::Score< ALLOC >.
|
static |
indicates whether the apriori is compatible (meaningful) with the score
|
static |
indicates whether the apriori is compatible (meaningful) with the score
a non empty string if the apriori is compatible with the score.
|
inherited |
indicates whether the score uses a cache
|
protectedinherited |
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) |
|
virtualinherited |
returns the minimum of rows that each thread should process
|
virtualinherited |
returns the number of threads used to parse the database
|
inherited |
return the mapping between the columns of the database and the node ids
ScoreLog2Likelihood< ALLOC >& gum::learning::ScoreLog2Likelihood< ALLOC >::operator= | ( | const ScoreLog2Likelihood< ALLOC > & | from | ) |
copy operator
ScoreLog2Likelihood< ALLOC >& gum::learning::ScoreLog2Likelihood< ALLOC >::operator= | ( | ScoreLog2Likelihood< ALLOC > && | from | ) |
move operator
|
inherited |
returns the current ranges
|
inherited |
returns the score of a single node
|
inherited |
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 |
double gum::learning::ScoreLog2Likelihood< ALLOC >::score | ( | const IdCondSet< ALLOC > & | idset | ) |
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). |
|
finalprotectedvirtual |
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). |
Implements gum::learning::Score< ALLOC >.
|
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 new ranges to perform the countings used by the score
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. |
|
inherited |
turn on/off the use of a cache of the previously computed score
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |