update comments

release/4.3a0
Varun Agrawal 2025-04-13 13:00:05 -04:00
parent e2cb8c7f44
commit e30839bac9
2 changed files with 9 additions and 2 deletions

View File

@ -548,6 +548,9 @@ namespace gtsam {
DiscreteFactor::shared_ptr DecisionTreeFactor::restrict(
const DiscreteValues& assignment) const {
ADT restricted_tree = ADT::restrict(assignment);
// Get all the keys that are not restricted by the assignment
// This ensures that the new restricted factor doesn't have keys
// for which the information has been removed.
DiscreteKeys restricted_keys = this->discreteKeys();
for (auto&& kv : assignment) {
Key key = kv.first;
@ -557,6 +560,7 @@ DiscreteFactor::shared_ptr DecisionTreeFactor::restrict(
[key](const DiscreteKey& k) { return k.first == key; }),
restricted_keys.end());
}
// Create the restricted factor with the appropriate keys and tree.
return std::make_shared<DecisionTreeFactor>(restricted_keys, restricted_tree);
}

View File

@ -237,8 +237,11 @@ HybridNonlinearFactorGraph HybridNonlinearFactorGraph::restrict(
result.push_back(hf->restrict(discreteValues));
} else if (auto df = dynamic_pointer_cast<DiscreteFactor>(f)) {
auto restricted_df = df->restrict(discreteValues);
// In the case where all the discrete values have been selected,
// we ignore the factor since it doesn't add any information
// In the case where all the discrete values in the factor
// have been selected, we get a factor without any keys,
// and default values of 0.5.
// Since this factor no longer adds any information, we ignore it to make
// inference faster.
if (restricted_df->discreteKeys().size() > 0) {
result.push_back(restricted_df);
}