From 5f83464f0d4dafd0c1c780852ebfdd47a55e4322 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Sat, 22 Jul 2023 01:09:55 -0400 Subject: [PATCH] use existing cardinalities --- gtsam/discrete/DecisionTreeFactor.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/gtsam/discrete/DecisionTreeFactor.cpp b/gtsam/discrete/DecisionTreeFactor.cpp index 19cc8e230..7ba4c9011 100644 --- a/gtsam/discrete/DecisionTreeFactor.cpp +++ b/gtsam/discrete/DecisionTreeFactor.cpp @@ -196,18 +196,12 @@ namespace gtsam { /* ************************************************************************ */ std::vector DecisionTreeFactor::probabilities() const { - std::vector probs; - - // Get all the key cardinalities - std::map cardins; - for (auto [key, cardinality] : discreteKeys()) { - cardins[key] = cardinality; - } // Set of all keys std::set allKeys(keys().begin(), keys().end()); + std::vector probs; + // Go through the tree - std::vector ys; this->apply([&](const Assignment a, double p) { // Get all the keys in the current assignment std::set assignment_keys; @@ -224,7 +218,7 @@ namespace gtsam { // Compute the total number of assignments in the (pruned) subtree size_t nrAssignments = 1; for (auto&& k : diff) { - nrAssignments *= cardins.at(k); + nrAssignments *= cardinalities_.at(k); } probs.insert(probs.end(), nrAssignments, p); return p;