aGrUM
0.13.2

The counting class for all the scores used for learning (BIC, BDeu, etc) as well as for all the independence tests. More...
#include <counter.h>
Public Member Functions  
Constructors / Destructors  
template<typename RowFilter >  
Counter (const RowFilter &filter, const std::vector< Size > &var_modalities, Size min_range=0, Size max_range=std::numeric_limits< Size >::max())  
default constructor More...  
Counter (const Counter< IdSetAlloc, CountAlloc > &)  
copy constructor More...  
Counter (Counter< IdSetAlloc, CountAlloc > &&)  
move constructor More...  
virtual  ~Counter () 
destructor More...  
Modifiers for unconditioned variables  
Idx  addEmptyNodeSet () 
adds an empty set of variables to count More...  
Idx  addNodeSet (Idx var) 
add a new single variable to be counted More...  
Modifiers for conditioned variables  
Idx  addNodeSet (Idx var1, Idx var2) 
add a new target node conditioned by another node to be counted More...  
Idx  addNodeSet (const std::pair< Idx, Idx > &vars) 
add a new target node conditioned by another node to be counted More...  
Idx  addNodeSet (Idx var, const std::vector< Idx > &conditioning_ids) 
add a new target variable plus some conditioning vars More...  
Idx  addNodeSet (Idx var, std::vector< Idx > &&conditioning_ids) 
add a new target variable plus some conditioning vars More...  
Idx  addNodeSet (Idx var1, Idx var2, const std::vector< Idx > &conditioning_ids) 
add a target conditioned by other variables to be counted More...  
Idx  addNodeSet (Idx var1, Idx var2, std::vector< Idx > &&conditioning_ids) 
add a target conditioned by other variables to be counted More...  
Idx  addNodeSet (const std::pair< Idx, Idx > &vars, const std::vector< Idx > &conditioning_ids) 
add a target conditioned by other variables to be counted More...  
Idx  addNodeSet (const std::pair< Idx, Idx > &vars, std::vector< Idx > &&conditioning_ids) 
add a target conditioned by other variables to be counted More...  
Accessors / General modifiers  
void  clear () 
clears all the data structures from memory More...  
const std::vector< Size > &  modalities () const noexcept 
returns the modalities of the variables More...  
void  setMaxNbThreads (Size nb) noexcept 
sets the maximum number of threads used to perform countings More...  
void  setRange (Size min_range, Size max_range) 
sets the range of records taken into account by the counter More...  
Protected Attributes  
const double  _1log2 {M_LOG2E} 
1 / log(2) More...  
const std::vector< Size > &  _modalities 
the modalities of the variables More...  
bool  _counts_computed {false} 
indicates whether we have already computed the countings of the nodesets More...  
RecordCounter< IdSetAlloc, CountAlloc >  _record_counter 
the recordCounter that will parse the database More...  
std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx > * >  _target_nodesets 
the target id sets to count and their indices in the record counter More...  
std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx > * >  _conditioning_nodesets 
the conditioning id sets to count and their indices in the record counter More...  
Protected Member Functions  
void  _count () 
perform the computation of the countings More...  
const std::vector< double, CountAlloc > &  _getAllCounts (Idx index) 
returns the counting vector for a given (conditioned) target set More...  
const std::vector< double, CountAlloc > &  _getConditioningCounts (Idx index) 
returns the counting vector for a conditioning set More...  
std::vector< std::vector< double, CountAlloc > > &  _getCounts () noexcept 
returns all the countings performed (both targets and conditioned) More...  
const std::vector< Idx, IdSetAlloc > &  _getAllNodes (Idx index) const noexcept 
returns the set of target + conditioning nodes More...  
const std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx > * > &  _getAllNodes () const noexcept 
returns all the sets of target + cond nodes, and their counting indices More...  
const std::vector< Idx, IdSetAlloc > *  _getConditioningNodes (Idx index) const noexcept 
returns the conditioning nodes (nullptr if there are no such nodes) More...  
const std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx > * > &  _getConditioningNodes () const noexcept 
returns all the sets of conditioning nodes More...  
Counter< IdSetAlloc, CountAlloc > &  operator= (const Counter< IdSetAlloc, CountAlloc > &)=delete 
prevent copy operator More...  
The counting class for all the scores used for learning (BIC, BDeu, etc) as well as for all the independence tests.
This class contains all the methods that enable to add (possibly conditioned) nodesets to be subsequently counted to produce a score or the result of an independence test. The class considers both symmetric and asymmetric scores or tests. Basically, a symmetric test involves two variables X and Y and, possibly a conditioning set of variables Z. The test usually relies on an equation involving quantities #XYZ, #XZ, #YZ and #Z, where "@#" refer to observation counts or frequencies. For instance, the Chi2 independence test uses the following formula: (#XYZ
The class should be used as follows: first, to speedup computations, you should consider computing all the scores or tests you need in one pass because this enables parsing the database once in order to fill many counting vectors. To do so, use the appropriate addNodeSet methods. These will compute everything you need. The addNodeSet methods where you do not specify a set of conditioning nodes assume that this set is empty. Once the computations have been performed, use methods _getAllCounts and _getConditioningCounts to get the countings that have been performed. Note that this class is not intended to be used as is, but is rather a basis for classes Score and IndependenceTest.
gum::learning::Counter< IdSetAlloc, CountAlloc >::Counter  (  const RowFilter &  filter, 
const std::vector< Size > &  var_modalities,  
Size  min_range = 0 , 

Size  max_range = std::numeric_limits< Size >::max() 

) 
default constructor
filter  the row filter that will be used to read the database 
var_modalities  the domain sizes of the variables in the database 
min_range  The minimal range 
max_range  The maximal range 
gum::learning::Counter< IdSetAlloc, CountAlloc >::Counter  (  const Counter< IdSetAlloc, CountAlloc > &  ) 
copy constructor
gum::learning::Counter< IdSetAlloc, CountAlloc >::Counter  (  Counter< IdSetAlloc, CountAlloc > &&  ) 
move constructor

virtual 
destructor

protected 
perform the computation of the countings

protected 
returns the counting vector for a given (conditioned) target set
This method returns the observtion countings for the set of variables whose index was returned by method addNodeSet or addNodeSet. If the set was conditioned, the countings correspond to the target variables and the conditioning variables. If you wish to get only the countings for the conditioning variables, prefer using method countConditioning.

protectednoexcept 
returns the set of target + conditioning nodes
conditioning nodes are always the first ones in the vector and targets are the last ones

protectednoexcept 
returns all the sets of target + cond nodes, and their counting indices
conditioning nodes are always the first ones in the vector and targets are the last ones

protected 
returns the counting vector for a conditioning set

protectednoexcept 
returns the conditioning nodes (nullptr if there are no such nodes)

protectednoexcept 
returns all the sets of conditioning nodes

protectednoexcept 
returns all the countings performed (both targets and conditioned)
this method returns the countings of the record counter. It should be used in conjunction with methods _getConditioningNodes () and _getTargetNodes () that indicate, for each nodeset, the index of the corresponding counting in the vector returned by _getCounts ().
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addEmptyNodeSet  (  ) 
adds an empty set of variables to count
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var  ) 
add a new single variable to be counted
var  represents the index of the variable in the filtered rows produced by the database cell filters whose observations shall be counted 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var1, 
Idx  var2  
) 
add a new target node conditioned by another node to be counted
var1  represents the index of the target variable in the filtered rows produced by the database cell filters 
var2  represents the index of the conditioning variable in the filtered rows produced by the database cell filters 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  const std::pair< Idx, Idx > &  vars  ) 
add a new target node conditioned by another node to be counted
vars  contains the index of the target variable (first) in the filtered rows produced by the database cell filters, and the index of the conditioning variable (second). 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var, 
const std::vector< Idx > &  conditioning_ids  
) 
add a new target variable plus some conditioning vars
var  represents the index of the target variable in the filtered rows produced by the database cell filters 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var, 
std::vector< Idx > &&  conditioning_ids  
) 
add a new target variable plus some conditioning vars
var  represents the index of the target variable in the filtered rows produced by the database cell filters 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var1, 
Idx  var2,  
const std::vector< Idx > &  conditioning_ids  
) 
add a target conditioned by other variables to be counted
var1  represents the index of the target variable in the filtered rows produced by the database cell filters 
var2  represents the index of the last conditioning variable in the filtered rows produced by the database cell filters 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows (minus var2, which is subsequently apended to it). 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  Idx  var1, 
Idx  var2,  
std::vector< Idx > &&  conditioning_ids  
) 
add a target conditioned by other variables to be counted
var1  represents the index of the target variable in the filtered rows produced by the database cell filters 
var2  represents the index of the last conditioning variable in the filtered rows produced by the database cell filters 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows (minus var2, which is subsequently apended to it). 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  const std::pair< Idx, Idx > &  vars, 
const std::vector< Idx > &  conditioning_ids  
) 
add a target conditioned by other variables to be counted
vars  represents the index of the target variable (first) in the filtered rows produced by the database cell filters, and the index of the last conditioning variable (second) 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows (minus vars.second which is appended to it) 
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet  (  const std::pair< Idx, Idx > &  vars, 
std::vector< Idx > &&  conditioning_ids  
) 
add a target conditioned by other variables to be counted
vars  represents the index of the target variable (first) in the filtered rows produced by the database cell filters, and the index of the last conditioning variable (second) 
conditioning_ids  the indices of the variables of the conditioning set in the filtered rows (minus vars.second which is appended to it) 
void gum::learning::Counter< IdSetAlloc, CountAlloc >::clear  (  ) 
clears all the data structures from memory

noexcept 
returns the modalities of the variables

protecteddelete 
prevent copy operator

noexcept 
sets the maximum number of threads used to perform countings
void gum::learning::Counter< IdSetAlloc, CountAlloc >::setRange  (  Size  min_range, 
Size  max_range  
) 
sets the range of records taken into account by the counter
min_range  he number of the first record to be taken into account during learning 
max_range  the number of the record after the last one taken into account 

protected 

protected 

protected 

protected 

protected 

protected 