discreteKeys method

release/4.3a0
Frank Dellaert 2022-01-22 11:06:52 -05:00
parent b875914f93
commit eb4309d264
2 changed files with 16 additions and 1 deletions

View File

@ -67,7 +67,7 @@ namespace gtsam {
void DecisionTreeFactor::print(const string& s, void DecisionTreeFactor::print(const string& s,
const KeyFormatter& formatter) const { const KeyFormatter& formatter) const {
cout << s; cout << s;
ADT::print("Potentials:",formatter); ADT::print("", formatter);
} }
/* ************************************************************************* */ /* ************************************************************************* */
@ -163,6 +163,18 @@ namespace gtsam {
return result; return result;
} }
/* ************************************************************************* */
DiscreteKeys DecisionTreeFactor::discreteKeys() const {
DiscreteKeys result;
for (auto&& key : keys()) {
DiscreteKey dkey(key, cardinality(key));
if (std::find(result.begin(), result.end(), dkey) == result.end()) {
result.push_back(dkey);
}
}
return result;
}
/* ************************************************************************* */ /* ************************************************************************* */
static std::string valueFormatter(const double& v) { static std::string valueFormatter(const double& v) {
return (boost::format("%4.2g") % v).str(); return (boost::format("%4.2g") % v).str();

View File

@ -183,6 +183,9 @@ namespace gtsam {
/// Enumerate all values into a map from values to double. /// Enumerate all values into a map from values to double.
std::vector<std::pair<DiscreteValues, double>> enumerate() const; std::vector<std::pair<DiscreteValues, double>> enumerate() const;
/// Return all the discrete keys associated with this factor.
DiscreteKeys discreteKeys() const;
/// @} /// @}
/// @name Wrapper support /// @name Wrapper support
/// @{ /// @{