4#include <unordered_map>
14 using Filter = std::unordered_map<unsigned, std::pair<Spn::SpnOperator, float>>;
15 using AttrFilter = std::unordered_map<ThreadSafePooledString, std::pair<Spn::SpnOperator, float>>;
21 SpnWrapper(
Spn spn, std::unordered_map<ThreadSafePooledString, unsigned> attribute_to_id)
28 for (
auto &elem : attr_filter) { filter.emplace(
translate_attribute(elem.first), elem.second); }
36 }
else { std::cerr <<
"could not find attribute: " << attribute << std::endl; }
56 std::vector<Spn::LeafType> leaf_types =
decltype(leaf_types)());
64 static std::unordered_map<ThreadSafePooledString, SpnWrapper*>
ThreadSafeStringPool::proxy_type ThreadSafePooledString
A wrapper class for an Spn to be used in the context of databases.
void dump(std::ostream &out) const
float expectation(unsigned attribute_id, const Filter &filter) const
Compute the expectation of the given attribute.
unsigned translate_attribute(const ThreadSafePooledString &attribute) const
std::size_t estimate_number_distinct_values(const ThreadSafePooledString &attribute) const
Estimate the number of distinct values of the given attribute.
void update_row(Eigen::VectorXf &old_row, Eigen::VectorXf &updated_row)
Update the SPN with the given row.
std::size_t num_rows() const
returns the number of rows in the SPN.
float upper_bound(const AttrFilter &attr_filter) const
Compute the upper bound probability for continuous domains.
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.
std::size_t memory_usage() const
float lower_bound(const AttrFilter &attr_filter) const
Compute the lower bound probability for continuous domains.
std::unordered_map< ThreadSafePooledString, std::pair< Spn::SpnOperator, float > > AttrFilter
SpnWrapper(const SpnWrapper &)=delete
void delete_row(Eigen::VectorXf &row)
Delete the given row from the SPN.
float likelihood(const Filter &filter) const
Compute the likelihood of the given filter predicates given by a map from spn internal id to the resp...
std::unordered_map< unsigned, std::pair< Spn::SpnOperator, float > > Filter
std::size_t estimate_number_distinct_values(unsigned attribute_id) const
Estimate the number of distinct values of the given attribute.
float likelihood(const AttrFilter &attr_filter) const
Compute the likelihood of the given filter predicates given by a map from attribute to the respective...
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.
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.
SpnWrapper(SpnWrapper &&)=default
std::unordered_map< ThreadSafePooledString, unsigned > attribute_to_id_
a map from attribute to spn internal id
const std::unordered_map< ThreadSafePooledString, unsigned > & get_attribute_to_id() const
Get the reference to the attribute to spn internal id mapping.
Filter translate_filter(const AttrFilter &attr_filter) const
float upper_bound(const Filter &filter) const
Compute the upper bound probability for continuous domains.
SpnWrapper(Spn spn, std::unordered_map< ThreadSafePooledString, unsigned > attribute_to_id)
void insert_row(Eigen::VectorXf &row)
Insert the given row into the SPN.
Tree structure for Sum Product Networks.
float lower_bound(const Filter &filter) const
Compute the lower bound probability for continuous domains.
void update_row(Eigen::VectorXf &old_row, Eigen::VectorXf &updated_row)
Update the SPN with the given row.
float likelihood(const Filter &filter) const
Compute the likelihood of the given filter predicates given by a map from attribute to the respective...
void delete_row(Eigen::VectorXf &row)
Delete the given row from the SPN.
float upper_bound(const Filter &filter) const
Compute the upper bound probability for continuous domains.
std::size_t estimate_number_distinct_values(unsigned attribute_id) const
Estimate the number of distinct values of the given attribute.
float expectation(unsigned attribute_id, const Filter &filter) const
Compute the expectation of the given attribute.
std::size_t num_rows() const
returns the number of rows in the SPN.
void insert_row(Eigen::VectorXf &row)
Insert the given row into the SPN.
std::size_t memory_usage() const