probability_values.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
9  *
10  * Unless required by applicable law or agreed to in writing, software
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef CARTOGRAPHER_MAPPING_PROBABILITY_VALUES_H_
18 #define CARTOGRAPHER_MAPPING_PROBABILITY_VALUES_H_
19
20 #include <cmath>
21 #include <vector>
22
25 #include "glog/logging.h"
26
27 namespace cartographer {
28 namespace mapping {
29
30 inline float Odds(float probability) {
31  return probability / (1.f - probability);
32 }
33
34 inline float ProbabilityFromOdds(const float odds) {
35  return odds / (odds + 1.f);
36 }
37
38 constexpr float kMinProbability = 0.1f;
39 constexpr float kMaxProbability = 1.f - kMinProbability;
40
41 // Clamps probability to be in the range [kMinProbability, kMaxProbability].
42 inline float ClampProbability(const float probability) {
43  return common::Clamp(probability, kMinProbability, kMaxProbability);
44 }
45
47 constexpr uint16 kUpdateMarker = 1u << 15;
48
49 // Converts a probability to a uint16 in the [1, 32767] range.
50 inline uint16 ProbabilityToValue(const float probability) {
51  const int value =
52  common::RoundToInt((ClampProbability(probability) - kMinProbability) *
53  (32766.f / (kMaxProbability - kMinProbability))) +
54  1;
55  // DCHECK for performance.
56  DCHECK_GE(value, 1);
57  DCHECK_LE(value, 32767);
58  return value;
59 }
60
61 extern const std::vector<float>* const kValueToProbability;
62
63 // Converts a uint16 (which may or may not have the update marker set) to a
64 // probability in the range [kMinProbability, kMaxProbability].
65 inline float ValueToProbability(const uint16 value) {
66  return (*kValueToProbability)[value];
67 }
68
69 std::vector<uint16> ComputeLookupTableToApplyOdds(float odds);
70
71 } // namespace mapping
72 } // namespace cartographer
73
74 #endif // CARTOGRAPHER_MAPPING_PROBABILITY_VALUES_H_
float ClampProbability(const float probability)
std::vector< uint16 > ComputeLookupTableToApplyOdds(const float odds)
float ProbabilityFromOdds(const float odds)
int RoundToInt(const float x)
Definition: port.h:42
constexpr float kMinProbability
float ValueToProbability(const uint16 value)
constexpr float kMaxProbability
float Odds(float probability)
const std::vector< float > *const kValueToProbability
constexpr uint16 kUnknownProbabilityValue
uint16 ProbabilityToValue(const float probability)
float value
T Clamp(const T value, const T min, const T max)
Definition: math.h:32
constexpr uint16 kUpdateMarker
uint16_t uint16
Definition: port.h:33

cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:39