From 35e1e6102fbb77c6e0f586553e9d99c0c21991ca Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Fri, 3 Jan 2025 15:11:07 -0500 Subject: [PATCH] kill operator* method --- gtsam/discrete/TableDistribution.cpp | 38 ---------------------------- gtsam/discrete/TableDistribution.h | 19 +------------- 2 files changed, 1 insertion(+), 56 deletions(-) diff --git a/gtsam/discrete/TableDistribution.cpp b/gtsam/discrete/TableDistribution.cpp index 87eeb1614..3fa66f78c 100644 --- a/gtsam/discrete/TableDistribution.cpp +++ b/gtsam/discrete/TableDistribution.cpp @@ -71,44 +71,6 @@ TableDistribution::TableDistribution(const Signature& signature) : BaseConditional(1, DecisionTreeFactor(DiscreteKeys{{1, 1}}, ADT(1))), table_(TableFactor(signature.discreteKeys(), signature.cpt())) {} -/* ************************************************************************** */ -TableDistribution TableDistribution::operator*( - const TableDistribution& other) const { - // Take union of frontal keys - std::set newFrontals; - for (auto&& key : this->frontals()) newFrontals.insert(key); - for (auto&& key : other.frontals()) newFrontals.insert(key); - - // Check if frontals overlapped - if (nrFrontals() + other.nrFrontals() > newFrontals.size()) - throw std::invalid_argument( - "TableDistribution::operator* called with overlapping frontal " - "keys."); - - // Now, add cardinalities. - DiscreteKeys discreteKeys; - for (auto&& key : frontals()) - discreteKeys.emplace_back(key, cardinality(key)); - for (auto&& key : other.frontals()) - discreteKeys.emplace_back(key, other.cardinality(key)); - - // Sort - std::sort(discreteKeys.begin(), discreteKeys.end()); - - // Add parents to set, to make them unique - std::set parents; - for (auto&& key : this->parents()) - if (!newFrontals.count(key)) parents.emplace(key, cardinality(key)); - for (auto&& key : other.parents()) - if (!newFrontals.count(key)) parents.emplace(key, other.cardinality(key)); - - // Finally, add parents to keys, in order - for (auto&& dk : parents) discreteKeys.push_back(dk); - - TableFactor product = this->table_ * other.table(); - return TableDistribution(newFrontals.size(), product); -} - /* ************************************************************************** */ void TableDistribution::print(const string& s, const KeyFormatter& formatter) const { diff --git a/gtsam/discrete/TableDistribution.h b/gtsam/discrete/TableDistribution.h index ccd768a83..8fb1cb60a 100644 --- a/gtsam/discrete/TableDistribution.h +++ b/gtsam/discrete/TableDistribution.h @@ -124,30 +124,13 @@ class GTSAM_EXPORT TableDistribution : public DiscreteConditional { TableDistribution(const TableFactor& joint, const TableFactor& marginal, const Ordering& orderedKeys); - /** - * @brief Combine two conditionals, yielding a new conditional with the union - * of the frontal keys, ordered by gtsam::Key. - * - * The two conditionals must make a valid Bayes net fragment, i.e., - * the frontal variables cannot overlap, and must be acyclic: - * Example of correct use: - * P(A,B) = P(A|B) * P(B) - * P(A,B|C) = P(A|B) * P(B|C) - * P(A,B,C) = P(A,B|C) * P(C) - * Example of incorrect use: - * P(A|B) * P(A|C) = ? - * P(A|B) * P(B|A) = ? - * We check for overlapping frontals, but do *not* check for cyclic. - */ - TableDistribution operator*(const TableDistribution& other) const; - /// @} /// @name Testable /// @{ /// GTSAM-style print void print( - const std::string& s = "Discrete Conditional: ", + const std::string& s = "Table Distribution: ", const KeyFormatter& formatter = DefaultKeyFormatter) const override; /// GTSAM-style equals