0.2.0
Loading...
Searching...
No Matches
BDCSVD.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 BDCSVD
30{
31 public:
33 BDCSVD() = 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 ;
54 return Eigen::BDCSVD<Eigen::MatrixXd>(H, Eigen::ComputeThinU | Eigen::ComputeThinV).solve(y);
55 }
56};
57
58} // namespace NAV
Assertion helpers.
Vector space operations.
Utility class for logging to console and file.
Bidiagonal Divide and Conquer SVD Curve Fitting.
Definition BDCSVD.hpp:30
BDCSVD()=delete
Constructor.
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 BDCSVD.hpp:40