Apollo 10.0
自动驾驶开放平台
apollo::prediction::math_util 命名空间参考

函数

double Normalize (const double value, const double mean, const double std)
 Normalize the value by specified mean and standard deviation.
 
double Relu (const double value)
 RELU function used in neural networks as an activation function.
 
std::vector< double > Softmax (const std::vector< double > &value, bool use_exp=true)
 Softmax function used in neural networks as an activation function.
 
int SolveQuadraticEquation (const std::vector< double > &coefficients, std::pair< double, double > *roots)
 Solve quadratic equation.
 
double EvaluateQuinticPolynomial (const std::array< double, 6 > &coeffs, const double t, const uint32_t order, const double end_t, const double end_v)
 Evaluate quintic polynomial.
 
double EvaluateQuarticPolynomial (const std::array< double, 5 > &coeffs, const double t, const uint32_t order, const double end_t, const double end_v)
 Evaluate quartic polynomial.
 
double EvaluateCubicPolynomial (const std::array< double, 4 > &coefs, const double t, const uint32_t order, const double end_t=std::numeric_limits< double >::infinity(), const double end_v=0.0)
 Evaluate cubic polynomial.
 
double GetSByConstantAcceleration (const double v0, const double acceleration, const double t)
 
template<std::size_t N>
std::array< double, 2 *N - 2 > ComputePolynomial (const std::array< double, N - 1 > &start_state, const std::array< double, N - 1 > &end_state, const double param)
 
template<>
std::array< double, 4 > ComputePolynomial< 3 > (const std::array< double, 2 > &start_state, const std::array< double, 2 > &end_state, const double param)
 

函数说明

◆ ComputePolynomial()

template<std::size_t N>
std::array< double, 2 *N - 2 > apollo::prediction::math_util::ComputePolynomial ( const std::array< double, N - 1 > &  start_state,
const std::array< double, N - 1 > &  end_state,
const double  param 
)

◆ ComputePolynomial< 3 >()

template<>
std::array< double, 4 > apollo::prediction::math_util::ComputePolynomial< 3 > ( const std::array< double, 2 > &  start_state,
const std::array< double, 2 > &  end_state,
const double  param 
)
inline

在文件 prediction_util.h97 行定义.

104 {
105 std::array<double, 4> coefs;
106 coefs[0] = start_state[0];
107 coefs[1] = start_state[1];
108
109 auto m0 = end_state[0] - start_state[0] - start_state[1] * param;
110 auto m1 = end_state[1] - start_state[1];
111
112 auto param_p3 = param * param * param;
113 coefs[3] = (m1 * param - 2.0 * m0) / param_p3;
114
115 coefs[2] = (m1 - 3.0 * coefs[3] * param * param) / param * 0.5;
116 return coefs;
117}

◆ EvaluateCubicPolynomial()

double apollo::prediction::math_util::EvaluateCubicPolynomial ( const std::array< double, 4 > &  coefs,
const double  t,
const uint32_t  order,
const double  end_t = std::numeric_limits< double >::infinity(),
const double  end_v = 0.0 
)

Evaluate cubic polynomial.

参数
coefficientsof the cubic polynomial, lower to higher.
parameterof the cubic polynomial.
end_tending time for extrapolation.
end_vending velocity for extrapolation.
返回
order of derivative to evaluate.

在文件 prediction_util.cc175 行定义.

177 {
178 if (t > end_t) {
179 switch (order) {
180 case 0: {
181 double end_value =
182 ((coefs[3] * end_t + coefs[2]) * end_t + coefs[1]) * end_t +
183 coefs[0];
184 return end_value + (t - end_t) * end_v;
185 }
186 case 1: {
187 return end_v;
188 }
189 default: { return 0.0; }
190 }
191 }
192
193 switch (order) {
194 case 0: {
195 return ((coefs[3] * t + coefs[2]) * t + coefs[1]) * t + coefs[0];
196 }
197 case 1: {
198 return (3.0 * coefs[3] * t + 2.0 * coefs[2]) * t + coefs[1];
199 }
200 case 2: {
201 return 6.0 * coefs[3] * t + 2.0 * coefs[2];
202 }
203 case 3: {
204 return 6.0 * coefs[3];
205 }
206 default:
207 return 0.0;
208 }
209}

◆ EvaluateQuarticPolynomial()

double apollo::prediction::math_util::EvaluateQuarticPolynomial ( const std::array< double, 5 > &  coeffs,
const double  t,
const uint32_t  order,
const double  end_t,
const double  end_v 
)

Evaluate quartic polynomial.

参数
coefficientsof the quartic polynomial, lower to higher.
parameterof the quartic polynomial.
返回
order of derivative to evaluate.

在文件 prediction_util.cc131 行定义.

133 {
134 if (t >= end_t) {
135 switch (order) {
136 case 0: {
137 double end_value =
138 (((coeffs[4] * end_t + coeffs[3]) * end_t + coeffs[2]) * end_t +
139 coeffs[1]) *
140 end_t +
141 coeffs[0];
142 return end_value + (t - end_t) * end_v;
143 }
144 case 1: {
145 return end_v;
146 }
147 default: { return 0.0; }
148 }
149 }
150 switch (order) {
151 case 0: {
152 return (((coeffs[4] * t + coeffs[3]) * t + coeffs[2]) * t + coeffs[1]) *
153 t +
154 coeffs[0];
155 }
156 case 1: {
157 return ((4.0 * coeffs[4] * t + 3.0 * coeffs[3]) * t + 2.0 * coeffs[2]) *
158 t +
159 coeffs[1];
160 }
161 case 2: {
162 return (12.0 * coeffs[4] * t + 6.0 * coeffs[3]) * t + 2.0 * coeffs[2];
163 }
164 case 3: {
165 return 24.0 * coeffs[4] * t + 6.0 * coeffs[3];
166 }
167 case 4: {
168 return 24.0 * coeffs[4];
169 }
170 default:
171 return 0.0;
172 }
173}

◆ EvaluateQuinticPolynomial()

double apollo::prediction::math_util::EvaluateQuinticPolynomial ( const std::array< double, 6 > &  coeffs,
const double  t,
const uint32_t  order,
const double  end_t,
const double  end_v 
)

Evaluate quintic polynomial.

参数
coefficientsof the quintic polynomial, lower to higher.
parameterof the quintic polynomial.
返回
order of derivative to evaluate.

在文件 prediction_util.cc75 行定义.

77 {
78 if (t >= end_t) {
79 switch (order) {
80 case 0: {
81 double end_value =
82 ((((coeffs[5] * end_t + coeffs[4]) * end_t + coeffs[3]) * end_t +
83 coeffs[2]) *
84 end_t +
85 coeffs[1]) *
86 end_t +
87 coeffs[0];
88 return end_value + end_v * (t - end_t);
89 }
90 case 1: {
91 return end_v;
92 }
93 default: { return 0.0; }
94 }
95 }
96 switch (order) {
97 case 0: {
98 return ((((coeffs[5] * t + coeffs[4]) * t + coeffs[3]) * t + coeffs[2]) *
99 t +
100 coeffs[1]) *
101 t +
102 coeffs[0];
103 }
104 case 1: {
105 return (((5.0 * coeffs[5] * t + 4.0 * coeffs[4]) * t + 3.0 * coeffs[3]) *
106 t +
107 2.0 * coeffs[2]) *
108 t +
109 coeffs[1];
110 }
111 case 2: {
112 return (((20.0 * coeffs[5] * t + 12.0 * coeffs[4]) * t) +
113 6.0 * coeffs[3]) *
114 t +
115 2.0 * coeffs[2];
116 }
117 case 3: {
118 return (60.0 * coeffs[5] * t + 24.0 * coeffs[4]) * t + 6.0 * coeffs[3];
119 }
120 case 4: {
121 return 120.0 * coeffs[5] * t + 24.0 * coeffs[4];
122 }
123 case 5: {
124 return 120.0 * coeffs[5];
125 }
126 default:
127 return 0.0;
128 }
129}

◆ GetSByConstantAcceleration()

double apollo::prediction::math_util::GetSByConstantAcceleration ( const double  v0,
const double  acceleration,
const double  t 
)

在文件 prediction_util.cc211 行定义.

212 {
213 if (acceleration > -FLAGS_double_precision) {
214 return v0 * t + 0.5 * acceleration * t * t;
215 }
216 double t_stop = v0 / (-acceleration);
217 double t_actual = std::min(t, t_stop);
218 return v0 * t_actual + 0.5 * acceleration * t_actual * t_actual;
219}

◆ Normalize()

double apollo::prediction::math_util::Normalize ( const double  value,
const double  mean,
const double  std 
)

Normalize the value by specified mean and standard deviation.

参数
valueThe value to be normalized.
meanThe mean used for normalization.
stdThe standard deviation used for normalization.
返回
The normalized value.

在文件 prediction_util.cc28 行定义.

28 {
29 const double eps = 1e-10;
30 return (value - mean) / (std + eps);
31}
Definition future.h:29

◆ Relu()

double apollo::prediction::math_util::Relu ( const double  value)

RELU function used in neural networks as an activation function.

参数
valueThe input.
返回
The output of RELU function.

在文件 prediction_util.cc33 行定义.

33{ return (value > 0.0) ? value : 0.0; }

◆ Softmax()

std::vector< double > apollo::prediction::math_util::Softmax ( const std::vector< double > &  value,
bool  use_exp = true 
)

Softmax function used in neural networks as an activation function.

参数
vectorThe input.
返回
The output of Softmax function.

在文件 prediction_util.cc35 行定义.

35 {
36 std::vector<double> result;
37 double sum = 0.0;
38 for (std::size_t i = 0; i < value.size(); ++i) {
39 double exp_value = std::max(0.001, value[i]);
40 if (use_exp) {
41 exp_value = std::exp(value[i]);
42 }
43 sum += exp_value;
44 result.push_back(exp_value);
45 }
46 for (std::size_t i = 0; i < value.size(); ++i) {
47 result[i] = result[i] / sum;
48 }
49 return result;
50}

◆ SolveQuadraticEquation()

int apollo::prediction::math_util::SolveQuadraticEquation ( const std::vector< double > &  coefficients,
std::pair< double, double > *  roots 
)

Solve quadratic equation.

参数
coefficientsThe coefficients of quadratic equation.
rootsTwo roots of the equation if any.
返回
An integer indicating the success of solving equation.

在文件 prediction_util.cc52 行定义.

53 {
54 if (coefficients.size() != 3) {
55 return -1;
56 }
57 const double a = coefficients[0];
58 const double b = coefficients[1];
59 const double c = coefficients[2];
60 if (std::fabs(a) <= std::numeric_limits<double>::epsilon()) {
61 return -1;
62 }
63
64 double delta = b * b - 4.0 * a * c;
65 if (delta < 0.0) {
66 return -1;
67 }
68
69 double sqrt_delta = std::sqrt(delta);
70 roots->first = (-b + sqrt_delta) * 0.5 / a;
71 roots->second = (-b - sqrt_delta) * 0.5 / a;
72 return 0;
73}