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

Simpler HybridGaussianFoo constructors #1848

Merged
merged 23 commits into from
Sep 27, 2024
Merged

Conversation

dellaert
Copy link
Member

  • Remove superfluous arguments
  • Add helper structs and private constructor to ensure proper initialization
  • Added input checking on factors and conditional keys but removed it since
    • expensive
    • it was not checked before
  • simplified all call sites -> no code is the best code

@dellaert
Copy link
Member Author

Updating to also fix HybridNonlinearFactor

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.

Partial review. Will do more later tonight.

gtsam/hybrid/HybridGaussianConditional.cpp Outdated Show resolved Hide resolved
const DiscreteKey &discreteKey,
const std::vector<GaussianFactor::shared_ptr> &factors)
: discreteKeys({discreteKey}) {
// Extract continuous keys from the first non-null factor
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll do a full review in a bit, but I am wondering about the extra compute happening here when we could have just given the keys directly.

Currently I am struggling with the hybrid state estimator being far too slow and having too many hypotheses. Pruning is working but the blow up is still immense, hence my concerns here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ironically, it's a bit faster.

Copy link
Member Author

Choose a reason for hiding this comment

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

Esp, GaussianConditional, which did two tree traversals, now only does one.

@dellaert
Copy link
Member Author

Partial review. Will do more later tonight.

That's fine, I'm moving some more stuff to cpp files now rather than cluttering the headers.

@dellaert
Copy link
Member Author

Partial review. Will do more later tonight.

That's fine, I'm moving some more stuff to cpp files now rather than cluttering the headers.

OK, done, and cleaned up some missing python test changes.

Copy link
Member Author

@dellaert dellaert left a comment

Choose a reason for hiding this comment

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

Some things I noticed while looking over PR

const ConstructorHelper &helper)
: BaseFactor(discreteParents, helper.pairs),
BaseConditional(helper.frontals.size()),
conditionals_(conditionals),
Copy link
Member Author

Choose a reason for hiding this comment

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

These things are here twice! Once in BaseFactor, and once in conditionals_.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I thought about that too. There was a reason I couldn't get rid of conditionals_, which I think was to do with negLogConstant. I'll think about this again so we can remove it.

gtsam/hybrid/HybridGaussianFactor.cpp Outdated Show resolved Hide resolved
gtsam/hybrid/HybridGaussianFactor.h Outdated Show resolved Hide resolved
gtsam/hybrid/HybridNonlinearFactor.cpp Outdated Show resolved Hide resolved
value = c->negLogConstant();
negLogConstant = std::min(negLogConstant, value);
}
return {std::dynamic_pointer_cast<GaussianFactor>(c), value};
Copy link
Member Author

Choose a reason for hiding this comment

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

Because we store the value, we should never have to call negLogConstant in this file again!
And that’s why we currently need to keep conditionals :-( at least until the hiding is removed.

@dellaert
Copy link
Member Author

@varunagrawal whats up with windows CI?

@varunagrawal
Copy link
Collaborator

I think the boost download link is invalid. It's affecting multiple PRs.

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.

LGTM

The whole ConstructorHelper code seems a bit too convoluted, and not specifying continuous keys feels a bit strange but that may be my not being used to it.
Good thing we have a slew of unit tests. :)

const ConstructorHelper &helper)
: BaseFactor(discreteParents, helper.pairs),
BaseConditional(helper.frontals.size()),
conditionals_(conditionals),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I thought about that too. There was a reason I couldn't get rid of conditionals_, which I think was to do with negLogConstant. I'll think about this again so we can remove it.

gtsam/hybrid/HybridGaussianConditional.cpp Show resolved Hide resolved
gtsam/hybrid/HybridGaussianConditional.cpp Show resolved Hide resolved
gtsam/hybrid/HybridGaussianConditional.h Show resolved Hide resolved
const std::vector<GaussianFactorValuePair> &factorPairs)
: HybridGaussianFactor(ConstructorHelper(discreteKey, factorPairs)) {}

HybridGaussianFactor::HybridGaussianFactor(const DiscreteKeys &discreteKeys,
Copy link
Collaborator

Choose a reason for hiding this comment

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

All three of the above constructors need the divider
/* *******************************************************************************/

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 more for me when I add it.

@dellaert dellaert merged commit 31eade5 into develop Sep 27, 2024
33 checks passed
@dellaert dellaert deleted the feature/simpler_constructors branch September 27, 2024 23:07
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.

2 participants