aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::learning::KNML Class Reference

the class for computing the NML penalty used by MIIC More...

#include <kNML.h>

Inheritance diagram for gum::learning::KNML:
Collaboration diagram for gum::learning::KNML:

Public Member Functions

Constructors / Destructors
 KNML (const DBRowGeneratorParser &parser, const Prior &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
 KNML (const DBRowGeneratorParser &parser, const Prior &prior, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
 default constructor
 KNML (const KNML &from)
 copy constructor
 KNML (KNML &&from)
 move constructor
virtual KNMLclone () const
 virtual copy constructor
 ~KNML () override
 destructor
Operators
KNMLoperator= (const KNML &from)
 copy operator
KNMLoperator= (KNML &&from)
 move operator
Accessors / Modifiers
double score (NodeId var1, NodeId var2)
 returns the kNML penalty for a pair of nodes
double score (NodeId var1, NodeId var2, const std::vector< NodeId > &rhs_ids)
 returns the kNML penalty for a pair of nodes given conditioning nodes
void clear () override
 clears all the data structures from memory, including the C_n^r cache
void clearCache () override
 clears the current C_n^r cache
void useCache (const bool on_off) override
 turn on/off the use of the C_n^r cache
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
const Bijection< NodeId, std::size_t > & nodeId2Columns () const
 return the mapping between the columns of the database and the node ids
const DatabaseTabledatabase () const
 return the database used by the score

Protected Attributes

const double one_log2_ {M_LOG2E}
 1 / log(2)
Priorprior_ {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< NodeIdempty_ids_
 an empty vector

Detailed Description

the class for computing the NML penalty used by MIIC

Definition at line 67 of file kNML.h.

Constructor & Destructor Documentation

◆ KNML() [1/4]

gum::learning::KNML::KNML ( const DBRowGeneratorParser & parser,
const Prior & prior,
const std::vector< std::pair< std::size_t, std::size_t > > & ranges,
const Bijection< NodeId, std::size_t > & nodeId2columns = BijectionNodeId, std::size_t >() )

default constructor

Parameters
parserthe parser used to parse the database
priorAn 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
rangesa 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.
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.
Warning
If nodeId2columns is not empty, then only the scores over the ids belonging to this bijection can be computed: applying method score() over other ids will raise exception NotFound.

References gum::learning::CachedContingencyCounter::ranges().

Referenced by KNML(), KNML(), clone(), operator=(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ KNML() [2/4]

gum::learning::KNML::KNML ( const DBRowGeneratorParser & parser,
const Prior & prior,
const Bijection< NodeId, std::size_t > & nodeId2columns = BijectionNodeId, std::size_t >() )

default constructor

Parameters
parserthe parser used to parse the database
priorAn 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
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.
Warning
If nodeId2columns is not empty, then only the scores over the ids belonging to this bijection can be computed: applying method score() over other ids will raise exception NotFound.

◆ KNML() [3/4]

gum::learning::KNML::KNML ( const KNML & from)

copy constructor

References KNML().

Here is the call graph for this function:

◆ KNML() [4/4]

gum::learning::KNML::KNML ( KNML && from)

move constructor

References KNML().

Here is the call graph for this function:

◆ ~KNML()

gum::learning::KNML::~KNML ( )
override

destructor

Member Function Documentation

◆ clear()

void gum::learning::KNML::clear ( )
overridevirtual

clears all the data structures from memory, including the C_n^r cache

Reimplemented from gum::learning::CachedContingencyCounter.

◆ clearCache()

void gum::learning::KNML::clearCache ( )
overridevirtual

clears the current C_n^r cache

Reimplemented from gum::learning::CachedContingencyCounter.

◆ clearRanges()

void gum::learning::CachedContingencyCounter::clearRanges ( )
inherited

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

◆ clone()

virtual KNML * gum::learning::KNML::clone ( ) const
nodiscardvirtual

virtual copy constructor

References KNML().

Here is the call graph for this function:

◆ database()

const DatabaseTable & gum::learning::CachedContingencyCounter::database ( ) const
inherited

return the database used by the score

◆ getNumberOfThreads()

Size gum::learning::CachedContingencyCounter::getNumberOfThreads ( ) const
overridevirtualinherited

returns the current max number of threads of the scheduler

Implements gum::IThreadNumberManager.

◆ isGumNumberOfThreadsOverriden()

bool gum::learning::CachedContingencyCounter::isGumNumberOfThreadsOverriden ( ) const
overridevirtualinherited

indicates whether the user set herself the number of threads

Implements gum::IThreadNumberManager.

◆ minNbRowsPerThread()

virtual std::size_t gum::learning::CachedContingencyCounter::minNbRowsPerThread ( ) const
virtualinherited

returns the minimum of rows that each thread should process

◆ nodeId2Columns()

const Bijection< NodeId, std::size_t > & gum::learning::CachedContingencyCounter::nodeId2Columns ( ) const
inherited

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]

KNML & gum::learning::KNML::operator= ( const KNML & from)

copy operator

References KNML().

Here is the call graph for this function:

◆ operator=() [2/2]

KNML & gum::learning::KNML::operator= ( KNML && from)

move operator

References KNML().

Here is the call graph for this function:

◆ ranges()

const std::vector< std::pair< std::size_t, std::size_t > > & gum::learning::CachedContingencyCounter::ranges ( ) const
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().

Here is the caller graph for this function:

◆ score() [1/2]

double gum::learning::KNML::score ( NodeId var1,
NodeId var2 )

returns the kNML penalty for a pair of nodes

◆ score() [2/2]

double gum::learning::KNML::score ( NodeId var1,
NodeId var2,
const std::vector< NodeId > & rhs_ids )

returns the kNML penalty for a pair of nodes given conditioning nodes

◆ setMinNbRowsPerThread()

virtual void gum::learning::CachedContingencyCounter::setMinNbRowsPerThread ( const std::size_t nb) const
virtualinherited

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

◆ setNumberOfThreads()

void gum::learning::CachedContingencyCounter::setNumberOfThreads ( Size nb)
overridevirtualinherited

sets the number max of threads that can be used

Implements gum::IThreadNumberManager.

◆ setRanges()

void gum::learning::CachedContingencyCounter::setRanges ( const std::vector< std::pair< std::size_t, std::size_t > > & new_ranges)
inherited

sets new ranges to perform the counts

◆ useCache()

void gum::learning::KNML::useCache ( const bool on_off)
overridevirtual

turn on/off the use of the C_n^r cache

Reimplemented from gum::learning::CachedContingencyCounter.

Member Data Documentation

◆ cache_

ScoringCache gum::learning::CachedContingencyCounter::cache_
protectedinherited

the scoring cache

Definition at line 171 of file cachedContingencyCounter.h.

◆ counter_

RecordCounter gum::learning::CachedContingencyCounter::counter_
protectedinherited

the record counter used for the counts over discrete variables

Definition at line 168 of file cachedContingencyCounter.h.

◆ empty_ids_

const std::vector< NodeId > gum::learning::CachedContingencyCounter::empty_ids_
protectedinherited

an empty vector

Definition at line 177 of file cachedContingencyCounter.h.

◆ one_log2_

const double gum::learning::CachedContingencyCounter::one_log2_ {M_LOG2E}
protectedinherited

1 / log(2)

Definition at line 162 of file cachedContingencyCounter.h.

162{M_LOG2E};
#define M_LOG2E
Definition math_utils.h:55

◆ prior_

Prior* gum::learning::CachedContingencyCounter::prior_ {nullptr}
protectedinherited

the expert knowledge prior added to the contingency tables

Definition at line 165 of file cachedContingencyCounter.h.

165{nullptr};

◆ use_cache_

bool gum::learning::CachedContingencyCounter::use_cache_ {true}
protectedinherited

a Boolean indicating whether we wish to use the cache

Definition at line 174 of file cachedContingencyCounter.h.

174{true};

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