Apollo 11.0
自动驾驶开放平台
probabilities.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
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 *****************************************************************************/
17
18#include <cmath>
19#include <numeric>
20
21namespace apollo {
22namespace perception {
23namespace fusion {
24
25// @brief: scale input prob within input range
26// @return bounded & scaled prob
27// @NOTE: original method name is bound_scale_probability
28double BoundedScalePositiveProbability(double p, double max_p, double min_p) {
29 p = std::max(p, min_p);
30 p = (p - min_p) * (max_p - min_p) / (1 - min_p) + min_p;
31 return p;
32}
33// @brief: scale input prob
34// @return scaled prob
35// @NOTE: original method name is scale_positive_probability
36double ScalePositiveProbability(double p, double max_p, double th_p) {
37 if (p <= th_p) {
38 return p;
39 }
40 p = (p - th_p) * (max_p - th_p) / (1 - th_p) + th_p;
41 return p;
42}
43// @brief: calculate the Welsh Loss
44// @return Welsh Loss of input dist
45// @NOTE: original method name is welsh_var_loss_fun
46double WelshVarLossFun(double dist, double th, double scale) {
47 double p = 1e-6;
48 if (dist < th) {
49 p = 1 - 1e-6;
50 } else {
51 dist -= th;
52 dist /= scale;
53 p = std::exp(-dist * dist);
54 }
55 return p;
56}
57// @brief: fuse two probabilities, fused prob is greater than 0.5, if
58// the sum of input prob pair is greater than 1, otherwise, fused prob
59// is less than 0.5
60// @return fused prob of input prob pair
61// @NOTE: original method name is fused_tow_probabilities
62double FuseTwoProbabilities(double prob1, double prob2) {
63 double prob = (prob1 * prob2) / (2 * prob1 * prob2 + 1 - prob1 - prob2);
64 return prob;
65}
66// @brief: fuse multiple probabilities
67// @return fsued probability of input multiple probabilities
68// @NOTE: original method name is fused_multiple_probabilities
69double FuseMultipleProbabilities(const std::vector<double>& probs) {
70 std::vector<double> log_odd_probs = probs;
71 auto prob_to_log_odd = [](double p) {
72 p = std::max(std::min(p, 1 - 1e-6), 1e-6);
73 return std::log(p / (1 - p));
74 };
75 auto log_odd_to_prob = [](double log_odd_p) {
76 double tmp = std::exp(log_odd_p);
77 return tmp / (tmp + 1);
78 };
79 for (auto& log_odd_prob : log_odd_probs) {
80 log_odd_prob = prob_to_log_odd(log_odd_prob);
81 }
82 double log_odd_probs_sum =
83 std::accumulate(log_odd_probs.begin(), log_odd_probs.end(), 0.0);
84 return log_odd_to_prob(log_odd_probs_sum);
85}
86
87} // namespace fusion
88} // namespace perception
89} // namespace apollo
double BoundedScalePositiveProbability(double p, double max_p, double min_p)
double FuseMultipleProbabilities(const std::vector< double > &probs)
double ScalePositiveProbability(double p, double max_p, double th_p)
double WelshVarLossFun(double dist, double th, double scale)
double FuseTwoProbabilities(double prob1, double prob2)
class register implement
Definition arena_queue.h:37