18#include <unsupported/Eigen/MatrixFunctions>
26template<
typename SolutionVector,
typename VarianceMatrix>
46template<
typename DerivedA,
typename DerivedB>
47Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime>
solveLinearLeastSquares(
const Eigen::MatrixBase<DerivedA>& H,
const Eigen::MatrixBase<DerivedB>& dz)
49 return (H.transpose() * H).inverse() * H.transpose() * dz;
61template<
typename DerivedA,
typename DerivedW,
typename DerivedB>
62Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime>
solveWeightedLinearLeastSquares(
const Eigen::MatrixBase<DerivedA>& H,
const Eigen::MatrixBase<DerivedW>& W,
const Eigen::MatrixBase<DerivedB>& dz)
64 return (H.transpose() * W * H).inverse() * H.transpose() * W * dz;
71template<
typename DerivedA,
typename DerivedB>
72LeastSquaresResult<Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime>, Eigen::Matrix<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime, DerivedA::ColsAtCompileTime>>
76 Eigen::Matrix<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime, DerivedA::ColsAtCompileTime> Q = (H.transpose() * H).inverse();
79 Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime> dx = Q * H.transpose() * dz;
83 double RSS = std::pow(dz.norm(), 2);
95 double sigma2 = RSS /
static_cast<double>(dof);
102 return { .solution = dx, .variance = Q };
110template<
typename DerivedA,
typename DerivedW,
typename DerivedB>
111LeastSquaresResult<Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime>, Eigen::Matrix<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime, DerivedA::ColsAtCompileTime>>
115 Eigen::Matrix<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime, DerivedA::ColsAtCompileTime> Q = (H.transpose() * W * H).inverse();
116 LOG_DATA(
"Cofactor matrix = \n{}", Q);
118 Eigen::Vector<typename DerivedA::Scalar, DerivedA::ColsAtCompileTime> dx = Q * H.transpose() * W * dz;
119 LOG_DATA(
"dx = {}", dx.transpose());
122 double RSS = dz.transpose() * W * dz;
134 double sigma2 = RSS /
static_cast<double>(dof);
139 LOG_DATA(
"Covariance matrix = \n{}", Q);
141 return { .solution = dx, .variance = Q };
KeyedLeastSquaresResult< Scalar, StateKeyType > solveLinearLeastSquaresUncertainties(const KeyedMatrixX< Scalar, MeasKeyType, StateKeyType > &H, const KeyedVectorX< Scalar, MeasKeyType > &dz)
Finds the "least squares" solution for the equation .
Definition KeyedLeastSquares.hpp:62
KeyedVectorX< Scalar, StateKeyType > solveLinearLeastSquares(const KeyedMatrixX< Scalar, MeasKeyType, StateKeyType > &H, const KeyedVectorX< Scalar, MeasKeyType > &dz)
Finds the "least squares" solution for the equation .
Definition KeyedLeastSquares.hpp:36
KeyedVectorX< Scalar, StateKeyType > solveWeightedLinearLeastSquares(const KeyedMatrixX< Scalar, MeasKeyType, StateKeyType > &H, const KeyedMatrixX< Scalar, MeasKeyType, MeasKeyType > &W, const KeyedVectorX< Scalar, MeasKeyType > &dz)
Finds the "weighted least squares" solution (see LeastSquares.hpp)
Definition KeyedLeastSquares.hpp:49
KeyedLeastSquaresResult< Scalar, StateKeyType > solveWeightedLinearLeastSquaresUncertainties(const KeyedMatrixX< Scalar, MeasKeyType, StateKeyType > &H, const KeyedMatrixX< Scalar, MeasKeyType, MeasKeyType > &W, const KeyedVectorX< Scalar, MeasKeyType > &dz)
Finds the "weighted least squares" solution.
Definition KeyedLeastSquares.hpp:104
Utility class for logging to console and file.
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
Definition Logger.hpp:29
Least Squares Uncertainties return value.
Definition LeastSquares.hpp:28
VarianceMatrix variance
Least squares variance.
Definition LeastSquares.hpp:30
SolutionVector solution
Least squares solution.
Definition LeastSquares.hpp:29