aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > Class Template Referenceabstract

Base class for DBRowGenerator classes that use a BN for computing their outputs. More...

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

+ Inheritance diagram for gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >:
+ Collaboration diagram for gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >:

Public Member Functions

Constructors / Destructors
 DBRowGeneratorWithBN (const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types, const BayesNet< GUM_SCALAR > &bn, const DBRowGeneratorGoal goal, 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...
 
 DBRowGeneratorWithBN (const DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &from)
 copy constructor More...
 
 DBRowGeneratorWithBN (const DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 DBRowGeneratorWithBN (DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &&from)
 move constructor More...
 
 DBRowGeneratorWithBN (DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &&from, const allocator_type &alloc)
 move constructor with a given allocator More...
 
 ~DBRowGeneratorWithBN ()
 destructor More...
 
Accessors / Modifiers
virtual void setBayesNet (const BayesNet< GUM_SCALAR > &new_bn)
 assign a new Bayes net to the generator More...
 
const BayesNet< GUM_SCALAR > & getBayesNet () const
 returns the Bayes net used by the generator More...
 
allocator_type getAllocator () const
 returns the allocator used More...
 
Constructors / Destructors
virtual DBRowGenerator< ALLOC > * clone () const =0
 virtual copy constructor More...
 
virtual DBRowGenerator< ALLOC > * clone (const allocator_type &alloc) const =0
 virtual copy constructor with a given allocator More...
 
Accessors / Modifiers
bool hasRows ()
 returns true if there are still rows that can be output by the DBRowGenerator More...
 
bool setInputRow (const DBRow< DBTranslatedValue, ALLOC > &row)
 sets the input row from which the generator will create its output rows More...
 
virtual const DBRow< DBTranslatedValue, ALLOC > & generate ()=0
 generate new rows from the input row More...
 
void decreaseRemainingRows ()
 decrease the number of remaining output rows More...
 
virtual void reset ()
 resets the generator. There are therefore no more ouput row to generate More...
 
virtual void setColumnsOfInterest (const std::vector< std::size_t, ALLOC< std::size_t > > &cols_of_interest)
 sets the columns of interest: the output DBRow needs only contain correct values fot these columns More...
 
virtual void setColumnsOfInterest (std::vector< std::size_t, ALLOC< std::size_t > > &&cols_of_interest)
 sets the columns of interest: the output DBRow needs only contain correct values fot these columns More...
 
const std::vector< std::size_t, ALLOC< std::size_t > > & columnsOfInterest () const
 returns the current set of columns of interest More...
 
DBRowGeneratorGoal goal () const
 returns the goal of the DBRowGenerator More...
 

Public Types

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

Protected Attributes

const BayesNet< GUM_SCALAR > * bn_
 the Bayesian network used to fill the unobserved values More...
 
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > nodeId2columns_
 the mapping betwen the BN's node ids and the database's columns More...
 
std::size_t nb_remaining_output_rows_ {std::size_t(0)}
 the number of output rows still to retrieve through the generate method More...
 
std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > column_types_
 the types of the columns in the DatabaseTable More...
 
std::vector< std::size_t, ALLOC< std::size_t > > columns_of_interest_
 the set of columns of interest More...
 
DBRowGeneratorGoal goal_ {DBRowGeneratorGoal::OTHER_THINGS_THAN_REMOVE_MISSING_VALUES}
 the goal of the DBRowGenerator (just remove missing values or not) More...
 

Protected Member Functions

DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > & operator= (const DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &from)
 copy operator More...
 
DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > & operator= (DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &&from)
 move operator More...
 
virtual std::size_t computeRows_ (const DBRow< DBTranslatedValue, ALLOC > &row)=0
 the method that computes the set of DBRow instances to output after method setInputRow has been called More...
 

Detailed Description

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
class gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >

Base class for DBRowGenerator classes that use a BN for computing their outputs.

This class is a DBRowGenerator that fills the unobserved values of the nodes of interest as the WithBN algorithm does, i.e., by returning all the possible completed rows with a weight corresponding to the probability of the completion. The standard usage of a DBRowGenerator is the following:

// create a DatabaseTable and fill it
for ( int i = 0; i < 10; ++i )
// fill the database
// keep in a vector the types of the columns in the database
const std::vector<gum::learning::DBTranslatedValueType>
// create the generator
gum::learning::DBRowGeneratorWithBN<> generator ( col_types );
// parse the database and produce output rows
for ( auto dbrow : database ) {
generator.setInputRow ( dbrow );
while ( generator.hasRows() ) {
const auto& output_dbrow = generator.generate ();
// do something with the output dbrow
}
}

Definition at line 81 of file DBRowGeneratorWithBN.h.

Member Typedef Documentation

◆ allocator_type

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
using gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::allocator_type = ALLOC< DBTranslatedValue >

type for the allocators passed in arguments of methods

Definition at line 84 of file DBRowGeneratorWithBN.h.

Constructor & Destructor Documentation

◆ DBRowGeneratorWithBN() [1/5]

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::DBRowGeneratorWithBN ( const std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > >  column_types,
const BayesNet< GUM_SCALAR > &  bn,
const DBRowGeneratorGoal  goal,
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

◆ DBRowGeneratorWithBN() [2/5]

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::DBRowGeneratorWithBN ( const DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &  from)

copy constructor

◆ DBRowGeneratorWithBN() [3/5]

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

copy constructor with a given allocator

◆ DBRowGeneratorWithBN() [4/5]

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::DBRowGeneratorWithBN ( DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &&  from)

move constructor

◆ DBRowGeneratorWithBN() [5/5]

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

move constructor with a given allocator

◆ ~DBRowGeneratorWithBN()

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::~DBRowGeneratorWithBN ( )

destructor

Member Function Documentation

◆ clone() [1/2]

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

◆ clone() [2/2]

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

◆ columnsOfInterest()

template<template< typename > class ALLOC = std::allocator>
const std::vector< std::size_t, ALLOC< std::size_t > >& gum::learning::DBRowGenerator< ALLOC >::columnsOfInterest ( ) const
inherited

returns the current set of columns of interest

◆ computeRows_()

template<template< typename > class ALLOC = std::allocator>
virtual std::size_t gum::learning::DBRowGenerator< ALLOC >::computeRows_ ( const DBRow< DBTranslatedValue, ALLOC > &  row)
protectedpure virtualinherited

the method that computes the set of DBRow instances to output after method setInputRow has been called

Implemented in gum::learning::DBRowGeneratorEM< GUM_SCALAR, ALLOC >, gum::learning::DBRowGenerator4CompleteRows< ALLOC >, and gum::learning::DBRowGeneratorIdentity< ALLOC >.

◆ decreaseRemainingRows()

template<template< typename > class ALLOC = std::allocator>
void gum::learning::DBRowGenerator< ALLOC >::decreaseRemainingRows ( )
inherited

decrease the number of remaining output rows

When method setInputRow is performed, the DBRowGenerator knows how many output rows it will be able to generate. Each time method decreaseRemainingRows is called, we decrement this number. When the number becomes equal to 0, then there remains no new output row to generate.

◆ generate()

template<template< typename > class ALLOC = std::allocator>
virtual const DBRow< DBTranslatedValue, ALLOC >& gum::learning::DBRowGenerator< ALLOC >::generate ( )
pure virtualinherited

◆ getAllocator()

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
allocator_type gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::getAllocator ( ) const

returns the allocator used

◆ getBayesNet()

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
const BayesNet< GUM_SCALAR >& gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::getBayesNet ( ) const

returns the Bayes net used by the generator

◆ goal()

template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorGoal gum::learning::DBRowGenerator< ALLOC >::goal ( ) const
inherited

returns the goal of the DBRowGenerator

◆ hasRows()

template<template< typename > class ALLOC = std::allocator>
bool gum::learning::DBRowGenerator< ALLOC >::hasRows ( )
inherited

returns true if there are still rows that can be output by the DBRowGenerator

◆ operator=() [1/2]

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >& gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::operator= ( const DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &  from)
protected

copy operator

◆ operator=() [2/2]

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >& gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::operator= ( DBRowGeneratorWithBN< GUM_SCALAR, ALLOC > &&  from)
protected

move operator

◆ reset()

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBRowGenerator< ALLOC >::reset ( )
virtualinherited

resets the generator. There are therefore no more ouput row to generate

◆ setBayesNet()

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::setBayesNet ( const BayesNet< GUM_SCALAR > &  new_bn)
virtual

assign a new Bayes net to the generator

Reimplemented in gum::learning::DBRowGeneratorEM< GUM_SCALAR, ALLOC >.

◆ setColumnsOfInterest() [1/2]

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBRowGenerator< ALLOC >::setColumnsOfInterest ( const std::vector< std::size_t, ALLOC< std::size_t > > &  cols_of_interest)
virtualinherited

sets the columns of interest: the output DBRow needs only contain correct values fot these columns

This method is useful, e.g., for EM-like algorithms that need to know which unobserved variables/values need be filled. In this case, the DBRowGenerator still outputs DBRows with the same columns as the DatabaseTable, but only the columns of these DBRows corresponding to those passed in argument to Method setColumnsOfInterest are meaningful. For instance, if a DatabaseTable contains 10 columns and Method setColumnsOfInterest() is applied with vector<> { 0, 3, 4 }, then the DBRowGenerator will output DBRows with 10 columns, in which only columns 0, 3 and 4 are guaranteed to have correct values (columns are always indexed, starting from 0).

◆ setColumnsOfInterest() [2/2]

template<template< typename > class ALLOC = std::allocator>
virtual void gum::learning::DBRowGenerator< ALLOC >::setColumnsOfInterest ( std::vector< std::size_t, ALLOC< std::size_t > > &&  cols_of_interest)
virtualinherited

sets the columns of interest: the output DBRow needs only contain correct values fot these columns

This method is useful, e.g., for EM-like algorithms that need to know which unobserved variables/values need be filled. In this case, the DBRowGenerator still outputs DBRows with the same columns as the DatabaseTable, but only the columns of these DBRows corresponding to those passed in argument to Method setColumnsOfInterest are meaningful. For instance, if a DatabaseTable contains 10 columns and Method setColumnsOfInterest() is applied with vector<> { 0, 3, 4 }, then the DBRowGenerator will output DBRows with 10 columns, in which only columns 0, 3 and 4 are guaranteed to have correct values (columns are always indexed, starting from 0).

◆ setInputRow()

template<template< typename > class ALLOC = std::allocator>
bool gum::learning::DBRowGenerator< ALLOC >::setInputRow ( const DBRow< DBTranslatedValue, ALLOC > &  row)
inherited

sets the input row from which the generator will create its output rows

Returns
a Boolean indicating whether, from this input DBRow, the DBRowGenerator is capable of outputing at least one row or not

Member Data Documentation

◆ bn_

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
const BayesNet< GUM_SCALAR >* gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::bn_
protected

the Bayesian network used to fill the unobserved values

Definition at line 141 of file DBRowGeneratorWithBN.h.

◆ column_types_

template<template< typename > class ALLOC = std::allocator>
std::vector< DBTranslatedValueType, ALLOC< DBTranslatedValueType > > gum::learning::DBRowGenerator< ALLOC >::column_types_
protectedinherited

the types of the columns in the DatabaseTable

This is useful to determine whether we need to use the .discr_val field or the .cont_val field in DBTranslatedValue instances.

Definition at line 361 of file DBRowGenerator.h.

◆ columns_of_interest_

template<template< typename > class ALLOC = std::allocator>
std::vector< std::size_t, ALLOC< std::size_t > > gum::learning::DBRowGenerator< ALLOC >::columns_of_interest_
protectedinherited

the set of columns of interest

Definition at line 364 of file DBRowGenerator.h.

◆ goal_

template<template< typename > class ALLOC = std::allocator>
DBRowGeneratorGoal gum::learning::DBRowGenerator< ALLOC >::goal_ {DBRowGeneratorGoal::OTHER_THINGS_THAN_REMOVE_MISSING_VALUES}
protectedinherited

the goal of the DBRowGenerator (just remove missing values or not)

Definition at line 367 of file DBRowGenerator.h.

◆ nb_remaining_output_rows_

template<template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::DBRowGenerator< ALLOC >::nb_remaining_output_rows_ {std::size_t(0)}
protectedinherited

the number of output rows still to retrieve through the generate method

Definition at line 356 of file DBRowGenerator.h.

◆ nodeId2columns_

template<typename GUM_SCALAR = double, template< typename > class ALLOC = std::allocator>
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > gum::learning::DBRowGeneratorWithBN< GUM_SCALAR, ALLOC >::nodeId2columns_
protected

the mapping betwen the BN's node ids and the database's columns

Definition at line 144 of file DBRowGeneratorWithBN.h.


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