Apollo 10.0
自动驾驶开放平台
sim_control_util.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 *****************************************************************************/
16
18
19#include <cmath>
20
21namespace apollo {
22namespace dreamview {
23
24double SimControlUtil::interpolate_1d(const double& p1, const double& p2,
25 const double& frac1) {
26 return p1 * (1.0 - frac1) + p2 * frac1;
27}
28
29double SimControlUtil::interpolated_find(const std::vector<double>& range_table,
30 const std::vector<double>& val_table,
31 double to_find) {
32 int size = range_table.size();
33 int left = -1;
34 int right = size;
35 int mid = 0;
36
37 // assert range_table[right] >= to_find and range_table[left] < to_find
38 while (left + 1 != right) {
39 mid = ((right - left) >> 1) + left;
40
41 if (range_table[mid] >= to_find) {
42 right = mid;
43 } else {
44 left = mid;
45 }
46 }
47
48 if (left == -1) {
49 return val_table[0];
50 }
51
52 if (left == (size - 1)) {
53 return val_table[range_table.size() - 1];
54 }
55
56 double range = range_table[right] - range_table[left];
57
58 if (fabs(range) < 1e-6) {
59 return 0.0;
60 }
61
62 double fraction = (to_find - range_table[left]) / range;
63
64 return interpolate_1d(val_table[left], val_table[right], fraction);
65}
66
67double SimControlUtil::sigmoid(const double value) {
68 return 1 / (1 + std::exp(-1.0 * value));
69}
70
71double SimControlUtil::relu(const double value) {
72 return (value > 0.0) ? value : 0.0;
73}
74
75double SimControlUtil::normalize(const double value, const double mean,
76 const double std) {
77 double eps = 1e-10;
78 return (value - mean) / (std + eps);
79}
80
81} // namespace dreamview
82} // namespace apollo
double interpolate_1d(const double &p1, const double &p2, const double &frac1)
double interpolated_find(const std::vector< double > &range_table, const std::vector< double > &val_table, double to_find)
static double relu(const double value)
double normalize(const double value, const double mean, const double std)
static double sigmoid(const double value)
class register implement
Definition arena_queue.h:37
Definition future.h:29