0.2.0
Loading...
Searching...
No Matches
COD.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <cstddef>
17#include <vector>
18#include <cmath>
19#include "util/Assert.h"
20#include "util/Eigen.hpp"
21#include "util/Logger.hpp"
22
23namespace NAV
24{
25
28template<typename Scalar>
29class COD
30{
31 public:
33 COD() = delete;
34
39 template<typename DerivedX, typename DerivedY>
40 [[nodiscard]] static Eigen::VectorX<Scalar> calcCoefficients(const Eigen::MatrixBase<DerivedX>& x, const Eigen::MatrixBase<DerivedY>& y, size_t polynomialDegree = 2)
41 {
42 auto effectiveDegree = static_cast<Eigen::Index>(std::min(polynomialDegree, static_cast<size_t>(x.rows()) - 1));
43
44 auto n = x.size();
45 Eigen::MatrixX<Scalar> H = Eigen::MatrixX<Scalar>(n, effectiveDegree + 1);
46 Eigen::ArrayX<Scalar> xpow = Eigen::ArrayX<Scalar>::Ones(x.rows());
47 for (int i = 0; i < effectiveDegree + 1; i++)
48 {
49 H.col(i) = xpow.matrix();
50 xpow *= x.array();
51 }
52
53 return Eigen::CompleteOrthogonalDecomposition<Eigen::MatrixXd>(H).solve(y);
54 }
55};
56
57} // namespace NAV
Assertion helpers.
Vector space operations.
Utility class for logging to console and file.
Complete Orthogonal Decomposition Curve Fitting.
Definition COD.hpp:30
static Eigen::VectorX< Scalar > calcCoefficients(const Eigen::MatrixBase< DerivedX > &x, const Eigen::MatrixBase< DerivedY > &y, size_t polynomialDegree=2)
Calculates the polynomial coefficients in order a0 + a1 * x + a2 * x^2 + ...
Definition COD.hpp:40
COD()=delete
Constructor.