diff --git a/gtsam/discrete/DiscreteBayesNet.cpp b/gtsam/discrete/DiscreteBayesNet.cpp index f00eca60c..c1aa18828 100644 --- a/gtsam/discrete/DiscreteBayesNet.cpp +++ b/gtsam/discrete/DiscreteBayesNet.cpp @@ -65,10 +65,6 @@ DiscreteValues DiscreteBayesNet::sample(DiscreteValues result) const { return result; } -DiscreteValues DiscreteBayesNet::mode() const { - return DiscreteFactorGraph(*this).optimize(); -} - /* *********************************************************************** */ std::string DiscreteBayesNet::markdown( const KeyFormatter& keyFormatter, diff --git a/gtsam/discrete/DiscreteBayesNet.h b/gtsam/discrete/DiscreteBayesNet.h index 3bcdcfe84..a5a4621aa 100644 --- a/gtsam/discrete/DiscreteBayesNet.h +++ b/gtsam/discrete/DiscreteBayesNet.h @@ -124,14 +124,6 @@ class GTSAM_EXPORT DiscreteBayesNet: public BayesNet { */ DiscreteValues sample(DiscreteValues given) const; - /** - * @brief Compute the discrete assignment which gives the highest - * probability for the DiscreteBayesNet. - * - * @return DiscreteValues - */ - DiscreteValues mode() const; - ///@} /// @name Wrapper support /// @{ diff --git a/gtsam/discrete/discrete.i b/gtsam/discrete/discrete.i index 43d2559d9..0f34840bf 100644 --- a/gtsam/discrete/discrete.i +++ b/gtsam/discrete/discrete.i @@ -193,7 +193,6 @@ class DiscreteBayesNet { gtsam::DiscreteValues sample() const; gtsam::DiscreteValues sample(gtsam::DiscreteValues given) const; - gtsam::DiscreteValues mode() const; string dot( const gtsam::KeyFormatter& keyFormatter = gtsam::DefaultKeyFormatter, diff --git a/gtsam/discrete/tests/testDiscreteBayesNet.cpp b/gtsam/discrete/tests/testDiscreteBayesNet.cpp index b87e1c67a..49a360cbb 100644 --- a/gtsam/discrete/tests/testDiscreteBayesNet.cpp +++ b/gtsam/discrete/tests/testDiscreteBayesNet.cpp @@ -120,55 +120,6 @@ TEST(DiscreteBayesNet, Asia) { EXPECT(assert_equal(expectedSample, actualSample)); } -/* ************************************************************************* */ -TEST(DiscreteBayesNet, Mode) { - DiscreteBayesNet asia; - - // We need to order the Bayes net in bottom-up fashion - asia.add(XRay | Either = "95/5 2/98"); - asia.add((Dyspnea | Either, Bronchitis) = "9/1 2/8 3/7 1/9"); - - asia.add((Either | Tuberculosis, LungCancer) = "F T T T"); - - asia.add(Tuberculosis | Asia = "99/1 95/5"); - asia.add(LungCancer | Smoking = "99/1 90/10"); - asia.add(Bronchitis | Smoking = "70/30 40/60"); - - asia.add(Asia, "99/1"); - asia.add(Smoking % "50/50"); // Signature version - - DiscreteValues actual = asia.mode(); - // NOTE: Examined the DBN and found the optimal assignment. - DiscreteValues expected{ - {Asia.first, 0}, {Smoking.first, 0}, {Tuberculosis.first, 0}, - {LungCancer.first, 0}, {Bronchitis.first, 0}, {Either.first, 0}, - {XRay.first, 0}, {Dyspnea.first, 0}, - }; - EXPECT(assert_equal(expected, actual)); -} - -/* ************************************************************************* */ -TEST(DiscreteBayesNet, ModeEdgeCase) { - // Declare 2 keys - DiscreteKey A(0, 2), B(1, 2); - - // Create Bayes net such that marginal on A is bigger for 0 than 1, but the - // MPE does not have A=0. - DiscreteBayesNet bayesNet; - bayesNet.add(B | A = "1/1 1/2"); - bayesNet.add(A % "10/9"); - - // Which we verify using max-product: - DiscreteFactorGraph graph(bayesNet); - // The expected MPE is A=1, B=1 - DiscreteValues expectedMPE = graph.optimize(); - - auto actualMPE = bayesNet.mode(); - - EXPECT(assert_equal(expectedMPE, actualMPE)); - EXPECT_DOUBLES_EQUAL(0.315789, bayesNet(expectedMPE), 1e-5); // regression -} - /* ************************************************************************* */ TEST(DiscreteBayesNet, Sugar) { DiscreteKey T(0, 2), L(1, 2), E(2, 2), C(8, 3), S(7, 2);