aGrUM  0.13.2
gum::learning::PartialEntropy< IdSetAlloc, CountAlloc > Class Template Reference

#include <partialEntropy.h>

+ Inheritance diagram for gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >:
+ Collaboration diagram for gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >:

Public Member Functions

Constructors / Destructors
template<typename RowFilter >
 PartialEntropy (const RowFilter &filter, const std::vector< Size > &var_modalities, Size min_range=0, Size max_range=std::numeric_limits< Size >::max())
 
 ~PartialEntropy ()
 
Accessors / Modifiers
Idx addNodeSet (const std::vector< Idx > &var_set)
 clears all the data structures from memory More...
 
Idx addNodeSet (Idx var)
 clears all the data structures from memory More...
 
Idx addNodeSet (Idx var1, Idx var2)
 clears all the data structures from memory More...
 
void clear ()
 clears all the data structures from memory More...
 
void clearCache ()
 clears the current cache (clear nodesets as well) More...
 
void useCache (bool on_off) noexcept
 turn on/off the use of a cache of the previously computed score More...
 
double score (Idx nodeset_index)
 returns the score corresponding to a given nodeset More...
 
void setRange (Size min_range, Size max_range)
 sets the range of records taken into account by the counter More...
 
const Size N ()
 return the size of the database More...
 
Modifiers for unconditioned variables
Idx addEmptyNodeSet ()
 adds an empty set of variables to count More...
 
Modifiers for conditioned variables
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
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...
 

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

bool _isInCache (Idx nodeset_index) const noexcept
 indicates whether a score belongs to the cache More...
 
void _insertIntoCache (Idx nodeset_index, double score)
 inserts a new score into the cache More...
 
double _cachedScore (Idx nodeset_index) const noexcept
 returns a cached score More...
 
bool _isUsingCache () const noexcept
 indicates whether we use the cache or not More...
 
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...
 

Detailed Description

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
class gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >

Definition at line 51 of file partialEntropy.h.

Constructor & Destructor Documentation

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
template<typename RowFilter >
gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::PartialEntropy ( const RowFilter &  filter,
const std::vector< Size > &  var_modalities,
Size  min_range = 0,
Size  max_range = std::numeric_limits< Size >::max() 
)
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::~PartialEntropy ( )

Member Function Documentation

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
double gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::_cachedScore ( Idx  nodeset_index) const
protectednoexcept

returns a cached score

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::Counter< IdSetAlloc, CountAlloc >::_count ( )
protectedinherited

perform the computation of the countings

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< double, CountAlloc >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getAllCounts ( Idx  index)
protectedinherited

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.

Warning
the dimensions of the vector are as follows: first come the nodes of the conditioning set (in the order in which they were specified when callind addNodeset, and then the target nodes).
whenever you call this function, if the counts have not been computed yet, they are computed before the function returns.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< Idx, IdSetAlloc >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getAllNodes ( Idx  index) const
protectednoexceptinherited

returns the set of target + conditioning nodes

conditioning nodes are always the first ones in the vector and targets are the last ones

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx >* >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getAllNodes ( ) const
protectednoexceptinherited

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

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< double, CountAlloc >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getConditioningCounts ( Idx  index)
protectedinherited

returns the counting vector for a conditioning set

Warning
whenever you call this function, if the counts have not been computed yet, they are computed before the function returns.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< Idx, IdSetAlloc >* gum::learning::Counter< IdSetAlloc, CountAlloc >::_getConditioningNodes ( Idx  index) const
protectednoexceptinherited

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

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx >* >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getConditioningNodes ( ) const
protectednoexceptinherited

returns all the sets of conditioning nodes

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
std::vector< std::vector< double, CountAlloc > >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_getCounts ( )
protectednoexceptinherited

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 ().

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::_insertIntoCache ( Idx  nodeset_index,
double  score 
)
protected

inserts a new score into the cache

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
bool gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::_isInCache ( Idx  nodeset_index) const
protectednoexcept

indicates whether a score belongs to the cache

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
bool gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::_isUsingCache ( ) const
protectednoexcept

indicates whether we use the cache or not

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addEmptyNodeSet ( )
inherited

adds an empty set of variables to count

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::addNodeSet ( const std::vector< Idx > &  var_set)

clears all the data structures from memory

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var)

clears all the data structures from memory

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var1,
Idx  var2 
)

clears all the data structures from memory

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( const std::pair< Idx, Idx > &  vars)
inherited

add a new target node conditioned by another node to be counted

Parameters
varscontains 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).
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the counts in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the observed countings of (vars.second, vars.first) [in this order] and vars.second respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var,
const std::vector< Idx > &  conditioning_ids 
)
inherited

add a new target variable plus some conditioning vars

Parameters
varrepresents the index of the target variable in the filtered rows produced by the database cell filters
conditioning_idsthe indices of the variables of the conditioning set in the filtered rows
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores or independence tests. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the countings of (var | conditioning_ids) in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the counting vectors of (conditioning_ids,vars) [in this order] and conditioning_ids respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var,
std::vector< Idx > &&  conditioning_ids 
)
inherited

add a new target variable plus some conditioning vars

Parameters
varrepresents the index of the target variable in the filtered rows produced by the database cell filters
conditioning_idsthe indices of the variables of the conditioning set in the filtered rows
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores or independence tests. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the countings of (var | conditioning_ids) in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the counting vectors of (conditioning_ids,vars) [in this order] and conditioning_ids respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var1,
Idx  var2,
const std::vector< Idx > &  conditioning_ids 
)
inherited

add a target conditioned by other variables to be counted

Parameters
var1represents the index of the target variable in the filtered rows produced by the database cell filters
var2represents the index of the last conditioning variable in the filtered rows produced by the database cell filters
conditioning_idsthe indices of the variables of the conditioning set in the filtered rows (minus var2, which is subsequently apended to it).
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the counts in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the countings of (conditioning_ids, var2, var1) [in this order] and (conditioning_ids, var2) [in this order] respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( Idx  var1,
Idx  var2,
std::vector< Idx > &&  conditioning_ids 
)
inherited

add a target conditioned by other variables to be counted

Parameters
var1represents the index of the target variable in the filtered rows produced by the database cell filters
var2represents the index of the last conditioning variable in the filtered rows produced by the database cell filters
conditioning_idsthe indices of the variables of the conditioning set in the filtered rows (minus var2, which is subsequently apended to it).
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the counts in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the countings of (conditioning_ids, var2, var1) [in this order] and (conditioning_ids, var2) [in this order] respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( const std::pair< Idx, Idx > &  vars,
const std::vector< Idx > &  conditioning_ids 
)
inherited

add a target conditioned by other variables to be counted

Parameters
varsrepresents 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_idsthe indices of the variables of the conditioning set in the filtered rows (minus vars.second which is appended to it)
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the counts in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the observed countings of (conditioning_ids, vars.second, vars.first) [in this order] and (conditioning_ids, vars.second) [in this order] respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Idx gum::learning::Counter< IdSetAlloc, CountAlloc >::addNodeSet ( const std::pair< Idx, Idx > &  vars,
std::vector< Idx > &&  conditioning_ids 
)
inherited

add a target conditioned by other variables to be counted

Parameters
varsrepresents 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_idsthe indices of the variables of the conditioning set in the filtered rows (minus vars.second which is appended to it)
Returns
the index of the produced counting vector: the user should use class Counter to compute in one pass several scores. These and their corresponding countings in the database are stored into a vector and the value returned by method addNodeSet is the index of the counts in this vector. The user shall pass this index as argument to methods _getAllCounts and _getConditioningCounts to get the observed countings of (conditioning_ids, vars.second, vars.first) [in this order] and (conditioning_ids, vars.second) [in this order] respectively.
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::clear ( )

clears all the data structures from memory

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::clearCache ( )

clears the current cache (clear nodesets as well)

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< Size >& gum::learning::Counter< IdSetAlloc, CountAlloc >::modalities ( ) const
noexceptinherited

returns the modalities of the variables

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const Size gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::N ( )

return the size of the database

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
double gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::score ( Idx  nodeset_index)

returns the score corresponding to a given nodeset

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::Counter< IdSetAlloc, CountAlloc >::setMaxNbThreads ( Size  nb)
noexceptinherited

sets the maximum number of threads used to perform countings

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::setRange ( Size  min_range,
Size  max_range 
)

sets the range of records taken into account by the counter

Parameters
min_rangehe number of the first record to be taken into account during learning
max_rangethe number of the record after the last one taken into account
template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
void gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::useCache ( bool  on_off)
noexcept

turn on/off the use of a cache of the previously computed score

Member Data Documentation

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const double gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::_1log2 {M_LOG2E}
protected

1 / log(2)

Definition at line 105 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Cache4PartEntropy gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__cache
private

a cache for the previously computed scores

Definition at line 150 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
std::vector< double > gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__cached_score
private

the vector of scores for the current nodesets

Definition at line 159 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< Idx, IdSetAlloc > gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__empty_conditioning_set
private

an empty conditioning set

Definition at line 162 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
std::vector< bool > gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__is_cached_score
private

indicates whether the ith nodeset's score is in the cache or not

Definition at line 156 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
Size gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__N = 0
private

Size of the database.

Definition at line 147 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
bool gum::learning::PartialEntropy< IdSetAlloc, CountAlloc >::__use_cache {true}
private

a Boolean indicating whether we wish to use the cache

Definition at line 153 of file partialEntropy.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx >* > gum::learning::Counter< IdSetAlloc, CountAlloc >::_conditioning_nodesets
protectedinherited

the conditioning id sets to count and their indices in the record counter

Definition at line 361 of file counter.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
bool gum::learning::Counter< IdSetAlloc, CountAlloc >::_counts_computed {false}
protectedinherited

indicates whether we have already computed the countings of the nodesets

Definition at line 349 of file counter.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
const std::vector< Size >& gum::learning::Counter< IdSetAlloc, CountAlloc >::_modalities
protectedinherited

the modalities of the variables

Definition at line 345 of file counter.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
RecordCounter< IdSetAlloc, CountAlloc > gum::learning::Counter< IdSetAlloc, CountAlloc >::_record_counter
protectedinherited

the recordCounter that will parse the database

Definition at line 352 of file counter.h.

template<typename IdSetAlloc = std::allocator< Idx >, typename CountAlloc = std::allocator< double >>
std::vector< std::pair< std::vector< Idx, IdSetAlloc >, Idx >* > gum::learning::Counter< IdSetAlloc, CountAlloc >::_target_nodesets
protectedinherited

the target id sets to count and their indices in the record counter

Definition at line 356 of file counter.h.


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