0.2.0
Loading...
Searching...
No Matches
HouseholderQr.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
22namespace NAV
23{
24
27template<typename Scalar>
29{
30 public:
32 HouseholderQr() = delete;
33
38 template<typename DerivedX, typename DerivedY>
39 [[nodiscard]] static Eigen::VectorX<Scalar> calcCoefficients(const Eigen::MatrixBase<DerivedX>& x, const Eigen::MatrixBase<DerivedY>& y, size_t polynomialDegree = 2)
40 {
41 auto effectiveDegree = static_cast<Eigen::Index>(std::min(polynomialDegree, static_cast<size_t>(x.rows()) - 1));
42
43 auto n = x.size();
44 Eigen::MatrixX<Scalar> H = Eigen::MatrixX<Scalar>(n, effectiveDegree + 1);
45 Eigen::ArrayX<Scalar> xpow = Eigen::ArrayX<Scalar>::Ones(x.rows());
46 for (int i = 0; i < effectiveDegree + 1; i++)
47 {
48 H.col(i) = xpow.matrix();
49 xpow *= x.array();
50 }
51
52 return H.householderQr().solve(y);
53 }
54};
55
56} // namespace NAV
Assertion helpers.
Vector space operations.
Householder QR decomposition Curve Fitting.
Definition HouseholderQr.hpp:29
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 HouseholderQr.hpp:39
HouseholderQr()=delete
Constructor.