-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix visitWith
for Pruned Tree
#1135
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good find! Please see whether my suggested fix works, as I think that will not touch the complexity.
@@ -20,13 +20,11 @@ | |||
// #define DT_DEBUG_MEMORY | |||
// #define DT_NO_PRUNING | |||
#define DISABLE_DOT | |||
#include <gtsam/discrete/DecisionTree-inl.h> | |||
|
|||
#include <CppUnitLite/TestHarness.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include order convention in gtsam is near -> far. It was already correct except all discrete includes should precede base includes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-format oopsie
gtsam/discrete/DecisionTree-inl.h
Outdated
(*this)(choice->branches()[i]); // recurse! | ||
choices[choice->label()] = i; // Set assignment for label to i | ||
|
||
VisitWith<L, Y> visit(f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems rather heavy handed. Can we not fix the issue simply by removing the choice after the recursive call? That we way we are not copying binary trees all over the place. Worried that the complexity of this method just became O(n^2) rather than O(n).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. The VisitWith
struct is a pretty lightweight datastructure so I figured a functional recursive implementation would be alright. Let me update it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool ! Thanks for finding the bug and fixing it!
Added a unit test demonstrating a bug in partial assignments of
visitWith
and added a fix for it.For example, if we have a pruned tree like below:
if we look at all the assignments that get generated by
visitWith
, we getand we should instead get