aGrUM  0.13.2
gum::learning::IDatabaseTable< T_DATA, ALLOC > Class Template Referenceabstract

The common class for the tabular database tables. More...

#include <agrum/learning/IDatabaseTable.h>

+ Inheritance diagram for gum::learning::IDatabaseTable< T_DATA, ALLOC >:
+ Collaboration diagram for gum::learning::IDatabaseTable< T_DATA, ALLOC >:

Public Member Functions

Constructors / Destructors
template<template< typename > class VARALLOC, template< typename > class MISSALLOC>
 IDatabaseTable (const MissingValType< MISSALLOC > &missing_symbols, const std::vector< std::string, VARALLOC< std::string > > &var_names, const ALLOC< T_DATA > &alloc)
 default constructor More...
 
 IDatabaseTable (const IDatabaseTable< T_DATA, ALLOC > &from)
 copy constructor More...
 
 IDatabaseTable (const IDatabaseTable< T_DATA, ALLOC > &from, const allocator_type &alloc)
 copy constructor with a given allocator More...
 
 IDatabaseTable (IDatabaseTable< T_DATA, ALLOC > &&from)
 move constructor More...
 
 IDatabaseTable (IDatabaseTable< T_DATA, ALLOC > &&from, const allocator_type &alloc)
 move constructor with a given allocator More...
 
virtual IDatabaseTable< T_DATA, ALLOC > * clone () const =0
 virtual copy constructor More...
 
virtual IDatabaseTable< T_DATA, ALLOC > * clone (const allocator_type &alloc) const =0
 virtual copy constructor with a given allocator More...
 
virtual ~IDatabaseTable ()
 destructor More...
 
Iterators
iterator begin () const
 returns a new unsafe handler pointing to the beginning of the database More...
 
iterator_safe beginSafe () const
 returns a new safe handler pointing to the beginning of the database More...
 
const iteratorend () const noexcept
 returns a new unsafe handler pointing to the end of the database More...
 
const iterator_safeendSafe () const noexcept
 returns a new safe handler pointing to the end of the database More...
 
Accessors / Modifiers
const Matrix< T_DATA > & content () const noexcept
 returns the content of the database More...
 
iterator handler () const
 returns a new unsafe handler on the database More...
 
iterator_safe handlerSafe () const
 returns a new safe handler on the database More...
 
const DBVector< std::string > & variableNames () const noexcept
 returns the variable names for all the columns of the database More...
 
virtual void setVariableNames (const std::vector< std::string, ALLOC< std::string > > &names, const bool from_external_object=true)=0
 sets the names of the variables More...
 
template<template< typename > class OTHER_ALLOC>
void setVariableNames (const std::vector< std::string, OTHER_ALLOC< std::string > > &names, const bool from_external_object=true)
 sets the names of the variables More...
 
const std::string & variableName (const std::size_t k) const
 returns the name of the kth column of the database More...
 
std::size_t columnFromVariableName (const std::string &name) const
 returns the index of the column whose name is passed in argument More...
 
std::size_t nbVariables () const noexcept
 returns the number of variables (columns) of the database More...
 
std::size_t size () const noexcept
 returns the number of records (rows) in the database More...
 
virtual void ignoreColumn (const std::size_t k, const bool from_external_object=true)=0
 makes the database table ignore from now on the kth column More...
 
virtual const DBVector< std::size_t > ignoredColumns () const =0
 returns the set of columns of the original dataset that are ignored More...
 
virtual const DBVector< std::size_t > inputColumns () const =0
 returns the set of columns of the original dataset that are present in the IDatabaseTable More...
 
bool hasMissingValues () const
 indicates whether the database contains some missing values More...
 
bool hasMissingValues (const std::size_t k) const
 indicates whether the kth row contains some missing values More...
 
template<template< typename > class OTHER_ALLOC>
void insertRow (const std::vector< std::string, OTHER_ALLOC< std::string > > &new_row)
 insert a new row at the end of the database More...
 
virtual void insertRow (Row< T_DATA > &&new_row, const IsMissing contains_missing_data)
 insert a new DBRow at the end of the database More...
 
virtual void insertRow (const Row< T_DATA > &new_row, const IsMissing contains_missing_data)
 insert a new row at the end of the database More...
 
virtual void insertRows (Matrix< T_DATA > &&new_rows, const DBVector< IsMissing > &rows_have_missing_vals)
 insert a set of new DBRows at the end of the database More...
 
virtual void insertRows (const Matrix< T_DATA > &new_rows, const DBVector< IsMissing > &rows_have_missing_vals)
 insert a set of new DBRows at the end of the database More...
 
void eraseRow (std::size_t index)
 erase a given row specified by its index in the table More...
 
void eraseFirstRow ()
 erase the first row More...
 
void eraseLastRow ()
 erase the last row More...
 
void eraseFirstRows (const std::size_t k)
 erase the k first rows More...
 
void eraseLastRows (const std::size_t k)
 erase the k last rows More...
 
void eraseRows (std::size_t deb, std::size_t end)
 erase the rows from the debth to the endth (not included) More...
 
void eraseAllRows ()
 erase all the rows More...
 
virtual void clear ()
 erase the content of the database, including the names of the variables More...
 
ALLOC< T_DATA > getAllocator () const
 returns the allocator of the database More...
 
const DBVector< std::string > & missingSymbols () const
 returns the set of missing symbols More...
 

Public Types

enum  IsMissing : char { False, True }
 
template<typename TX_DATA >
using DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >
 the type for the vectors used in the IDatabaseTable More...
 
template<typename TX_DATA >
using Row = DBRow< TX_DATA, ALLOC >
 a row of the database More...
 
template<typename TX_DATA >
using Matrix = std::vector< DBRow< TX_DATA, ALLOC >, ALLOC< DBRow< TX_DATA, ALLOC > > >
 the type for the matrices stored into the database More...
 
template<template< typename > class XALLOC>
using MissingValType = std::vector< std::string, XALLOC< std::string > >
 
using value_type = Row< T_DATA >
 Types for STL compliance. More...
 
using reference = value_type &
 Types for STL compliance. More...
 
using const_reference = const value_type &
 Types for STL compliance. More...
 
using pointer = value_type *
 Types for STL compliance. More...
 
using const_pointer = const value_type *
 Types for STL compliance. More...
 
using size_type = std::size_t
 Types for STL compliance. More...
 
using difference_type = std::ptrdiff_t
 Types for STL compliance. More...
 
using iterator = Handler
 Types for STL compliance. More...
 
using iterator_safe = HandlerSafe
 Types for STL compliance. More...
 
using const_iterator = const Handler
 Types for STL compliance. More...
 
using const_iterator_safe = const HandlerSafe
 Types for STL compliance. More...
 
using allocator_type = ALLOC< T_DATA >
 Types for STL compliance. More...
 

Protected Attributes

DBVector< std::string > _variable_names
 the names of the variables for each column More...
 

Protected Member Functions

Matrix< T_DATA > & _content () noexcept
 returns the content of the database More...
 
DBVector< IsMissing > & _hasRowMissingVal () noexcept
 returns the vector indicating whether a row contains missing values More...
 
const DBVector< std::string > & _missingSymbols () const
 returns the set of symbols for the missing values More...
 
bool _isRowSizeOK (const std::size_t size) const
 checks whether a size corresponds to the number of columns of the database More...
 
IDatabaseTable< T_DATA, ALLOC > & operator= (const IDatabaseTable< T_DATA, ALLOC > &from)
 copy operator More...
 
IDatabaseTable< T_DATA, ALLOC > & operator= (IDatabaseTable< T_DATA, ALLOC > &&from)
 move constructor More...
 

Friends

class Handler
 allow the handlers to access the database directly More...
 
class HandlerSafe
 
template<typename TX_DATA , template< typename > class OTHER_ALLOC>
class IDatabaseTable
 

Classes

class  Handler
 the (unsafe) handler for the tabular databases More...
 
class  HandlerSafe
 the safe handler of the tabular databases More...
 

Detailed Description

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
class gum::learning::IDatabaseTable< T_DATA, ALLOC >

The common class for the tabular database tables.

Although it is possible to create IDatabases, those are not intended to be created as is but should be created through classes that inherit them, like RawDatabaseTable and DatabaseTable.

Here is an example of how to use the class, illustrated with the DatabaseTable class (in this case, the T_DATA type is just equal to DBTranslatedValue):

// create the database from a CSV. This is not compulsory for
// IDatabaseTable instances, but this is how we usually create
// DatabaseTable instances
gum::learning::DBInitializerFromCSV<> initializer ( "asia.csv" );
const auto& var_names = initializer.variableNames ();
for ( std::size_t i = 0; i < var_names.size(); ++i )
translator_set.insertTranslator ( translator, i );
gum::learning::DatabaseTable<> database ( translator_set );
database.setVariableNames( initializer.variableNames () );
// here, database contains the content of the asia.csv file.
// determine how many columns and rows the database contains
std::size_t nb_rows = database.content().size()
std::size_t nb_cols = database.nbVariables ();
// manually add a new row into the database
std::vector<std::string> row( 8, "toto" ); // asia has 8 columns
database.insertRow ( row );
dbrow ( 8, gum::learning::DBTranslatedValue { std::size_t(0) } );
database.insertRow ( dbrow );
// insert 4 rows in a single call
database.insertRows(
( 4, dbrow ) );
// erase some rows
database.eraseRow ( 12 ); // erase the 13th row of the database
database.eraseFirstRow (); // erase the first row of the database
database.eraseLastRow (); // erase the last row of the database
database.eraseFirstRows ( 2 ); // erase the first two rows
database.eraseLastRows ( 3 ); // erase the last three rows
database.eraseRows ( 2,4 ); // erase rows indexed from 2 to 4 (excluded)
// parse the content of the database, the usual way
for ( const auto& dbrow : database )
std::cout << dbrow.row() << " weight: " << dbrow.weight() << std::endl;
// ignore some columns of the database, i.e., remove them
database.ignoreColumn ( 3 ); // remove the 4th column of the CSV file
// now, the database contains columns 0, 1, 2, 4, 5, 6, 7 of the
// CSV file. If we wish to remove Column 5 of the CSV file:
database.ignoreColumn ( 3 ); // remove the 4th column of the CSV file
// now, the database contains columns 0, 1, 2, 4, 6, 7 of the CSV file.
// if we wish to remove the 3rd column of the IDatabaseTable, i.e.,
// column 2 of the CSV, either we determine that this actually correspond
// to column 2 of the CSV and we use database.ignoreColumn ( 2 ) or
// we call:
database.ignoreColumn ( 2, false ); // false => 2 = the 3rd column of
// the IDatabaseTable, not the 3rd column of the CSV file
// display the columns of the CSV that were ignored and those that
// were kept:
std::vector<std::size_t> ignored_cols = database.ignoredColumns ();
std::vector<std::size_t> kept_cols = database.inputColumns ();
// parse the content of the database using handlers
typename gum::learning::DatabaseTable<>::Handler uhandler( database );
// by default, the handlers range over the whole database
// change the range of rows handled by the DBHandler
std::cout << handler.setRange ( 1, 40 ); // now parses rows [1,40)
std::cout << handler.size (); // displays 39: rows 1,...,39
std::cout << handler.DBSize (); // shows the number of rows in the database
std::cout << handler.numRow (); // displays 0: the handler currently
// points on the first row of its managed area [1,40)
// move the handler to the next row
std::cout << handler.numRow (); // displays 1: the handler points now
// on the second row of its managed area. This corresponds to the third
// DBRow of the database since the range of handler is [1,40)
++handler; // move again to the next row
std::cout << handler.numRow (); // displays 2
handler += 4; // advances the pointer by 4 rows
std::cout << handler.numRow (); // displays 6
// get the DBRow pointed to by the handler: this is the 7th DBRow
// of the database
const auto& xrow7 = handler.row (); // get the DBRow, unsafe version
const auto& yrow7 = handler.rowSafe (); // get the DBRow, safe version
const std::vector<gum::learning::DBCell>& xrow = xrow7.row ();
const double xweight = xrow27.weight ();
// another way to access the row
const auto& zrow7 = *handler; // get the DBRow, unsafe version
// check whether there exist other rows managed by the handler after
// the current row
bool has_rows = handler.hasRows (); // true: there remains 33 rows
// makes the handler point again on the 2nd row of the database
handler.reset (); // the handler points to the beginning of its area
std::cout << handler.numRow (); // displays 0: the handler currently
// points on the first row of its managed area [1,40)
// see the variables' names, i.e., the names of the database's columns
const auto& vars = handler.variableNames();
// parse all the rows managed
for ( auto end = handler.end (); handler != end; ++handler )
std::cout << handler.row ().weight () << std::endl;
// another possibility:
for ( const auto& row : handler )
std::cout << row.weight () << std::endl;

Definition at line 251 of file IDatabaseTable.h.

Member Typedef Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::allocator_type = ALLOC< T_DATA >

Types for STL compliance.

Definition at line 765 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::const_iterator = const Handler

Types for STL compliance.

Definition at line 763 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::const_iterator_safe = const HandlerSafe

Types for STL compliance.

Definition at line 764 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::const_pointer = const value_type*

Types for STL compliance.

Definition at line 758 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::const_reference = const value_type&

Types for STL compliance.

Definition at line 756 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<typename TX_DATA >
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::DBVector = std::vector< TX_DATA, ALLOC< TX_DATA > >

the type for the vectors used in the IDatabaseTable

Definition at line 259 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::difference_type = std::ptrdiff_t

Types for STL compliance.

Definition at line 760 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::iterator = Handler

Types for STL compliance.

Definition at line 761 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::iterator_safe = HandlerSafe

Types for STL compliance.

Definition at line 762 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<typename TX_DATA >
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::Matrix = std::vector< DBRow< TX_DATA, ALLOC >, ALLOC< DBRow< TX_DATA, ALLOC > > >

the type for the matrices stored into the database

Definition at line 268 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<template< typename > class XALLOC>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::MissingValType = std::vector< std::string, XALLOC< std::string > >

Definition at line 271 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::pointer = value_type*

Types for STL compliance.

Definition at line 757 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::reference = value_type&

Types for STL compliance.

Definition at line 755 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<typename TX_DATA >
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::Row = DBRow< TX_DATA, ALLOC >

a row of the database

Definition at line 263 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::size_type = std::size_t

Types for STL compliance.

Definition at line 759 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
using gum::learning::IDatabaseTable< T_DATA, ALLOC >::value_type = Row< T_DATA >

Types for STL compliance.

Definition at line 754 of file IDatabaseTable.h.

Member Enumeration Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
enum gum::learning::IDatabaseTable::IsMissing : char
Enumerator
False 
True 

Definition at line 274 of file IDatabaseTable.h.

Constructor & Destructor Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<template< typename > class VARALLOC, template< typename > class MISSALLOC>
gum::learning::IDatabaseTable< T_DATA, ALLOC >::IDatabaseTable ( const MissingValType< MISSALLOC > &  missing_symbols,
const std::vector< std::string, VARALLOC< std::string > > &  var_names,
const ALLOC< T_DATA > &  alloc 
)

default constructor

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

copy constructor

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

copy constructor with a given allocator

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

move constructor

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

move constructor with a given allocator

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

destructor

Member Function Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
Matrix< T_DATA >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::_content ( )
protectednoexcept

returns the content of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
DBVector< IsMissing >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::_hasRowMissingVal ( )
protectednoexcept

returns the vector indicating whether a row contains missing values

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
bool gum::learning::IDatabaseTable< T_DATA, ALLOC >::_isRowSizeOK ( const std::size_t  size) const
protected

checks whether a size corresponds to the number of columns of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const DBVector< std::string >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::_missingSymbols ( ) const
protected

returns the set of symbols for the missing values

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
iterator gum::learning::IDatabaseTable< T_DATA, ALLOC >::begin ( ) const

returns a new unsafe handler pointing to the beginning of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
iterator_safe gum::learning::IDatabaseTable< T_DATA, ALLOC >::beginSafe ( ) const

returns a new safe handler pointing to the beginning of the database

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

erase the content of the database, including the names of the variables

Reimplemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

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

virtual copy constructor with a given allocator

Implemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::IDatabaseTable< T_DATA, ALLOC >::columnFromVariableName ( const std::string &  name) const

returns the index of the column whose name is passed in argument

Exceptions
UndefinedElementis raised if there exists no column with the given name
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const Matrix< T_DATA >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::content ( ) const
noexcept

returns the content of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const iterator& gum::learning::IDatabaseTable< T_DATA, ALLOC >::end ( ) const
noexcept

returns a new unsafe handler pointing to the end of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const iterator_safe& gum::learning::IDatabaseTable< T_DATA, ALLOC >::endSafe ( ) const
noexcept

returns a new safe handler pointing to the end of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseAllRows ( )

erase all the rows

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseFirstRow ( )

erase the first row

Warning
if the row does not exist, nothing is done. In particular, no exception is raised.
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseFirstRows ( const std::size_t  k)

erase the k first rows

Warning
if there are fewer than k rows in the database, the database is completely emptied
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseLastRow ( )

erase the last row

Warning
if the row does not exist, nothing is done. In particular, no exception is raised.
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseLastRows ( const std::size_t  k)

erase the k last rows

Warning
if there are fewer than k rows in the database, the database is completely emptied
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseRow ( std::size_t  index)

erase a given row specified by its index in the table

In the database, rows are indexed, starting from 0.

Warning
If the row does not exist, nothing is done. In particular, no exception is raised.
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::eraseRows ( std::size_t  deb,
std::size_t  end 
)

erase the rows from the debth to the endth (not included)

In the database, rows are indexed, starting from 0.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
ALLOC< T_DATA > gum::learning::IDatabaseTable< T_DATA, ALLOC >::getAllocator ( ) const

returns the allocator of the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
iterator gum::learning::IDatabaseTable< T_DATA, ALLOC >::handler ( ) const

returns a new unsafe handler on the database

Referenced by gum::learning::genericBNLearner::Database::Database(), and gum::learning::genericBNLearner::Database::operator=().

+ Here is the caller graph for this function:

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
iterator_safe gum::learning::IDatabaseTable< T_DATA, ALLOC >::handlerSafe ( ) const

returns a new safe handler on the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
bool gum::learning::IDatabaseTable< T_DATA, ALLOC >::hasMissingValues ( ) const

indicates whether the database contains some missing values

Referenced by gum::learning::genericBNLearner::Database::Database().

+ Here is the caller graph for this function:

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
bool gum::learning::IDatabaseTable< T_DATA, ALLOC >::hasMissingValues ( const std::size_t  k) const

indicates whether the kth row contains some missing values

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::ignoreColumn ( const std::size_t  k,
const bool  from_external_object = true 
)
pure virtual

makes the database table ignore from now on the kth column

This method can be called in two different ways: either k refers to the current kth column of the database table (in this case, parameter from_external_object is set to false), or k corresponds to the kth column of an original dataset used to fill the database table (in this case from_external_object is set to true). Depending on from_external_object's value, the ignored columns may differ. As an example, imagine that the database table is created from a CSV file with 5 columns named X0, X1, X2, X3 and X4 respectivly. Then a call to ignoreColumn ( 1, true ) will exclude column X1 from the database table. As a result, the database table columns are X0, X2, X3 and X4. Therefore, subsequently calling ignoreColumn ( 1, false ) will result in excluding X2 since X2 is the 2nd column (columns are indexed starting from 0). So, now the database table's columns are X0, X3 and X4. If, now, we call ignoreColumn ( 3, true ), this will remove column X3 because, in the original database, X3 was the 4th column.

Warning
If the database table was not empty, then the kth column is removed from all the rows currently stored.
If the kth column does not exist (i.e., the original dataset does not contain the kth column when from_external_object is set to true, or the IDatabaseTable has no kth column when from_external_object is set to false), column k is marked as to be ignored and nothing is done on the content of the IDatabaseTable. No exception is raised.
Parameters
kthe column to remove. See the above detailed description on how k is computed.
from_external_objectindicates whether k refers to the kth column of an original external database or to the current kth column of the database table.

Implemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual const DBVector< std::size_t > gum::learning::IDatabaseTable< T_DATA, ALLOC >::ignoredColumns ( ) const
pure virtual

returns the set of columns of the original dataset that are ignored

Implemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual const DBVector< std::size_t > gum::learning::IDatabaseTable< T_DATA, ALLOC >::inputColumns ( ) const
pure virtual

returns the set of columns of the original dataset that are present in the IDatabaseTable

Implemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<template< typename > class OTHER_ALLOC>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::insertRow ( const std::vector< std::string, OTHER_ALLOC< std::string > > &  new_row)

insert a new row at the end of the database

The new_row passed in argument is supposed to come from an external database. So it must contain data for the ignored columns.

Exceptions
SizeErroris raised if the vector of string cannot be inserted in the IDatabaseTable because its size does not allow a matching with the columns of the IDatabaseTable (taking into account the ignored columns)
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::insertRow ( Row< T_DATA > &&  new_row,
const IsMissing  contains_missing_data 
)
virtual

insert a new DBRow at the end of the database

Unlike methods insertRow for data whose type is different from T_DATA, this method assumes that the new row passed in argument does not contain any data of the ignored columns. So, basically, it could be copied as is into the database table.

Exceptions
SizeErroris raised if the size of the new_row is not equal to the number of columns retained in the IDatabaseTable
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::insertRow ( const Row< T_DATA > &  new_row,
const IsMissing  contains_missing_data 
)
virtual

insert a new row at the end of the database

Unlike methods insertRow for data whose type is different from T_DATA, this method assumes that the new row passed in argument does not contain any data of the ignored columns. So, basically, it could be copied as is into the database table.

Exceptions
SizeErroris raised if the size of the new_row is not equal to the number of columns retained in the IDatabaseTable
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::insertRows ( Matrix< T_DATA > &&  new_rows,
const DBVector< IsMissing > &  rows_have_missing_vals 
)
virtual

insert a set of new DBRows at the end of the database

Unlike methods insertRows for data whose type is different from T_DATA, this method assumes that the new rows passed in argument do not contain any data of the ignored columns. So, basically, these rows could be copied as is into the database table.

Exceptions
SizeErroris raised if the size of at least one row in new_rows is not equal to the number of columns retained in the IDatabaseTable
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::insertRows ( const Matrix< T_DATA > &  new_rows,
const DBVector< IsMissing > &  rows_have_missing_vals 
)
virtual

insert a set of new DBRows at the end of the database

Unlike methods insertRows for data whose type is different from T_DATA, this method assumes that the new rows passed in argument do not contain any data of the ignored columns. So, basically, these rows could be copied as is into the database table.

Exceptions
SizeErroris raised if the size of at least one row in new_rows is not equal to the number of columns retained in the IDatabaseTable
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const DBVector< std::string >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::missingSymbols ( ) const

returns the set of missing symbols

Referenced by gum::learning::genericBNLearner::Database::missingSymbols().

+ Here is the caller graph for this function:

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::IDatabaseTable< T_DATA, ALLOC >::nbVariables ( ) const
noexcept

returns the number of variables (columns) of the database

Referenced by gum::learning::genericBNLearner::Database::__BNVars(), and gum::learning::genericBNLearner::Database::Database().

+ Here is the caller graph for this function:

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

copy operator

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
IDatabaseTable< T_DATA, ALLOC >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::operator= ( IDatabaseTable< T_DATA, ALLOC > &&  from)
protected

move constructor

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
virtual void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setVariableNames ( const std::vector< std::string, ALLOC< std::string > > &  names,
const bool  from_external_object = true 
)
pure virtual

sets the names of the variables

This method can be called in two different ways: either the names correspond precisely to the columns stored into the database table (in this case, parameter from_external_object is equal to false), or they corresponds to the columns of an external database (e.g., a CSV file) from which we potentially excluded some columns and, consequently, these columns should not be taken into account (in this case, parameter from_external_object is equal to true). As an example, imagine that the database table is created from a CSV file with 5 columns named X0, X1, X2, X3 and X4 respectivly. Suppose that we asked the database table to ignore columns X1 and X3. Then setVariableNames( { "X0", "X1", "X2", "X3", "X4" }, true ) will set the columns of the database table as { "X0", "X2", "X4" }. The same result could be obtained by executing setVariableNames( { "X0", "X2", "X4" }, false ), which specifies directly the set of names to retain in the database table.

Parameters
namesthe names of all the columns, including the ignored columns if from_external_object is set to true, else excluding them (i.e., this should precisely correspond to the columns stored into the database table).
from_external_objecta Boolean indicating whether parameter names includes the columns ignored by the database table (true) or not (false).
Exceptions
SizeErroris raised if the names passed in arguments cannot be assigned to the columns of the IDatabaseTable because the size of their vector is inadequate.

Implemented in gum::learning::DatabaseTable< ALLOC >, and gum::learning::RawDatabaseTable< ALLOC >.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<template< typename > class OTHER_ALLOC>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setVariableNames ( const std::vector< std::string, OTHER_ALLOC< std::string > > &  names,
const bool  from_external_object = true 
)

sets the names of the variables

This method can be called in two different ways: either the names correspond precisely to the columns stored into the database table (in this case, parameter from_external_object is equal to false), or they corresponds to the columns of an external database (e.g., a CSV file) from which we potentially excluded some columns and, consequently, these columns should not be taken into account (in this case, parameter from_external_object is equal to true). As an example, imagine that the database table is created from a CSV file with 5 columns named X0, X1, X2, X3 and X4 respectivly. Suppose that we asked the database table to ignore columns X1 and X3. Then setVariableNames( { "X0", "X1", "X2", "X3", "X4" }, true ) will set the columns of the database table as { "X0", "X2", "X4" }. The same result could be obtained by executing setVariableNames( { "X0", "X2", "X4" }, false ), which specifies directly the set of names to retain in the database table.

Parameters
namesthe names of all the columns, including the ignored columns if from_external_object is set to true, else excluding them (i.e., this should precisely correspond to the columns stored into the database table).
from_external_objecta Boolean indicating whether parameter names includes the columns ignored by the database table (true) or not (false).
Exceptions
SizeErroris raised if the names passed in arguments cannot be assigned to the columns of the IDatabaseTable because the size of their vector is inadequate.
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::IDatabaseTable< T_DATA, ALLOC >::size ( ) const
noexcept

returns the number of records (rows) in the database

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const std::string& gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableName ( const std::size_t  k) const

returns the name of the kth column of the database

Exceptions
OutOfBoundsis raised if the dtabase contains fewer than k columns.
template<typename T_DATA, template< typename > class ALLOC = std::allocator>
const DBVector< std::string >& gum::learning::IDatabaseTable< T_DATA, ALLOC >::variableNames ( ) const
noexcept

returns the variable names for all the columns of the database

The names do not include the ignored columns.

Referenced by gum::learning::genericBNLearner::Database::Database(), and gum::learning::genericBNLearner::Database::names().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
template<typename TX_DATA , template< typename > class OTHER_ALLOC>
friend class IDatabaseTable
friend

Definition at line 1146 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
friend class Handler
friend

allow the handlers to access the database directly

Definition at line 1141 of file IDatabaseTable.h.

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
friend class HandlerSafe
friend

Definition at line 1142 of file IDatabaseTable.h.

Member Data Documentation

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
DBVector< std::string > gum::learning::IDatabaseTable< T_DATA, ALLOC >::_variable_names
protected

the names of the variables for each column

Definition at line 1076 of file IDatabaseTable.h.


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