Skip to content

Conversation

p-zach
Copy link
Member

@p-zach p-zach commented May 1, 2025

New docs for hybrid folder. There were a lot of classes in here that had many, many functions that were not yet wrapped. Frank also exposed AlgebraicDecisionTreeKey for methods like errorTree().

Finished Notebooks

  • HybridSmoother
  • HybridValues
  • HybridBayesTree
  • HybridFactor
  • HybridBayesNet
  • HybridConditional
  • HybridEliminationTree
  • HybridFactorGraph
  • HybridGaussianConditional
  • HybridGaussianFactor
  • HybridGaussianFactorGraph
  • HybridGaussianISAM
  • HybridGaussianProductFactor
  • HybridJunctionTree
  • HybridNonlinearFactor
  • HybridNonlinearFactorGraph
  • HybridNonlinearISAM

@dellaert dellaert marked this pull request as ready for review May 26, 2025 13:44
Copy link
Member

@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.

Thanks @p-zach !!! I fixed all remaining wrapper issues

@dellaert
Copy link
Member

@varunagrawal FYI

Copy link
Contributor

@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.

Okay this PR is a very nice effort, but I am not comfortable with the wrapping for 2 reasons:

  1. Lack of tests: whatever I wrapped, I extensively unit tested, and my own work allowed for integration testing.
  2. Verification with the Matlab wrapper. The matlab wrapper is more finicky than the python wrapper since it cares a whole lot more about return types and other smaller details. I don't see if this was checked (CI doesn't do it).

Moreover, I want to land other hybrid related PRs first (such as DCSAM) and include a new class called Key[Algebraic]DecisionTree which specializes AlgebraicDecisionTree<Key> to make its use much easier and cleaner. It's a low priority item since it simplifies the API but is a lot of effort for a single developer (aka me).

I am not selecting Request changes (which would be the right way to go), but I DO NOT recommend merging this yet.

uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 8
shell: bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please document what's going on here? It's much more complicated than what we had before and is not quite obvious.


/* ************************************************************************ */
double HybridConditional::error(const HybridValues &values) const {
double HybridConditional::error(const HybridValues &hybridValues) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is a bit superficial since HybridConditional::error only ever accepts HybridValues.

template <>
struct traits<HybridFactor> : public Testable<HybridFactor> {};

// For wrapper:
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason I haven't wrapped a lot of stuff in hybrid is primarily because of this class, and also because I want to add a new class called KeyDecisionTree which specializes the template AlgebraicDecisionTree.

This would have many benefits since we wouldn't have to always pass in keyFormatter arguments, and wrapping would be a cinch, but it is a big PR which is lower priority than some others (such as DCSAM).

DiscreteKeys newFactorDiscreteKeys; // For the new, restricted factor

// Iterate over the discrete keys of the current factor
for (const DiscreteKey& factor_dk_pair : currentFactorDiscreteKeys) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: The iterate can simply be called discreteKey.

const Key& key = factor_dk_pair.first;

// Check if this key is specified in the assignment
auto assignment_it = assignment.find(key);
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be combined with the below line

if (assignment.find(key) != assignment.end()) {

and since assignment is a std::map, you can just do assignment.at(key) to get the assigned index. You shouldn't need the iterator assignment_it.

const std::vector<std::pair<gtsam::Vector, double>>& parameters);

// Standard API
gtsam::GaussianConditional::shared_ptr choose(
Copy link
Contributor

Choose a reason for hiding this comment

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

shared_ptr has specific wrapper syntax: gtsam::GaussianConditional*.

Also did you test the matlab wrapper?

const gtsam::VectorValues& frontals) const;
double logProbability(const gtsam::HybridValues& values) const;
double evaluate(const gtsam::HybridValues& values) const;
// double operator()(const gtsam::HybridValues &values) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should just work right?

}

/* ************************************************************************* */
TEST(HybridBayesTree, EliminateMultifrontal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test doesn't seem to be verifying correctness. Seems more like a test for dot printing.


// Check discrete keys now empty
DiscreteKeys expected_dk1;
GTSAM_PRINT(restricted->discreteKeys());
Copy link
Contributor

Choose a reason for hiding this comment

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

Please kill prints.

/** private helper method for saving the Tree to a text file in GraphViz format */
void dot(std::ostream &s, sharedClique clique, const KeyFormatter& keyFormatter,
int parentnum = 0) const;
size_t parentnum = 0) const;
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be problematic on different compilers due to the platform dependent size_t definitions.

Copy link
Contributor

@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.

Please verify the matlab wrapper compiles and update the restrict method.

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