mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
m::SpnWrapper Struct Reference

A wrapper class for an Spn to be used in the context of databases. More...

#include <SpnWrapper.hpp>

Collaboration diagram for m::SpnWrapper:
[legend]

Public Types

using Filter = std::unordered_map< unsigned, std::pair< Spn::SpnOperator, float > >
 
using AttrFilter = std::unordered_map< ThreadSafePooledString, std::pair< Spn::SpnOperator, float > >
 

Public Member Functions

 SpnWrapper (const SpnWrapper &)=delete
 
 SpnWrapper (SpnWrapper &&)=default
 
const std::unordered_map< ThreadSafePooledString, unsigned > & get_attribute_to_id () const
 Get the reference to the attribute to spn internal id mapping.
 
std::size_t num_rows () const
 returns the number of rows in the SPN.
 
float likelihood (const AttrFilter &attr_filter) const
 Compute the likelihood of the given filter predicates given by a map from attribute to the respective operator and value.
 
float likelihood (const Filter &filter) const
 Compute the likelihood of the given filter predicates given by a map from spn internal id to the respective operator and value.
 
float upper_bound (const AttrFilter &attr_filter) const
 Compute the upper bound probability for continuous domains.
 
float upper_bound (const Filter &filter) const
 Compute the upper bound probability for continuous domains.
 
float lower_bound (const AttrFilter &attr_filter) const
 Compute the lower bound probability for continuous domains.
 
float lower_bound (const Filter &filter) const
 Compute the lower bound probability for continuous domains.
 
float expectation (const ThreadSafePooledString &attribute, const AttrFilter &attr_filter) const
 Compute the expectation of the given attribute.
 
float expectation (unsigned attribute_id, const Filter &filter) const
 Compute the expectation of the given attribute.
 
void update_row (Eigen::VectorXf &old_row, Eigen::VectorXf &updated_row)
 Update the SPN with the given row.
 
void insert_row (Eigen::VectorXf &row)
 Insert the given row into the SPN.
 
void delete_row (Eigen::VectorXf &row)
 Delete the given row from the SPN.
 
std::size_t estimate_number_distinct_values (const ThreadSafePooledString &attribute) const
 Estimate the number of distinct values of the given attribute.
 
std::size_t estimate_number_distinct_values (unsigned attribute_id) const
 Estimate the number of distinct values of the given attribute.
 
unsigned height () const
 
unsigned breadth () const
 
unsigned degree () const
 
std::size_t memory_usage () const
 
void dump () const
 
void dump (std::ostream &out) const
 

Static Public Member Functions

static SpnWrapper learn_spn_table (const ThreadSafePooledString &name_of_database, const ThreadSafePooledString &name_of_table, std::vector< Spn::LeafType > leaf_types=decltype(leaf_types)())
 Learn an SPN over the given table.
 
static std::unordered_map< ThreadSafePooledString, SpnWrapper * > learn_spn_database (const ThreadSafePooledString &name_of_database, std::unordered_map< ThreadSafePooledString, std::vector< Spn::LeafType > > leaf_types=decltype(leaf_types)())
 Learn SPNs over the tables in the given database.
 

Private Member Functions

 SpnWrapper (Spn spn, std::unordered_map< ThreadSafePooledString, unsigned > attribute_to_id)
 
Filter translate_filter (const AttrFilter &attr_filter) const
 
unsigned translate_attribute (const ThreadSafePooledString &attribute) const
 

Private Attributes

Spn spn_
 
std::unordered_map< ThreadSafePooledString, unsigned > attribute_to_id_
 a map from attribute to spn internal id
 

Detailed Description

A wrapper class for an Spn to be used in the context of databases.

Definition at line 12 of file SpnWrapper.hpp.

Member Typedef Documentation

◆ AttrFilter

using m::SpnWrapper::AttrFilter = std::unordered_map<ThreadSafePooledString, std::pair<Spn::SpnOperator, float> >

Definition at line 15 of file SpnWrapper.hpp.

◆ Filter

using m::SpnWrapper::Filter = std::unordered_map<unsigned, std::pair<Spn::SpnOperator, float> >

Definition at line 14 of file SpnWrapper.hpp.

Constructor & Destructor Documentation

◆ SpnWrapper() [1/3]

m::SpnWrapper::SpnWrapper ( Spn  spn,
std::unordered_map< ThreadSafePooledString, unsigned >  attribute_to_id 
)
inlineprivate

Definition at line 21 of file SpnWrapper.hpp.

◆ SpnWrapper() [2/3]

m::SpnWrapper::SpnWrapper ( const SpnWrapper )
delete

◆ SpnWrapper() [3/3]

m::SpnWrapper::SpnWrapper ( SpnWrapper &&  )
default

Member Function Documentation

◆ breadth()

unsigned m::SpnWrapper::breadth ( ) const
inline

Definition at line 119 of file SpnWrapper.hpp.

References m::Spn::breadth(), and spn_.

◆ degree()

unsigned m::SpnWrapper::degree ( ) const
inline

Definition at line 120 of file SpnWrapper.hpp.

References m::Spn::degree(), and spn_.

◆ delete_row()

void m::SpnWrapper::delete_row ( Eigen::VectorXf &  row)
inline

Delete the given row from the SPN.

Definition at line 107 of file SpnWrapper.hpp.

References m::Spn::delete_row(), and spn_.

◆ dump() [1/2]

void m::SpnWrapper::dump ( ) const
inline

Definition at line 122 of file SpnWrapper.hpp.

References m::Spn::dump(), and spn_.

◆ dump() [2/2]

void m::SpnWrapper::dump ( std::ostream &  out) const
inline

Definition at line 123 of file SpnWrapper.hpp.

References m::Spn::dump(), and spn_.

◆ estimate_number_distinct_values() [1/2]

std::size_t m::SpnWrapper::estimate_number_distinct_values ( const ThreadSafePooledString attribute) const
inline

Estimate the number of distinct values of the given attribute.

Definition at line 110 of file SpnWrapper.hpp.

References m::Spn::estimate_number_distinct_values(), spn_, and translate_attribute().

Referenced by m::SpnEstimator::max_frequency().

◆ estimate_number_distinct_values() [2/2]

std::size_t m::SpnWrapper::estimate_number_distinct_values ( unsigned  attribute_id) const
inline

Estimate the number of distinct values of the given attribute.

Definition at line 114 of file SpnWrapper.hpp.

References m::Spn::estimate_number_distinct_values(), and spn_.

◆ expectation() [1/2]

float m::SpnWrapper::expectation ( const ThreadSafePooledString attribute,
const AttrFilter attr_filter 
) const
inline

Compute the expectation of the given attribute.

Definition at line 92 of file SpnWrapper.hpp.

References m::Spn::expectation(), spn_, translate_attribute(), and translate_filter().

◆ expectation() [2/2]

float m::SpnWrapper::expectation ( unsigned  attribute_id,
const Filter filter 
) const
inline

Compute the expectation of the given attribute.

Definition at line 96 of file SpnWrapper.hpp.

References m::Spn::expectation(), and spn_.

◆ get_attribute_to_id()

const std::unordered_map< ThreadSafePooledString, unsigned > & m::SpnWrapper::get_attribute_to_id ( ) const
inline

Get the reference to the attribute to spn internal id mapping.

Definition at line 45 of file SpnWrapper.hpp.

References attribute_to_id_.

Referenced by m::SpnEstimator::max_frequency().

◆ height()

unsigned m::SpnWrapper::height ( ) const
inline

Definition at line 118 of file SpnWrapper.hpp.

References m::Spn::height(), and spn_.

◆ insert_row()

void m::SpnWrapper::insert_row ( Eigen::VectorXf &  row)
inline

Insert the given row into the SPN.

Definition at line 104 of file SpnWrapper.hpp.

References m::Spn::insert_row(), and spn_.

◆ learn_spn_database()

std::unordered_map< ThreadSafePooledString, SpnWrapper * > SpnWrapper::learn_spn_database ( const ThreadSafePooledString name_of_database,
std::unordered_map< ThreadSafePooledString, std::vector< Spn::LeafType > >  leaf_types = decltype(leaf_types)() 
)
static

Learn SPNs over the tables in the given database.

Parameters
name_of_databasethe database
leaf_typesthe type of a leaf for a non-primary key attribute in the respective table
Returns
the learned SPNs

Definition at line 133 of file SpnWrapper.cpp.

References m::Catalog::Get(), and learn_spn_table().

Referenced by m::SpnEstimator::learn_spns().

◆ learn_spn_table()

SpnWrapper SpnWrapper::learn_spn_table ( const ThreadSafePooledString name_of_database,
const ThreadSafePooledString name_of_table,
std::vector< Spn::LeafType leaf_types = decltype(leaf_types)() 
)
static

Learn an SPN over the given table.

Parameters
name_of_databasethe database
name_of_tablethe table in the database
leaf_typesthe types of a leaf for a non-primary key attribute
Returns
the learned SPN

Definition at line 11 of file SpnWrapper.cpp.

References m::Spn::AUTO, m::Spn::CONTINUOUS, m::Spn::DISCRETE, m::execute_query(), m::Catalog::Get(), lower_bound(), num_rows(), m::statement_from_string(), and m::T().

Referenced by m::SpnEstimator::learn_new_spn(), and learn_spn_database().

◆ likelihood() [1/2]

float m::SpnWrapper::likelihood ( const AttrFilter attr_filter) const
inline

Compute the likelihood of the given filter predicates given by a map from attribute to the respective operator and value.

The predicates in the map are seen as conjunctions.

Definition at line 76 of file SpnWrapper.hpp.

References m::Spn::likelihood(), spn_, and translate_filter().

◆ likelihood() [2/2]

float m::SpnWrapper::likelihood ( const Filter filter) const
inline

Compute the likelihood of the given filter predicates given by a map from spn internal id to the respective operator and value.

The predicates in the map are seen as conjunctions.

Definition at line 79 of file SpnWrapper.hpp.

References m::Spn::likelihood(), and spn_.

◆ lower_bound() [1/2]

float m::SpnWrapper::lower_bound ( const AttrFilter attr_filter) const
inline

Compute the lower bound probability for continuous domains.

Definition at line 87 of file SpnWrapper.hpp.

References m::Spn::lower_bound(), spn_, and translate_filter().

Referenced by learn_spn_table().

◆ lower_bound() [2/2]

float m::SpnWrapper::lower_bound ( const Filter filter) const
inline

Compute the lower bound probability for continuous domains.

Definition at line 89 of file SpnWrapper.hpp.

References m::Spn::lower_bound(), and spn_.

◆ memory_usage()

std::size_t m::SpnWrapper::memory_usage ( ) const
inline

Definition at line 121 of file SpnWrapper.hpp.

References m::Spn::memory_usage(), and spn_.

◆ num_rows()

std::size_t m::SpnWrapper::num_rows ( ) const
inline

returns the number of rows in the SPN.

Definition at line 72 of file SpnWrapper.hpp.

References m::Spn::num_rows(), and spn_.

Referenced by m::SpnEstimator::estimate_scan(), and learn_spn_table().

◆ translate_attribute()

unsigned m::SpnWrapper::translate_attribute ( const ThreadSafePooledString attribute) const
inlineprivate

Definition at line 32 of file SpnWrapper.hpp.

References attribute_to_id_.

Referenced by estimate_number_distinct_values(), expectation(), and translate_filter().

◆ translate_filter()

Filter m::SpnWrapper::translate_filter ( const AttrFilter attr_filter) const
inlineprivate

Definition at line 26 of file SpnWrapper.hpp.

References translate_attribute().

Referenced by expectation(), likelihood(), lower_bound(), and upper_bound().

◆ update_row()

void m::SpnWrapper::update_row ( Eigen::VectorXf &  old_row,
Eigen::VectorXf &  updated_row 
)
inline

Update the SPN with the given row.

Definition at line 101 of file SpnWrapper.hpp.

References spn_, and m::Spn::update_row().

◆ upper_bound() [1/2]

float m::SpnWrapper::upper_bound ( const AttrFilter attr_filter) const
inline

Compute the upper bound probability for continuous domains.

Definition at line 82 of file SpnWrapper.hpp.

References spn_, translate_filter(), and m::Spn::upper_bound().

◆ upper_bound() [2/2]

float m::SpnWrapper::upper_bound ( const Filter filter) const
inline

Compute the upper bound probability for continuous domains.

Definition at line 84 of file SpnWrapper.hpp.

References spn_, and m::Spn::upper_bound().

Field Documentation

◆ attribute_to_id_

std::unordered_map<ThreadSafePooledString, unsigned> m::SpnWrapper::attribute_to_id_
private

a map from attribute to spn internal id

Definition at line 19 of file SpnWrapper.hpp.

Referenced by get_attribute_to_id(), and translate_attribute().

◆ spn_

Spn m::SpnWrapper::spn_
private

The documentation for this struct was generated from the following files: