aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::learning::PseudoCount< ALLOC > Class Template Reference

The class for giving access to pseudo count : count in the database + prior. More...

#include <pseudoCount.h>

Public Member Functions

Constructors / Destructors
 PseudoCount (const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_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...
 
 PseudoCount (const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_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...
 
virtual ~PseudoCount ()
 destructor More...
 
 PseudoCount (const PseudoCount< ALLOC > &from)
 copy constructor More...
 
 PseudoCount (const PseudoCount< ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 PseudoCount (PseudoCount< ALLOC > &&from)
 move constructor More...
 
 PseudoCount (PseudoCount< ALLOC > &&from, const allocator_type &alloc)
 move constructor with a given allocator More...
 
PseudoCount< ALLOC > & operator= (const PseudoCount< ALLOC > &from)
 copy operator More...
 
PseudoCount< ALLOC > & operator= (PseudoCount< ALLOC > &&from)
 move operator 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 independence test 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...
 
std::vector< double, ALLOC< double > > get (const std::vector< NodeId, ALLOC< NodeId > > &ids)
 returns the pseudo-count of a pair of nodes given some other nodes More...
 
virtual void clear ()
 clears all the data structures from memory, including the 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 pseudo-count More...
 
allocator_type getAllocator () const
 returns the allocator used by the pseudo-count More...
 

Public Types

using allocator_type = ALLOC< NodeId >
 type for the allocators passed in arguments of methods More...
 

Protected Attributes

Apriori< ALLOC > * apriori_ {nullptr}
 the expert knowledge a priori we add to the contingency tables More...
 
RecordCounter< ALLOC > counter_
 the record counter used for the countings over discrete variables More...
 
const std::vector< NodeId, ALLOC< NodeId > > empty_ids_
 an empty vector More...
 

Detailed Description

template<template< typename > class ALLOC = std::allocator>
class gum::learning::PseudoCount< ALLOC >

The class for giving access to pseudo count : count in the database + prior.

Definition at line 52 of file pseudoCount.h.

Member Typedef Documentation

◆ allocator_type

template<template< typename > class ALLOC = std::allocator>
using gum::learning::PseudoCount< ALLOC >::allocator_type = ALLOC< NodeId >

type for the allocators passed in arguments of methods

Definition at line 55 of file pseudoCount.h.

Constructor & Destructor Documentation

◆ PseudoCount() [1/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( const DBRowGeneratorParser< ALLOC > &  parser,
const Apriori< ALLOC > &  external_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 = BijectionNodeId, std::size_t, ALLOC< std::size_t > >(),
const allocator_type alloc = allocator_type() 
)

default constructor

Parameters
parserthe parser used to parse the database
external_aprioriAn apriori that we add to the computation of the pseudo-count (this should come from expert knowledge): this consists in adding numbers to countings in the contingency tables
rangesa 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.
nodeId2Columnsa 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.
allocthe allocator used to allocate the structures within the PseudoCount.
Warning
If nodeId2columns is not empty, then only the pseudo-counts over the ids belonging to this bijection can be computed: applying method pseudo-count() over other ids will raise exception NotFound.

◆ PseudoCount() [2/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( const DBRowGeneratorParser< ALLOC > &  parser,
const Apriori< ALLOC > &  external_apriori,
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > &  nodeId2columns = BijectionNodeId, std::size_t, ALLOC< std::size_t > >(),
const allocator_type alloc = allocator_type() 
)

default constructor

Parameters
parserthe parser used to parse the database
external_aprioriAn apriori that we add to the computation of the pseudo-count (this should come from expert knowledge): this consists in adding numbers to countings in the contingency tables
nodeId2Columnsa 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.
allocthe allocator used to allocate the structures within the PseudoCount.
Warning
If nodeId2columns is not empty, then only the pseudo-counts over the ids belonging to this bijection can be computed: applying method pseudo-count() over other ids will raise exception NotFound.

◆ ~PseudoCount()

template<template< typename > class ALLOC = std::allocator>
virtual gum::learning::PseudoCount< ALLOC >::~PseudoCount ( )
virtual

destructor

◆ PseudoCount() [3/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( const PseudoCount< ALLOC > &  from)

copy constructor

◆ PseudoCount() [4/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( const PseudoCount< ALLOC > &  from,
const allocator_type alloc 
)

copy constructor with a given allocator

◆ PseudoCount() [5/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( PseudoCount< ALLOC > &&  from)

move constructor

◆ PseudoCount() [6/6]

template<template< typename > class ALLOC = std::allocator>
gum::learning::PseudoCount< ALLOC >::PseudoCount ( PseudoCount< ALLOC > &&  from,
const allocator_type alloc 
)

move constructor with a given allocator

Member Function Documentation

◆ clear()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::PseudoCount< ALLOC >::clear ( )
virtual

clears all the data structures from memory, including the cache

◆ clearRanges()

template<template< typename > class ALLOC = std::allocator>
void gum::learning::PseudoCount< ALLOC >::clearRanges ( )

reset the ranges to the one range corresponding to the whole database

◆ database()

template<template< typename > class ALLOC = std::allocator>
const DatabaseTable< ALLOC >& gum::learning::PseudoCount< ALLOC >::database ( ) const

return the database used by the pseudo-count

◆ get()

template<template< typename > class ALLOC = std::allocator>
std::vector< double, ALLOC< double > > gum::learning::PseudoCount< ALLOC >::get ( const std::vector< NodeId, ALLOC< NodeId > > &  ids)

returns the pseudo-count of a pair of nodes given some other nodes

Parameters
var1the first variable on the left side of the conditioning bar
var2the second variable on the left side of the conditioning bar
rhs_idsthe set of variables on the right side of the conditioning bar

◆ getAllocator()

template<template< typename > class ALLOC = std::allocator>
allocator_type gum::learning::PseudoCount< ALLOC >::getAllocator ( ) const

returns the allocator used by the pseudo-count

◆ minNbRowsPerThread()

template<template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::PseudoCount< ALLOC >::minNbRowsPerThread ( ) const
virtual

returns the minimum of rows that each thread should process

◆ nbThreads()

template<template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::PseudoCount< ALLOC >::nbThreads ( ) const
virtual

returns the number of threads used to parse the database

◆ nodeId2Columns()

template<template< typename > class ALLOC = std::allocator>
const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >& gum::learning::PseudoCount< ALLOC >::nodeId2Columns ( ) const

return the mapping between the columns of the database and the node ids

Warning
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.

◆ operator=() [1/2]

template<template< typename > class ALLOC = std::allocator>
PseudoCount< ALLOC >& gum::learning::PseudoCount< ALLOC >::operator= ( const PseudoCount< ALLOC > &  from)

copy operator

◆ operator=() [2/2]

template<template< typename > class ALLOC = std::allocator>
PseudoCount< ALLOC >& gum::learning::PseudoCount< ALLOC >::operator= ( PseudoCount< ALLOC > &&  from)

move operator

◆ ranges()

template<template< typename > class ALLOC = std::allocator>
const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > >& gum::learning::PseudoCount< ALLOC >::ranges ( ) const

returns the current ranges

◆ setMaxNbThreads()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::PseudoCount< ALLOC >::setMaxNbThreads ( std::size_t  nb) const
virtual

changes the max number of threads used to parse the database

◆ setMinNbRowsPerThread()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::PseudoCount< ALLOC >::setMinNbRowsPerThread ( const std::size_t  nb) const
virtual

changes the number min of rows a thread should process in a multithreading context

When computing pseudo-count, 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.

◆ setRanges()

template<template< typename > class ALLOC = std::allocator>
template<template< typename > class XALLOC>
void gum::learning::PseudoCount< ALLOC >::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 independence test

Parameters
rangesa 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.

Member Data Documentation

◆ apriori_

template<template< typename > class ALLOC = std::allocator>
Apriori< ALLOC >* gum::learning::PseudoCount< ALLOC >::apriori_ {nullptr}
protected

the expert knowledge a priori we add to the contingency tables

Definition at line 213 of file pseudoCount.h.

◆ counter_

template<template< typename > class ALLOC = std::allocator>
RecordCounter< ALLOC > gum::learning::PseudoCount< ALLOC >::counter_
protected

the record counter used for the countings over discrete variables

Definition at line 216 of file pseudoCount.h.

◆ empty_ids_

template<template< typename > class ALLOC = std::allocator>
const std::vector< NodeId, ALLOC< NodeId > > gum::learning::PseudoCount< ALLOC >::empty_ids_
protected

an empty vector

Definition at line 219 of file pseudoCount.h.


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