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

the internal apriori for the K2 score = Laplace AprioriK2 is a BD score with a Laplace apriori (i.e., a smoothing of 1). More...

#include <agrum/tools/database/aprioriK2.h>

+ Inheritance diagram for gum::learning::AprioriK2< ALLOC >:
+ Collaboration diagram for gum::learning::AprioriK2< ALLOC >:

Public Member Functions

Constructors / Destructors
 AprioriK2 (const DatabaseTable< ALLOC > &database, 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...
 
 AprioriK2 (const AprioriK2< ALLOC > &from)
 copy constructor More...
 
 AprioriK2 (const AprioriK2< ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 AprioriK2 (AprioriK2< ALLOC > &&from)
 move constructor More...
 
 AprioriK2 (AprioriK2< ALLOC > &&from, const allocator_type &alloc)
 move constructor with a given allocator More...
 
virtual AprioriK2< ALLOC > * clone () const
 virtual copy constructor More...
 
virtual AprioriK2< ALLOC > * clone (const allocator_type &alloc) const
 virtual copy constructor with a given allocator More...
 
virtual ~AprioriK2 ()
 destructor More...
 
Operators
AprioriK2< ALLOC > & operator= (const AprioriK2< ALLOC > &from)
 copy operator More...
 
AprioriK2< ALLOC > & operator= (AprioriK2< ALLOC > &&from)
 move operator More...
 
Accessors / Modifiers
virtual void setWeight (const double weight) final
 dummy set weight function: in K2, weights are always equal to 1 More...
 
Accessors / Modifiers
virtual bool isOfType (const std::string &type) final
 indicates whether an apriori is of a certain type More...
 
virtual const std::string & getType () const final
 returns the type of the apriori More...
 
virtual bool isInformative () const final
 indicates whether the apriori is potentially informative More...
 
virtual void addAllApriori (const IdCondSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts) final
 adds the apriori to a counting vector corresponding to the idset More...
 
virtual void addConditioningApriori (const IdCondSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts) final
 adds the apriori to a counting vectordefined over the right hand side of the idset More...
 
Accessors / Modifiers
double weight () const
 returns the weight assigned to the apriori More...
 
allocator_type getAllocator () const
 returns the allocator used by the internal apriori More...
 

Public Types

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

Protected Attributes

double weight_ {1.0}
 the weight of the apriori More...
 
const DatabaseTable< ALLOC > * database_
 a reference to the database in order to have access to its variables More...
 
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > nodeId2columns_
 a mapping from the NodeIds of the variables to the indices of the columns in the database More...
 

Detailed Description

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

the internal apriori for the K2 score = Laplace Apriori

K2 is a BD score with a Laplace apriori (i.e., a smoothing of 1).

It is important to note that, to be meaningful a structure + parameter learning requires that the same aprioris are taken into account during structure learning and parameter learning.

Definition at line 51 of file aprioriK2.h.

Member Typedef Documentation

◆ allocator_type

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

type for the allocators passed in arguments of methods

Definition at line 57 of file aprioriK2.h.

◆ type

template<template< typename > class ALLOC = std::allocator>
using gum::learning::AprioriK2< ALLOC >::type = AprioriSmoothingType

the type of the a priori

Definition at line 54 of file aprioriK2.h.

Constructor & Destructor Documentation

◆ AprioriK2() [1/5]

template<template< typename > class ALLOC = std::allocator>
gum::learning::AprioriK2< ALLOC >::AprioriK2 ( const DatabaseTable< ALLOC > &  database,
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
databasethe database from which learning is performed. This is useful to get access to the random variables
nodeId2Columnsa mapping from the ids of the nodes in the graphical model to the corresponding column in the DatabaseTable. 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 RecordCounter.

◆ AprioriK2() [2/5]

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

copy constructor

◆ AprioriK2() [3/5]

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

copy constructor with a given allocator

◆ AprioriK2() [4/5]

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

move constructor

◆ AprioriK2() [5/5]

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

move constructor with a given allocator

◆ ~AprioriK2()

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

destructor

Member Function Documentation

◆ addAllApriori()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::AprioriSmoothing< ALLOC >::addAllApriori ( const IdCondSet< ALLOC > &  idset,
std::vector< double, ALLOC< double > > &  counts 
)
finalvirtualinherited

adds the apriori to a counting vector corresponding to the idset

adds the apriori to an already created counting vector defined over the union of the variables on both the left and right hand side of the conditioning bar of the idset.

Warning
the method assumes that the size of the vector is exactly the domain size of the joint variables set.

Implements gum::learning::Apriori< ALLOC >.

◆ addConditioningApriori()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::AprioriSmoothing< ALLOC >::addConditioningApriori ( const IdCondSet< ALLOC > &  idset,
std::vector< double, ALLOC< double > > &  counts 
)
finalvirtualinherited

adds the apriori to a counting vectordefined over the right hand side of the idset

Warning
the method assumes that the size of the vector is exactly the domain size of the joint RHS variables of the idset.

Implements gum::learning::Apriori< ALLOC >.

◆ clone() [1/2]

template<template< typename > class ALLOC = std::allocator>
virtual AprioriK2< ALLOC >* gum::learning::AprioriK2< ALLOC >::clone ( ) const
virtual

virtual copy constructor

Reimplemented from gum::learning::AprioriSmoothing< ALLOC >.

◆ clone() [2/2]

template<template< typename > class ALLOC = std::allocator>
virtual AprioriK2< ALLOC >* gum::learning::AprioriK2< ALLOC >::clone ( const allocator_type alloc) const
virtual

virtual copy constructor with a given allocator

Reimplemented from gum::learning::AprioriSmoothing< ALLOC >.

◆ getAllocator()

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

returns the allocator used by the internal apriori

◆ getType()

template<template< typename > class ALLOC = std::allocator>
virtual const std::string& gum::learning::AprioriSmoothing< ALLOC >::getType ( ) const
finalvirtualinherited

returns the type of the apriori

Implements gum::learning::Apriori< ALLOC >.

◆ isInformative()

template<template< typename > class ALLOC = std::allocator>
virtual bool gum::learning::AprioriSmoothing< ALLOC >::isInformative ( ) const
finalvirtualinherited

indicates whether the apriori is potentially informative

Basically, only the NoApriori is uninformative. However, it may happen that, under some circonstances, an apriori, which is usually not equal to the NoApriori, becomes equal to it (e.g., when the weight is equal to zero). In this case, if the apriori can detect this case, it shall inform the classes that use it that it is temporarily uninformative. These classes will then be able to speed-up their code by avoiding to take into account the apriori in their computations.

Implements gum::learning::Apriori< ALLOC >.

◆ isOfType()

template<template< typename > class ALLOC = std::allocator>
virtual bool gum::learning::AprioriSmoothing< ALLOC >::isOfType ( const std::string &  type)
finalvirtualinherited

indicates whether an apriori is of a certain type

Implements gum::learning::Apriori< ALLOC >.

◆ operator=() [1/2]

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

copy operator

◆ operator=() [2/2]

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

move operator

◆ setWeight()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::AprioriK2< ALLOC >::setWeight ( const double  weight)
finalvirtual

dummy set weight function: in K2, weights are always equal to 1

Reimplemented from gum::learning::Apriori< ALLOC >.

◆ weight()

template<template< typename > class ALLOC = std::allocator>
double gum::learning::Apriori< ALLOC >::weight ( ) const
inherited

returns the weight assigned to the apriori

Member Data Documentation

◆ database_

template<template< typename > class ALLOC = std::allocator>
const DatabaseTable< ALLOC >* gum::learning::Apriori< ALLOC >::database_
protectedinherited

a reference to the database in order to have access to its variables

Definition at line 144 of file apriori.h.

◆ nodeId2columns_

template<template< typename > class ALLOC = std::allocator>
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > gum::learning::Apriori< ALLOC >::nodeId2columns_
protectedinherited

a mapping from the NodeIds of the variables to the indices of the columns in the database

Definition at line 148 of file apriori.h.

◆ weight_

template<template< typename > class ALLOC = std::allocator>
double gum::learning::Apriori< ALLOC >::weight_ {1.0}
protectedinherited

the weight of the apriori

Definition at line 141 of file apriori.h.


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