Deprecated solve

release/4.3a0
Frank Dellaert 2022-01-21 13:09:04 -05:00
parent 34a3b022d9
commit fcdb5b43c1
3 changed files with 32 additions and 3 deletions

View File

@ -49,4 +49,21 @@ std::vector<double> DiscreteDistribution::pmf() const {
return array;
}
/* ************************************************************************** */
size_t DiscreteDistribution::argmax() const {
size_t maxValue = 0;
double maxP = 0;
assert(nrFrontals() == 1);
Key j = firstFrontalKey();
for (size_t value = 0; value < cardinality(j); value++) {
double pValueS = (*this)(value);
// Update MPE solution if better
if (pValueS > maxP) {
maxP = pValueS;
maxValue = value;
}
}
return maxValue;
}
} // namespace gtsam

View File

@ -91,10 +91,10 @@ class GTSAM_EXPORT DiscreteDistribution : public DiscreteConditional {
std::vector<double> pmf() const;
/**
* solve a conditional
* @return MPE value of the child (1 frontal variable).
* @brief Return assignment that maximizes distribution.
* @return Optimal assignment (1 frontal variable).
*/
size_t solve() const { return Base::solve({}); }
size_t argmax() const;
/**
* sample
@ -103,6 +103,12 @@ class GTSAM_EXPORT DiscreteDistribution : public DiscreteConditional {
size_t sample() const { return Base::sample(); }
/// @}
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
/// @name Deprecated functionality
/// @{
size_t GTSAM_DEPRECATED solve() const { return Base::solve({}); }
/// @}
#endif
};
// DiscreteDistribution

View File

@ -74,6 +74,12 @@ TEST(DiscreteDistribution, sample) {
prior.sample();
}
/* ************************************************************************* */
TEST(DiscreteDistribution, argmax) {
DiscreteDistribution prior(X % "2/3");
EXPECT_LONGS_EQUAL(prior.argmax(), 1);
}
/* ************************************************************************* */
int main() {
TestResult tr;