25 #include "Eigen/Dense" 35 template <std::
size_t N>
39 for (
int i = N; i >= 0; --i) {
46 template <std::
size_t N, std::
size_t M>
48 const std::array<Eigen::Vector2d, M>& points,
49 double* ptr_error_square =
nullptr) {
50 Eigen::Matrix<double, M, N + 1> X;
51 Eigen::Matrix<double, M, 1> Y;
52 for (std::size_t i = 0; i < M; ++i) {
53 double x = points[i].x();
54 double y = points[i].y();
57 for (std::size_t j = 1; j < N + 1; ++j) {
58 X(i, j) = X(i, j - 1) * x;
64 Eigen::Matrix<double, N + 1, 1> t =
65 PseudoInverse<double, N + 1, N + 1>(X.transpose() * X) * X.transpose() *
68 std::array<double, N + 1> coefs;
69 for (std::size_t i = 0; i < N + 1; ++i) {
73 if (ptr_error_square !=
nullptr) {
74 *ptr_error_square = 0.0;
77 *ptr_error_square += error * error;
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Eigen::Vector2d Vector2d
Definition: base_map_fwd.h:36
double EvaluatePolynomial(const std::array< double, N+1 > &coef, const double p)
Definition: curve_fitting.h:36
Defines some useful matrix operations.
std::array< double, N+1 > FitPolynomial(const std::array< Eigen::Vector2d, M > &points, double *ptr_error_square=nullptr)
Definition: curve_fitting.h:47