update comments
parent
e2cb8c7f44
commit
e30839bac9
|
@ -548,6 +548,9 @@ namespace gtsam {
|
||||||
DiscreteFactor::shared_ptr DecisionTreeFactor::restrict(
|
DiscreteFactor::shared_ptr DecisionTreeFactor::restrict(
|
||||||
const DiscreteValues& assignment) const {
|
const DiscreteValues& assignment) const {
|
||||||
ADT restricted_tree = ADT::restrict(assignment);
|
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();
|
DiscreteKeys restricted_keys = this->discreteKeys();
|
||||||
for (auto&& kv : assignment) {
|
for (auto&& kv : assignment) {
|
||||||
Key key = kv.first;
|
Key key = kv.first;
|
||||||
|
@ -557,6 +560,7 @@ DiscreteFactor::shared_ptr DecisionTreeFactor::restrict(
|
||||||
[key](const DiscreteKey& k) { return k.first == key; }),
|
[key](const DiscreteKey& k) { return k.first == key; }),
|
||||||
restricted_keys.end());
|
restricted_keys.end());
|
||||||
}
|
}
|
||||||
|
// Create the restricted factor with the appropriate keys and tree.
|
||||||
return std::make_shared<DecisionTreeFactor>(restricted_keys, restricted_tree);
|
return std::make_shared<DecisionTreeFactor>(restricted_keys, restricted_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -237,8 +237,11 @@ HybridNonlinearFactorGraph HybridNonlinearFactorGraph::restrict(
|
||||||
result.push_back(hf->restrict(discreteValues));
|
result.push_back(hf->restrict(discreteValues));
|
||||||
} else if (auto df = dynamic_pointer_cast<DiscreteFactor>(f)) {
|
} else if (auto df = dynamic_pointer_cast<DiscreteFactor>(f)) {
|
||||||
auto restricted_df = df->restrict(discreteValues);
|
auto restricted_df = df->restrict(discreteValues);
|
||||||
// In the case where all the discrete values have been selected,
|
// In the case where all the discrete values in the factor
|
||||||
// we ignore the factor since it doesn't add any information
|
// 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) {
|
if (restricted_df->discreteKeys().size() > 0) {
|
||||||
result.push_back(restricted_df);
|
result.push_back(restricted_df);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue