diff --git a/gtsam/discrete/TableFactor.cpp b/gtsam/discrete/TableFactor.cpp index f4e023a4d..2be8e077d 100644 --- a/gtsam/discrete/TableFactor.cpp +++ b/gtsam/discrete/TableFactor.cpp @@ -56,45 +56,9 @@ TableFactor::TableFactor(const DiscreteKeys& dkeys, sort(sorted_dkeys_.begin(), sorted_dkeys_.end()); } -/* ************************************************************************ */ -TableFactor::TableFactor(const DiscreteKeys& dkeys, - const DecisionTree& dtree) - : TableFactor(dkeys, DecisionTreeFactor(dkeys, dtree)) {} - -/** - * @brief Compute the correct ordering of the leaves in the decision tree. - * - * This is done by first taking all the values which have modulo 0 value with - * the cardinality of the innermost key `n`, and we go up to modulo n. - * - * @param dt The DecisionTree - * @return std::vector - */ -std::vector ComputeLeafOrdering(const DiscreteKeys& dkeys, - const DecisionTreeFactor& dt) { - std::vector probs = dt.probabilities(); - std::vector ordered; - - size_t n = dkeys[0].second; - - for (size_t k = 0; k < n; ++k) { - for (size_t idx = 0; idx < probs.size(); ++idx) { - if (idx % n == k) { - ordered.push_back(probs[idx]); - } - } - } - return ordered; -} - -/* ************************************************************************ */ -TableFactor::TableFactor(const DiscreteKeys& dkeys, - const DecisionTreeFactor& dtf) - : TableFactor(dkeys, ComputeLeafOrdering(dkeys, dtf)) {} - /* ************************************************************************ */ TableFactor::TableFactor(const DiscreteConditional& c) - : TableFactor(c.discreteKeys(), c) {} + : TableFactor(c.discreteKeys(), c.probabilities()) {} /* ************************************************************************ */ Eigen::SparseVector TableFactor::Convert( diff --git a/gtsam/discrete/TableFactor.h b/gtsam/discrete/TableFactor.h index 828e794e6..d5decd1a1 100644 --- a/gtsam/discrete/TableFactor.h +++ b/gtsam/discrete/TableFactor.h @@ -144,12 +144,6 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor { TableFactor(const DiscreteKey& key, const std::vector& row) : TableFactor(DiscreteKeys{key}, row) {} - /// Constructor from DecisionTreeFactor - TableFactor(const DiscreteKeys& keys, const DecisionTreeFactor& dtf); - - /// Constructor from DecisionTree/AlgebraicDecisionTree - TableFactor(const DiscreteKeys& keys, const DecisionTree& dtree); - /** Construct from a DiscreteConditional type */ explicit TableFactor(const DiscreteConditional& c); @@ -181,7 +175,7 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor { /// Calculate error for DiscreteValues `x`, is -log(probability). double error(const DiscreteValues& values) const; - /// multiply two TableFactors + /// multiple two TableFactors TableFactor operator*(const TableFactor& f) const { return apply(f, Ring::mul); }; diff --git a/gtsam/discrete/tests/testTableFactor.cpp b/gtsam/discrete/tests/testTableFactor.cpp index 0f7d7a615..7ad0ac1ff 100644 --- a/gtsam/discrete/tests/testTableFactor.cpp +++ b/gtsam/discrete/tests/testTableFactor.cpp @@ -132,16 +132,6 @@ TEST(TableFactor, constructors) { // Manually constructed via inspection and comparison to DecisionTreeFactor TableFactor expected(X & Y, "0.5 0.4 0.2 0.5 0.6 0.8"); EXPECT(assert_equal(expected, f4)); - - // Test for 9=3x3 values. - DiscreteKey V(0, 3), W(1, 3); - DiscreteConditional conditional5(V | W = "1/2/3 5/6/7 9/10/11"); - TableFactor f5(conditional5); - // GTSAM_PRINT(f5); - TableFactor expected_f5( - X & Y, - "0.166667 0.277778 0.3 0.333333 0.333333 0.333333 0.5 0.388889 0.366667"); - EXPECT(assert_equal(expected_f5, f5, 1e-6)); } /* ************************************************************************* */