-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify that wavemap returns estimates in log odds; add conversion utils
- Loading branch information
1 parent
5b024ab
commit c69798e
Showing
12 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
FAQ | ||
### | ||
|
||
We do not yet have FAQs. | ||
If you have a question that is not yet answered below, feel free to open a `GitHub Issue <https://github.com/ethz-asl/wavemap/issues>`_ or contact us over email. | ||
|
||
If you have a question, please do not hesitate to open a `GitHub Issue <https://github.com/ethz-asl/wavemap/issues>`_. | ||
How do I query if a point in the map is occupied? | ||
================================================= | ||
Please see the :doc:`usage examples <usage_examples>` on :ref:`interpolation <examples-interpolation>` and :ref:`classification <examples-classification>`. | ||
|
||
Does wavemap support (Euclidean) Signed Distance Fields? | ||
======================================================== | ||
Not yet, but we will add this feature in the near future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <wavemap/utils/query/probability_conversions.h> | ||
|
||
#include "wavemap_examples/common.h" | ||
|
||
using namespace wavemap; | ||
int main(int, char**) { | ||
// Declare a floating point value representing the occupancy posterior in log | ||
// odds as queried from the map in one of the previous examples | ||
const FloatingPoint occupancy_log_odds{}; | ||
|
||
// A point is considered unobserved if its occupancy posterior is equal to the | ||
// prior. Wavemap assumes that an unobserved point is equally likely to be | ||
// free or occupied. In other words, the prior occupancy probability is 0.5, | ||
// which corresponds to a log odds value of 0.0. Accounting for numerical | ||
// noise, checking whether a point is unobserved can be done as follows: | ||
constexpr FloatingPoint kUnobservedThreshold = 1e-3; | ||
const bool is_unobserved = | ||
std::abs(occupancy_log_odds) < kUnobservedThreshold; | ||
examples::doSomething(is_unobserved); | ||
|
||
// In case you would like to convert log odds into probabilities, we provide | ||
// the following convenience function: | ||
const FloatingPoint occupancy_probability = | ||
convert::logOddsToProbability(occupancy_log_odds); | ||
examples::doSomething(occupancy_probability); | ||
|
||
// To classify whether a point is estimated to be occupied or free, you need | ||
// to choose a discrimination threshold. A reasonable default threshold is 0.5 | ||
// (probability), which corresponds to 0.0 log odds. | ||
constexpr FloatingPoint kOccupancyThresholdProb = 0.5; | ||
constexpr FloatingPoint kOccupancyThresholdLogOdds = 0.0; | ||
|
||
// NOTE: To taylor the threshold, we recommend running wavemap on a dataset | ||
// that is representative of your application and analyzing the Receiver | ||
// Operating Characteristic curve. | ||
|
||
// Once a threshold has been chosen, you can either classify in log space | ||
{ | ||
const bool is_occupied = kOccupancyThresholdLogOdds < occupancy_log_odds; | ||
const bool is_free = occupancy_log_odds < kOccupancyThresholdLogOdds; | ||
examples::doSomething(is_occupied); | ||
examples::doSomething(is_free); | ||
} | ||
|
||
// Or in probability space | ||
{ | ||
const bool is_occupied = kOccupancyThresholdProb < occupancy_probability; | ||
const bool is_free = occupancy_probability < kOccupancyThresholdProb; | ||
examples::doSomething(is_occupied); | ||
examples::doSomething(is_free); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
libraries/wavemap/include/wavemap/utils/query/probability_conversions.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef WAVEMAP_UTILS_QUERY_PROBABILITY_CONVERSIONS_H_ | ||
#define WAVEMAP_UTILS_QUERY_PROBABILITY_CONVERSIONS_H_ | ||
|
||
#include <limits> | ||
|
||
#include "wavemap/common.h" | ||
|
||
namespace wavemap::convert { | ||
constexpr FloatingPoint kLogOddsNumericalMin = | ||
std::numeric_limits<FloatingPoint>::lowest(); | ||
const FloatingPoint kLogOddsNumericalMax = | ||
std::nextafter(std::log(std::numeric_limits<FloatingPoint>::max()), 0.f); | ||
|
||
constexpr FloatingPoint logOddsToProbability(FloatingPoint log_odds) { | ||
const FloatingPoint odds = std::exp(log_odds); | ||
const FloatingPoint prob = odds / (1.f + odds); | ||
return prob; | ||
} | ||
|
||
constexpr FloatingPoint probabilityToLogOdds(FloatingPoint probability) { | ||
const FloatingPoint odds = probability / (1.f - probability); | ||
return std::log(odds); | ||
} | ||
} // namespace wavemap::convert | ||
|
||
#endif // WAVEMAP_UTILS_QUERY_PROBABILITY_CONVERSIONS_H_ |
27 changes: 27 additions & 0 deletions
27
libraries/wavemap/test/src/utils/test_log_odds_converter.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <cmath> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "wavemap/utils/query/probability_conversions.h" | ||
|
||
namespace wavemap { | ||
TEST(ProbabilityConversionsTest, LogOddsToProbability) { | ||
constexpr auto kInf = std::numeric_limits<FloatingPoint>::infinity(); | ||
EXPECT_NEAR(convert::logOddsToProbability(convert::kLogOddsNumericalMin), 0.f, | ||
kEpsilon); | ||
EXPECT_NEAR(convert::logOddsToProbability(convert::kLogOddsNumericalMax), 1.f, | ||
kEpsilon); | ||
EXPECT_EQ(convert::probabilityToLogOdds(0.f), -kInf); | ||
EXPECT_EQ(convert::probabilityToLogOdds(1.f), kInf); | ||
|
||
constexpr int kNumSteps = 1000; | ||
for (int step_idx = 1; step_idx < kNumSteps; ++step_idx) { | ||
const FloatingPoint probability = static_cast<FloatingPoint>(step_idx) / | ||
static_cast<FloatingPoint>(kNumSteps); | ||
const FloatingPoint log_odds = convert::probabilityToLogOdds(probability); | ||
const FloatingPoint probability_round_trip = | ||
convert::logOddsToProbability(log_odds); | ||
EXPECT_NEAR(probability_round_trip, probability, kEpsilon); | ||
} | ||
} | ||
} // namespace wavemap |