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

Nonlinear Hybrid #1263

Merged
merged 42 commits into from
Aug 21, 2022
Merged

Nonlinear Hybrid #1263

merged 42 commits into from
Aug 21, 2022

Conversation

varunagrawal
Copy link
Collaborator

Add Nonlinear Hybrid Factor Graph machinery.

I moved all the tests for switching systems from our previous scheme to our current scheme and all of them pass!

@varunagrawal varunagrawal self-assigned this Aug 3, 2022
@varunagrawal varunagrawal requested a review from xsj01 August 3, 2022 15:11
Copy link
Contributor

@xsj01 xsj01 left a comment

Choose a reason for hiding this comment

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

LGTM with 2 minor comments

@@ -98,6 +98,12 @@ GaussianMixtureFactor::Sum sumFrontals(
} else if (f->isContinuous()) {
deferredFactors.push_back(
boost::dynamic_pointer_cast<HybridGaussianFactor>(f)->inner());

} else if (f->isDiscrete()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change necessary? I remember at this step there should be no pure discrete factors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah there was one test that was failing without this. You can probably comment it out and find out which one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I remember now. If we have discrete only factors it goes to the next condition and errors out since it is not an orphan. That shouldn't happen right? If we only have discrete factors left, we should just be returning a discrete decision tree and not erroring out.

@ProfFan can you please explain what was your rationale here?

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 because this is a GaussianMixtureFactor, there should not be any discrete factor added to it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a Hybrid Factor Graph method so a discrete factor can be present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not opposing to adding this branching. I am a bit worried that people could start to use this function without thinking about the preconditions when this operation is valid. So I prefer to keep this function as-is, or add some comments in the function Doxygen as a warning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay now this makes sense. In that case, you could have mentioned this before rather than simply saying this is wrong. I am not aware of your mental model and there aren't any comments about the same.

I believe we should still test EliminateHybrid individually. Letting users know what the assumptions are is the right way here, but we should also ensure we handle these kind of edge cases so it makes using the API easier. Can you please comment what would you like me to add as a note in the docstring and I'll add that to this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We will need to talk about the actual situation that will happen when this is called on an arbitrary factor graph. What I can think of is

Function to eliminate variables **under the following assumptions**:
1. When the ordering is fully continuous, and the graph only contains continuous and hybrid factors
2. When the ordering is fully discrete, and the graph only contains discrete factors
Any usage outside of this is incorrect.

\warning This function is not meant to be used with arbitrary hybrid factor graphs. For example, if there exists continuous parents, and one tries to eliminate a discrete variable (as specified in the ordering), the result will be INCORRECT and there will be NO error raised.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How does that sound to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to me.

@varunagrawal
Copy link
Collaborator Author

Folks, there are PRs before this one that need to be reviewed and merged first to make your lives easier. :)

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.

Thanks Varun, looks great sans two minor comments!

nlf->linearize(continuousValues));
linearFG.push_back(hgf);
} else {
linearFG.push_back(factor);
Copy link
Collaborator

Choose a reason for hiding this comment

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

(ignore if not right) So we do allow pushing linear factors to the Hybrid NLFG? Because I remember that there is a LinearContainerFactor, not sure if we want to do the same here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. This is something we can look at again once we update the type hierarchy for hybrid.

// IncrementalHybrid incrementalHybrid;
// HybridGaussianFactorGraph graph1;

// // Add the 3 DC factors, x1-x2, x2-x3, x3-x4
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are uncommented in the next PR, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup

factors.push_back(self.linearizedFactorGraph[1]); // involves m1
factors.push_back(self.linearizedFactorGraph[2]); // involves m2

// TODO(Varun) remove this block since sum is no longer exposed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I kept this since I wanted to highlight this change in the PR

@varunagrawal varunagrawal merged commit 7977f77 into hybrid/pruning Aug 21, 2022
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