-
Notifications
You must be signed in to change notification settings - Fork 792
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
Discrete Elimination Refactor #1919
Conversation
This reverts commit 306a3ba.
gtsam/discrete/DiscreteFactor.h
Outdated
virtual DecisionTreeFactor operator*(const DecisionTreeFactor&) const = 0; | ||
/// Multiply in a DiscreteFactor and return the result as | ||
/// DiscreteFactor | ||
virtual DiscreteFactor::shared_ptr operator*( |
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.
Should this be a DiscreteFactor::shared_ptr
or a DiscreteFactor&
(aka a reference?)
Maybe only push when you want a review? |
The second push was because of your comments on the multiply PR. Making your life easier. |
@dellaert this is ready for review |
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.
Awesomesauce. Some minor comments
@@ -45,7 +45,8 @@ template class GTSAM_EXPORT | |||
/* ************************************************************************** */ | |||
DiscreteConditional::DiscreteConditional(const size_t nrFrontals, |
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.
Can this now be a DiscreetFactor& ?
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.
Yes it can!
@@ -45,7 +45,8 @@ template class GTSAM_EXPORT | |||
/* ************************************************************************** */ | |||
DiscreteConditional::DiscreteConditional(const size_t nrFrontals, | |||
const DecisionTreeFactor& f) | |||
: BaseFactor(f / (*f.sum(nrFrontals))), BaseConditional(nrFrontals) {} | |||
: BaseFactor(f / f.sum(nrFrontals)->toDecisionTreeFactor()), |
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.
Is that a no-op if already a DecisionTreeFactor?
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.
It's not actually. In the simple case where there are no parents, we'll get a DecisionTreeFactor
with a single value as a DiscreteFactor::shared_ptr
. We can cast it explicitly, but I used toDecisionTreeFactor
to do it instead as a shortcut.
/* ************************************************************************ */ | ||
DiscreteFactor::shared_ptr DecisionTreeFactor::operator/( | ||
const DiscreteFactor::shared_ptr& f) const { | ||
if (auto tf = std::dynamic_pointer_cast<TableFactor>(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.
Add comments
@@ -111,15 +111,15 @@ TEST(DecisionTreeFactor, sum_max) { | |||
DecisionTreeFactor f1(v0 & v1, "1 2 3 4 5 6"); | |||
|
|||
DecisionTreeFactor expected(v1, "9 12"); | |||
DecisionTreeFactor::shared_ptr actual = f1.sum(1); | |||
auto actual = std::dynamic_pointer_cast<DecisionTreeFactor>(f1.sum(1)); | |||
CHECK(assert_equal(expected, *actual, 1e-5)); |
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.
Add CHECK(actual);
CHECK(assert_equal(expected, *actual, 1e-5)); | ||
|
||
DecisionTreeFactor expected2(v1, "5 6"); | ||
DecisionTreeFactor::shared_ptr actual2 = f1.max(1); | ||
auto actual2 = std::dynamic_pointer_cast<DecisionTreeFactor>(f1.max(1)); |
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.
same
CHECK(assert_equal(expected2, *actual2)); | ||
|
||
DecisionTreeFactor f2(v1 & v0, "1 2 3 4 5 6"); | ||
DecisionTreeFactor::shared_ptr actual22 = f2.sum(1); | ||
auto actual22 = std::dynamic_pointer_cast<DecisionTreeFactor>(f2.sum(1)); |
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.
same
@@ -303,15 +305,15 @@ TEST(TableFactor, sum_max) { | |||
TableFactor f1(v0 & v1, "1 2 3 4 5 6"); | |||
|
|||
TableFactor expected(v1, "9 12"); | |||
TableFactor::shared_ptr actual = f1.sum(1); | |||
auto actual = std::dynamic_pointer_cast<TableFactor>(f1.sum(1)); |
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.
Check all casts !
Refactor discrete elimination so it is agnostic to the underlying derived type of the
DiscreteFactor
.