-
Notifications
You must be signed in to change notification settings - Fork 782
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
TableFactor and TableDistribution #1953
Conversation
…ableConditional since it provides a clean abstraction
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.
Still have some concerns, and several smaller comments. MAybe we should chat about the joint calculation in particular. I did not expect that to break.
@@ -450,11 +450,18 @@ TEST(HybridBayesNet, UpdateDiscreteConditionals) { | |||
|
|||
DiscreteConditional joint; | |||
for (auto&& conditional : posterior->discreteMarginal()) { | |||
joint = joint * (*conditional); | |||
// The last discrete conditional may be a TableDistribution |
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.
I think this code should still work as is.
@@ -20,6 +20,7 @@ | |||
|
|||
#include <gtsam/discrete/DiscreteFactorGraph.h> | |||
#include <gtsam/discrete/DiscreteKey.h> | |||
#include <gtsam/discrete/TableDistribution.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.
Why? Move to cpp to remove header bloat
@@ -41,6 +42,22 @@ bool HybridBayesTree::equals(const This& other, double tol) const { | |||
return Base::equals(other, tol); | |||
} | |||
|
|||
/* ************************************************************************* */ | |||
DiscreteValues HybridBayesTree::discreteMaxProduct( |
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.
This should be in DiscreteFactorGraph?
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.
This is special behavior leveraging the TableFactor
. I don't think we should mess with DiscreteFactorGraph
wrt this.
gtsam/hybrid/HybridBayesNet.cpp
Outdated
@@ -52,15 +52,24 @@ HybridBayesNet HybridBayesNet::prune(size_t maxNrLeaves) const { | |||
// Multiply into one big conditional. NOTE: possibly quite expensive. | |||
DiscreteConditional joint; | |||
for (auto &&conditional : marginal) { | |||
joint = joint * (*conditional); | |||
// The last discrete conditional may be a TableDistribution |
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.
Why does code no longer work as is?
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.
Must have been from before we refactored discrete multiplication.
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.
Think about how it can still work this way, please? Seems it should be possible. The new code is too complex
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.
So this is not working as is because we enabled multiplication for DiscreteFactor::shared_ptr
so the result is a DiscreteFactor::shared_ptr
which has no concept of frontal variables.
We can either convert this to DiscreteFactor
s and then convert to a DiscreteConditional
at the end, or use a TableDistribution
as the type for joint
.
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.
Just seeing this comment. This will work with the fix we discussed, right? Noticed the comments is older than that...
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.
I am starting to wonder if this has been a distraction. The previous HybridBayesNet::TableProduct
method worked great for us.
NOTE: I had to override |
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.
LGTM!
I’ll let you merge |
Use the
TableFactor
for discrete elimination and use a newTableDistribution
which maintains an underlying representation of the distribution using the sameSparseVector
mechanism.