diff --git a/gtsam/discrete/DecisionTree-inl.h b/gtsam/discrete/DecisionTree-inl.h index b65cc6bcf..156177d03 100644 --- a/gtsam/discrete/DecisionTree-inl.h +++ b/gtsam/discrete/DecisionTree-inl.h @@ -137,7 +137,9 @@ namespace gtsam { // Applying binary operator to two leaves results in a leaf NodePtr apply_g_op_fL(const Leaf& fL, const Binary& op) const override { // fL op gL - NodePtr h(new Leaf(op(fL.constant_, constant_), nrAssignments_)); + // TODO(Varun) nrAssignments setting is not correct. + // Depending on f and g, the nrAssignments can be different. This is a bug! + NodePtr h(new Leaf(op(fL.constant_, constant_), fL.nrAssignments())); return h; } @@ -496,13 +498,11 @@ namespace gtsam { // DecisionTree /****************************************************************************/ template - DecisionTree::DecisionTree() { - } + DecisionTree::DecisionTree() {} template DecisionTree::DecisionTree(const NodePtr& root) : - root_(root) { - } + root_(root) {} /****************************************************************************/ template diff --git a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp index 33fa933d2..6e8621595 100644 --- a/gtsam/discrete/tests/testDiscreteFactorGraph.cpp +++ b/gtsam/discrete/tests/testDiscreteFactorGraph.cpp @@ -356,14 +356,14 @@ size: 2 factor 0: f[ (m0,2), (m1,2), (m2,2), ] Choice(m2) 0 Choice(m1) - 0 0 Leaf [1] 0 + 0 0 Leaf [2] 0 0 1 Choice(m0) 0 1 0 Leaf [1]0.27527634 - 0 1 1 Leaf [1]0.44944733 + 0 1 1 Leaf [1] 0 1 Choice(m1) - 1 0 Leaf [1] 0 + 1 0 Leaf [2] 0 1 1 Choice(m0) - 1 1 0 Leaf [1] 0 + 1 1 0 Leaf [1]0.44944733 1 1 1 Leaf [1]0.27527634 factor 1: f[ (m0,2), (m1,2), (m2,2), (m3,2), ] Choice(m3) @@ -442,7 +442,7 @@ factor 1: f[ (m0,2), (m1,2), (m2,2), (m3,2), ] )"; #endif - DiscreteKeys d0{{M(2), 2}, {M(1), 2}, {M(0), 2}}; + DiscreteKeys d0{{M(0), 2}, {M(1), 2}, {M(2), 2}}; std::vector p0 = {0, 0, 0.17054468, 0.27845056, 0, 0, 0, 0.17054468}; AlgebraicDecisionTree dt(d0, p0); //TODO(Varun) Passing ADT to DiscreteConditional causes nrAssignments to get messed up