Skip to content
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

Linear HybridBayesNet optimization #1270

Merged
merged 7 commits into from
Aug 22, 2022

Conversation

xsj01
Copy link
Contributor

@xsj01 xsj01 commented Aug 15, 2022

This PR adds the following:

  1. optimize() in HybridBayesNet. It finds the argmax by back-substitution.
  2. HybridValues class to store the optimization results.

@xsj01 xsj01 requested a review from varunagrawal August 15, 2022 01:16
@xsj01 xsj01 marked this pull request as ready for review August 15, 2022 01:19
@varunagrawal
Copy link
Collaborator

@xsj01 can you please run a formatter on your changed code? That should make reading and reviewing it easier.

gtsam/hybrid/HybridLookupDAG.cpp Outdated Show resolved Hide resolved
gtsam/hybrid/HybridLookupDAG.cpp Outdated Show resolved Hide resolved
* is typically used to store the variables of a HybridGaussianFactorGraph.
* Optimizing a HybridGaussianBayesNet returns this class.
*/
class GTSAM_EXPORT HybridValues {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for thoughts: I always wondered can we just get rid of DiscreteKey and stuff, and store the cardinality of variables somewhere else, like along with the value itself.

DiscreteValues discrete;

// VectorValue stored the continuous components of the HybridValues.
VectorValues continuous;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we name the class HybridVectorValues? This class is linear only. (comment only)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can change VectorValues to Values?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more like a design question: Is this limited to linear hybrid systems? If so we should name it Gaussian.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will extend that for nonlinear hybrid later, but currently it's only for linear hybrid system.
If we rename this to HybridVectorValues, then we will also need HybridValues for nonlinear hybrid system later. Is it necessary to have both HybridVectorValues and HybridValues?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the spirit for linear and nonlinear though. because VectorValues and values are different we should probably have the same

gtsam/hybrid/hybrid.i Show resolved Hide resolved
Copy link
Collaborator

@ProfFan ProfFan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
tested locally, seems to be working

@ProfFan
Copy link
Collaborator

ProfFan commented Aug 22, 2022

@xsj01

@xsj01 xsj01 merged commit ef066a0 into hybrid/hybrid-factor-graph Aug 22, 2022
@varunagrawal
Copy link
Collaborator

I think this was merged too soon. I didn't get to take a good look at it. :(
Also, @xsj01 please delete branches after merging.

@varunagrawal varunagrawal deleted the hybrid/hybrid-optimize branch August 22, 2022 15:50
@ProfFan
Copy link
Collaborator

ProfFan commented Aug 22, 2022

We can change this later, btw @xsj01 there is also optimize for HybridBayesTree, which is harder :)

Copy link
Collaborator

@varunagrawal varunagrawal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts and questions. Unfortunately this PR was merged too soon. 😞

HybridLookupTable(HybridConditional& conditional) : Base(conditional){};

/**
* @brief Calculate assignment for frontal variables that maximizes value.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xsj01 What would be the frontal variables here? They should all be continuous variables since we eliminate those first, so then this doesn't make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems the HybridLookupTable is not necessary. Just had some discussions with Fan, I will submit a new PR to fix this.

* is typically used to store the variables of a HybridGaussianFactorGraph.
* Optimizing a HybridGaussianBayesNet returns this class.
*/
class GTSAM_EXPORT HybridValues {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the use of this class. Can't we simply have optimize run MPE on the discrete tree and then run a regular optimization on the continuous values corresponding to the assignment? That way we can just return a pair<Values, DiscreteValues>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's also an option. But I feel like the api is not very user friendly while accessing/assigning values. We can talk about it in our meeting.


/** A DAG made from hybrid lookup tables, as defined above. Similar to
* DiscreteLookupDAG */
class GTSAM_EXPORT HybridLookupDAG : public BayesNet<HybridLookupTable> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs for this class are severely lacking. @xsj01 you have to be better than just copy-pasting the same docstrings, since now the motivation for this class is lost.

@varunagrawal
Copy link
Collaborator

We can change this later, btw @xsj01 there is also optimize for HybridBayesTree, which is harder :)

Not quite the point. There has to be coherence so that everyone working on hybrid estimation understands the overall design and there is less wasted effort. Going back and forth won't solve issues with design.

I had requested a PR from @xsj01 so I could see his work and understand his requirements, with the hope that it would lead to better overall structure.

@varunagrawal
Copy link
Collaborator

Also the tests don't have any docs. :(

@varunagrawal
Copy link
Collaborator

@xsj01 can you please respond with a plan to tackle these issues?

@xsj01
Copy link
Contributor Author

xsj01 commented Aug 24, 2022

Sorry for the delay @varunagrawal, I will address the comments. Just wondering shall we revert this PR and merge it later?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants