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

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

#include <agrum/BN/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 (the records) of the database More...
 
iterator handler () const
 returns a new unsafe handler pointing to the 1st record of the database More...
 
iterator_safe handlerSafe () const
 returns a new safe handler pointing to the 1st record of 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 IDatabaseTable More...
 
std::size_t columnFromVariableName (const std::string &name) const
 returns the index of the column whose name is passed in argument More...
 
DBVector< std::size_t > columnsFromVariableName (const std::string &name) const
 returns the indices of all the columns 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 nbRows () const noexcept
 returns the number of records (rows) in the database More...
 
std::size_t size () const noexcept
 returns the number of records (rows) in the database More...
 
bool empty () const noexcept
 indicates whether the database contains some records or not 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...
 
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...
 
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...
 
void setMaxNbThreads (const std::size_t nb) const
 changes the max number of threads that a database can use More...
 
std::size_t nbThreads () const
 returns the number of threads used to parse the database More...
 
void setMinNbRowsPerThread (const std::size_t nb) const
 changes the number min of rows a thread should process in a multithreading context More...
 
std::size_t minNbRowsPerThread () const
 returns the minimum of rows that each thread should process More...
 
void setAllRowsWeight (const double new_weight)
 assign a given weight to all the rows of the database More...
 
void setWeight (const std::size_t i, const double weight)
 assigns a given weight to the ith row of the database More...
 
double weight (const std::size_t i) const
 returns the weight of the ith record More...
 
double weight () const
 returns the weight of the whole database 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...
 
Matrix< T_DATA > rows_
 
DBVector< std::string > missing_symbols_
 
DBVector< IsMissinghas_row_missing_val_
 
std::size_t max_nb_threads_ {std::size_t(gum::getMaxNumberOfThreads())}
 
std::size_t min_nb_rows_per_thread_ {100}
 

Protected Member Functions

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 operator More...
 

Friends

class Handler
 allow the handlers to access the database directly More...
 
class HandlerSafe
 

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.

IDatabases are not intended to be created as is but should be created through the RawDatabaseTable and DatabaseTable classes. They represent the structures shared by these latter classes.

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.nbRows();
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 column X3 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 X5 of the CSV file:
database.ignoreColumn ( 5 ); // remove the column X5 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 5th column of the IDatabaseTable, i.e.,
// column #4 of the CSV, either we determine that this actually correspond
// to column X6 of the CSV and we use database.ignoreColumn ( 6 ) or
// we call:
database.ignoreColumn ( 4, false ); // false => 4 = the 5th column of
// the IDatabaseTable, not the 5th column/variable of the CSV file
// (remember that all column numbers start from 0).
// 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

◆ allocator_type

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 770 of file IDatabaseTable.h.

◆ const_iterator

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 768 of file IDatabaseTable.h.

◆ const_iterator_safe

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 769 of file IDatabaseTable.h.

◆ const_pointer

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 763 of file IDatabaseTable.h.

◆ const_reference

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 761 of file IDatabaseTable.h.

◆ DBVector

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 257 of file IDatabaseTable.h.

◆ difference_type

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 765 of file IDatabaseTable.h.

◆ iterator

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 766 of file IDatabaseTable.h.

◆ iterator_safe

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 767 of file IDatabaseTable.h.

◆ Matrix

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 265 of file IDatabaseTable.h.

◆ MissingValType

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 268 of file IDatabaseTable.h.

◆ pointer

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 762 of file IDatabaseTable.h.

◆ reference

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 760 of file IDatabaseTable.h.

◆ Row

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 261 of file IDatabaseTable.h.

◆ size_type

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 764 of file IDatabaseTable.h.

◆ value_type

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 759 of file IDatabaseTable.h.

Member Enumeration Documentation

◆ IsMissing

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

Definition at line 271 of file IDatabaseTable.h.

Constructor & Destructor Documentation

◆ IDatabaseTable() [1/5]

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

◆ IDatabaseTable() [2/5]

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

◆ IDatabaseTable() [3/5]

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

◆ IDatabaseTable() [4/5]

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

move constructor

◆ IDatabaseTable() [5/5]

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

◆ ~IDatabaseTable()

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

destructor

Member Function Documentation

◆ begin()

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

◆ beginSafe()

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

◆ clear()

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

◆ clone() [1/2]

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

◆ clone() [2/2]

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

◆ columnFromVariableName()

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

Warning
If several columns correspond to the name, only the column with the lowest index is returned. If you wish to retrieve all the columns, use method columnsFromVariableName
Exceptions
UndefinedElementis raised if there exists no column with the given name

◆ columnsFromVariableName()

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

returns the indices of all the columns whose name is passed in argument

It may happen that several columns correspond to a given variable name. In this case, the function returns the indices of all the columns of the IDatabase that match the name.

◆ content()

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 (the records) of the database

◆ empty()

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

indicates whether the database contains some records or not

◆ end()

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

◆ endSafe()

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

◆ eraseAllRows()

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

erase all the rows

◆ eraseFirstRow()

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.

◆ eraseFirstRows()

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

◆ eraseLastRow()

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.

◆ eraseLastRows()

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

◆ eraseRow()

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.

◆ eraseRows()

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.

◆ getAllocator()

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

◆ handler()

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

returns a new unsafe handler pointing to the 1st record of the database

◆ handlerSafe()

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 pointing to the 1st record of the database

◆ hasMissingValues() [1/2]

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

◆ hasMissingValues() [2/2]

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

◆ ignoreColumn()

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

◆ ignoredColumns()

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

◆ inputColumns()

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

◆ insertRow() [1/3]

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)

◆ insertRow() [2/3]

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

◆ insertRow() [3/3]

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

◆ insertRows() [1/2]

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.

Parameters
new_rowsthe new set of rows to be copied as is
rows_have_missing_valsa vector of the same size as new_rows that indicates, for each new row, whether it contains some missing value or not
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. A SizeError exception will also be raised if the number of new rows is not identical to the size of vector rows_have_missing_vals.

◆ insertRows() [2/2]

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.

Parameters
new_rowsthe new set of rows to be copied as is
rows_have_missing_valsa vector of the same size as new_rows that indicates, for each new row, whether it contains some missing value or not
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. A SizeError exception will also be raised if the number of new rows is not identical to the size of vector rows_have_missing_vals.

◆ isRowSizeOK_()

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

◆ minNbRowsPerThread()

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

returns the minimum of rows that each thread should process

◆ missingSymbols()

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

◆ nbRows()

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

returns the number of records (rows) in the database

◆ nbThreads()

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

returns the number of threads used to parse the database

◆ nbVariables()

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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 operator

◆ setAllRowsWeight()

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setAllRowsWeight ( const double  new_weight)

assign a given weight to all the rows of the database

◆ setMaxNbThreads()

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setMaxNbThreads ( const std::size_t  nb) const

changes the max number of threads that a database can use

Within databases, some methods can be processed in a parallel fashion. This methods indicates the maximum number of threads that can be run in parallel at the same time.

◆ setMinNbRowsPerThread()

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setMinNbRowsPerThread ( const std::size_t  nb) const

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

When a method executes several threads to perform actions on the rows of the database, the MinNbRowsPerThread 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.

◆ setVariableNames() [1/2]

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, the latter 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 respectively. 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 >.

◆ setVariableNames() [2/2]

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, the latter 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 respectively. 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.

◆ setWeight()

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
void gum::learning::IDatabaseTable< T_DATA, ALLOC >::setWeight ( const std::size_t  i,
const double  weight 
)

assigns a given weight to the ith row of the database

Exceptions
OutOfBoundsif i is outside the set of indices of the records or if the weight is negative

◆ size()

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

◆ variableName()

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 IDatabaseTable

Exceptions
OutOfBoundsis raised if the IDatabaseTable contains fewer than k columns.

◆ variableNames()

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.

◆ weight() [1/2]

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
double gum::learning::IDatabaseTable< T_DATA, ALLOC >::weight ( const std::size_t  i) const

returns the weight of the ith record

Exceptions
OutOfBoundsif i is outside the set of indices of the records

◆ weight() [2/2]

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

returns the weight of the whole database

Friends And Related Function Documentation

◆ Handler

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 1195 of file IDatabaseTable.h.

◆ HandlerSafe

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

Definition at line 1196 of file IDatabaseTable.h.

Member Data Documentation

◆ has_row_missing_val_

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

Definition at line 1142 of file IDatabaseTable.h.

◆ max_nb_threads_

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::IDatabaseTable< T_DATA, ALLOC >::max_nb_threads_ {std::size_t(gum::getMaxNumberOfThreads())}
mutableprotected

Definition at line 1145 of file IDatabaseTable.h.

◆ min_nb_rows_per_thread_

template<typename T_DATA, template< typename > class ALLOC = std::allocator>
std::size_t gum::learning::IDatabaseTable< T_DATA, ALLOC >::min_nb_rows_per_thread_ {100}
mutableprotected

Definition at line 1149 of file IDatabaseTable.h.

◆ missing_symbols_

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

Definition at line 1139 of file IDatabaseTable.h.

◆ rows_

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

Definition at line 1136 of file IDatabaseTable.h.

◆ variable_names_

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 1133 of file IDatabaseTable.h.


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