From bd30bef1a361488a9ef7a2e0ec223220ace56bb8 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 4 Jan 2025 05:16:21 -0500 Subject: [PATCH] remove constructors that need parents --- gtsam/discrete/TableDistribution.cpp | 24 ++++++-------- gtsam/discrete/TableDistribution.h | 48 ++-------------------------- 2 files changed, 12 insertions(+), 60 deletions(-) diff --git a/gtsam/discrete/TableDistribution.cpp b/gtsam/discrete/TableDistribution.cpp index 5862c64be..b74acbbd1 100644 --- a/gtsam/discrete/TableDistribution.cpp +++ b/gtsam/discrete/TableDistribution.cpp @@ -38,16 +38,15 @@ using std::vector; namespace gtsam { /* ************************************************************************** */ -TableDistribution::TableDistribution(const size_t nrFrontals, - const TableFactor& f) - : BaseConditional(nrFrontals, DecisionTreeFactor(f.discreteKeys(), ADT())), - table_(f / (*f.sum(nrFrontals))) {} +TableDistribution::TableDistribution(const TableFactor& f) + : BaseConditional(f.keys().size(), + DecisionTreeFactor(f.discreteKeys(), ADT())), + table_(f / (*f.sum(f.keys().size()))) {} /* ************************************************************************** */ TableDistribution::TableDistribution( - size_t nrFrontals, const DiscreteKeys& keys, - const Eigen::SparseVector& potentials) - : BaseConditional(nrFrontals, keys, DecisionTreeFactor(keys, ADT())), + const DiscreteKeys& keys, const Eigen::SparseVector& potentials) + : BaseConditional(keys.size(), keys, DecisionTreeFactor(keys, ADT())), table_(TableFactor(keys, potentials)) {} /* ************************************************************************** */ @@ -66,11 +65,6 @@ TableDistribution::TableDistribution(const TableFactor& joint, keys_.insert(keys_.end(), orderedKeys.begin(), orderedKeys.end()); } -/* ************************************************************************** */ -TableDistribution::TableDistribution(const Signature& signature) - : BaseConditional(1, DecisionTreeFactor(DiscreteKeys{{1, 1}}, ADT(1))), - table_(TableFactor(signature.discreteKeys(), signature.cpt())) {} - /* ************************************************************************** */ void TableDistribution::print(const string& s, const KeyFormatter& formatter) const { @@ -107,7 +101,7 @@ DiscreteConditional::shared_ptr TableDistribution::max( const Ordering& keys) const { auto m = *table_.max(keys); - return std::make_shared(m.discreteKeys().size(), m); + return std::make_shared(m); } /* ****************************************************************************/ @@ -124,8 +118,8 @@ DiscreteConditional::shared_ptr TableDistribution::prune( size_t maxNrAssignments) const { TableFactor pruned = table_.prune(maxNrAssignments); - return std::make_shared( - this->nrFrontals(), this->discreteKeys(), pruned.sparseTable()); + return std::make_shared(this->discreteKeys(), + pruned.sparseTable()); } } // namespace gtsam diff --git a/gtsam/discrete/TableDistribution.h b/gtsam/discrete/TableDistribution.h index 8fb1cb60a..a1c463e0e 100644 --- a/gtsam/discrete/TableDistribution.h +++ b/gtsam/discrete/TableDistribution.h @@ -58,58 +58,16 @@ class GTSAM_EXPORT TableDistribution : public DiscreteConditional { /// Default constructor needed for serialization. TableDistribution() {} - /// Construct from factor, taking the first `nFrontals` keys as frontals. - TableDistribution(size_t nFrontals, const TableFactor& f); + /// Construct from TableFactor. + TableDistribution(const TableFactor& f); /** * Construct from DiscreteKeys and SparseVector, taking the first * `nFrontals` keys as frontals, in the order given. */ - TableDistribution(size_t nFrontals, const DiscreteKeys& keys, + TableDistribution(const DiscreteKeys& keys, const Eigen::SparseVector& potentials); - /** Construct from signature */ - explicit TableDistribution(const Signature& signature); - - /** - * Construct from key, parents, and a Signature::Table specifying the - * conditional probability table (CPT) in 00 01 10 11 order. For - * three-valued, it would be 00 01 02 10 11 12 20 21 22, etc.... - * - * Example: TableDistribution P(D, {B,E}, table); - */ - TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents, - const Signature::Table& table) - : TableDistribution(Signature(key, parents, table)) {} - - /** - * Construct from key, parents, and a vector specifying the - * conditional probability table (CPT) in 00 01 10 11 order. For - * three-valued, it would be 00 01 02 10 11 12 20 21 22, etc.... - * - * Example: TableDistribution P(D, {B,E}, table); - */ - TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents, - const std::vector& table) - : TableDistribution(1, TableFactor(DiscreteKeys{key} & parents, table)) {} - - /** - * Construct from key, parents, and a string specifying the conditional - * probability table (CPT) in 00 01 10 11 order. For three-valued, it would - * be 00 01 02 10 11 12 20 21 22, etc.... - * - * The string is parsed into a Signature::Table. - * - * Example: TableDistribution P(D, {B,E}, "9/1 2/8 3/7 1/9"); - */ - TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents, - const std::string& spec) - : TableDistribution(Signature(key, parents, spec)) {} - - /// No-parent specialization; can also use DiscreteDistribution. - TableDistribution(const DiscreteKey& key, const std::string& spec) - : TableDistribution(Signature(key, {}, spec)) {} - /** * @brief construct P(X|Y) = f(X,Y)/f(Y) from f(X,Y) and f(Y) * Assumes but *does not check* that f(Y)=sum_X f(X,Y).