![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
the class for computing Chi2 independence test scores More...
#include <agrum/BN/learning/scores/indepTestChi2.h>
Public Member Functions | |
Constructors / Destructors | |
| IndepTestChi2 (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 | |
| IndepTestChi2 (const DBRowGeneratorParser &parser, const Prior &prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >()) | |
| default constructor | |
| IndepTestChi2 (const IndepTestChi2 &from) | |
| copy constructor | |
| IndepTestChi2 (IndepTestChi2 &&from) noexcept | |
| move constructor | |
| IndepTestChi2 * | clone () const override |
| virtual copy constructor | |
| ~IndepTestChi2 () override | |
| destructor | |
Operators | |
| IndepTestChi2 & | operator= (const IndepTestChi2 &from) |
| copy operator | |
| IndepTestChi2 & | operator= (IndepTestChi2 &&from) noexcept |
| move operator | |
Statistics | |
| std::pair< double, double > | statistics (NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids={}) override |
| get the pair <chi2 statistic,pvalue> for a test var1 indep var2 given rhs_ids | |
Accessors / Modifiers | |
| void | setNumberOfThreads (Size nb) override |
| sets the number max of threads that can be used | |
| Size | getNumberOfThreads () const override |
| returns the current max number of threads of the scheduler | |
| bool | isGumNumberOfThreadsOverriden () const override |
| 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 | |
| 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 | |
| virtual void | clear () |
| clears all the data structures from memory, including the cache | |
| virtual void | clearCache () |
| clears the current cache | |
| virtual void | useCache (const bool on_off) |
| turn on/off the use of a cache of the previously computed score | |
| 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 | |
Protected Member Functions | |
| std::pair< double, double > | statistics_ (const IdCondSet &idset) |
| compute the pair <chi2 statistic,pvalue> | |
| std::vector< double > | marginalize_ (const std::size_t node_2_marginalize, const std::size_t X_size, const std::size_t Y_size, const std::size_t Z_size, const std::vector< double > &N_xyz) const |
| returns a counting vector where variables are marginalized from N_xyz | |
| template<typename CellContribFn> | |
| std::pair< double, double > | computeStatistics_ (const IdCondSet &idset, CellContribFn cellContrib) |
| shared loop for chi-squared-family statistics | |
Static Protected Member Functions | |
| static Size | degreesOfFreedom_ (std::size_t X_size, std::size_t Y_size, std::size_t Z_size=1, std::size_t n_skipped=0) |
| returns the degrees of freedom for a chi2/G2 test X _|_ Y | Z | |
Protected Attributes | |
| std::vector< std::size_t > | _domain_sizes_ |
| the domain sizes of the variables (indexed by column id in the database) | |
| const double | one_log2_ {M_LOG2E} |
| 1 / log(2) | |
| Prior * | prior_ {nullptr} |
| the expert knowledge prior added to the contingency tables | |
| 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 class for computing Chi2 independence test scores
Definition at line 63 of file indepTestChi2.h.
| gum::learning::IndepTestChi2::IndepTestChi2 | ( | 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): this consists in adding numbers to counts in the contingency tables |
| 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 gum::learning::CachedContingencyCounter::ranges().
Referenced by IndepTestChi2(), IndepTestChi2(), clone(), operator=(), and operator=().
| gum::learning::IndepTestChi2::IndepTestChi2 | ( | const DBRowGeneratorParser & | parser, |
| const Prior & | prior, | ||
| const Bijection< NodeId, std::size_t > & | nodeId2columns = Bijection< NodeId, std::size_t >() ) |
default constructor
| parser | the parser used to parse the database |
| prior | An prior 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. |
| gum::learning::IndepTestChi2::IndepTestChi2 | ( | const IndepTestChi2 & | from | ) |
|
noexcept |
|
override |
destructor
|
virtualinherited |
clears all the data structures from memory, including the cache
Reimplemented in gum::learning::KNML.
|
virtualinherited |
clears the current cache
Reimplemented in gum::learning::KNML.
|
inherited |
reset the ranges to the one range corresponding to the whole database
|
nodiscardoverridevirtual |
virtual copy constructor
Implements gum::learning::IndependenceTest.
References IndepTestChi2().
|
protectedinherited |
shared loop for chi-squared-family statistics
Handles counts, marginalisation, structural-zero detection and the final p-value. Only active cells (margX * margY != 0) are forwarded to cellContrib; sampling zeros must be handled inside the lambda. Signature: double cellContrib(double O, double margX, double margY, double total)
|
inherited |
return the database used by the score
|
staticprotectedinherited |
returns the degrees of freedom for a chi2/G2 test X _|_ Y | Z
| X_size | domain size of X |
| Y_size | domain size of Y |
| Z_size | product of domain sizes of the conditioning variables (1 if no conditioning set) |
| n_skipped | number of cells excluded from the statistic sum because their expected count is zero (silent cells). Each such cell effectively removes one degree of freedom. The result is clamped to 1 to keep the distribution well-defined. |
|
overridevirtualinherited |
returns the current max number of threads of the scheduler
Implements gum::IThreadNumberManager.
|
overridevirtualinherited |
indicates whether the user set herself the number of threads
Implements gum::IThreadNumberManager.
|
protectedinherited |
returns a counting vector where variables are marginalized from N_xyz
| node_2_marginalize | indicates which node(s) shall be marginalized:
|
| X_size | the domain size of variable X |
| Y_size | the domain size of variable Y |
| Z_size | the domain size of the set of conditioning variables Z |
| N_xyz | a counting vector of dimension X * Y * Z (in this order) |
|
virtualinherited |
returns the minimum of rows that each thread should process
|
inherited |
return the mapping between the columns of the database and the node ids
| IndepTestChi2 & gum::learning::IndepTestChi2::operator= | ( | const IndepTestChi2 & | from | ) |
|
noexcept |
|
inherited |
returns the current ranges
Referenced by CachedContingencyCounter(), gum::learning::IndependenceTest::IndependenceTest(), gum::learning::IndepTestChi2::IndepTestChi2(), gum::learning::IndepTestG2::IndepTestG2(), and gum::learning::KNML::KNML().
|
virtualinherited |
changes the number min of rows a thread should process in a multithreading context
|
overridevirtualinherited |
sets the number max of threads that can be used
Implements gum::IThreadNumberManager.
|
inherited |
sets new ranges to perform the counts
|
overridevirtual |
get the pair <chi2 statistic,pvalue> for a test var1 indep var2 given rhs_ids
Implements gum::learning::IndependenceTest.
Referenced by gum::learning::IBNLearner::chi2().
|
protected |
compute the pair <chi2 statistic,pvalue>
|
virtualinherited |
turn on/off the use of a cache of the previously computed score
Reimplemented in gum::learning::KNML.
|
protectedinherited |
the domain sizes of the variables (indexed by column id in the database)
Definition at line 148 of file independenceTest.h.
|
protectedinherited |
the scoring cache
Definition at line 171 of file cachedContingencyCounter.h.
|
protectedinherited |
the record counter used for the counts over discrete variables
Definition at line 168 of file cachedContingencyCounter.h.
|
protectedinherited |
an empty vector
Definition at line 177 of file cachedContingencyCounter.h.
|
protectedinherited |
the expert knowledge prior added to the contingency tables
Definition at line 165 of file cachedContingencyCounter.h.
|
protectedinherited |
a Boolean indicating whether we wish to use the cache
Definition at line 174 of file cachedContingencyCounter.h.