49 template<
typename Matrix_TypeA,
typename Matrix_TypeB>
51 Matrix_TypeB &_dPinvJ,
52 const double _lambda = 0,
53 const double _epsilon = std::numeric_limits<typename Matrix_TypeA::Scalar>::epsilon())
56 constexpr
auto rowsA =
static_cast<int>(Matrix_TypeA::RowsAtCompileTime);
57 constexpr
auto colsA =
static_cast<int>(Matrix_TypeA::ColsAtCompileTime);
58 constexpr
auto rowsB =
static_cast<int>(Matrix_TypeB::RowsAtCompileTime);
59 constexpr
auto colsB =
static_cast<int>(Matrix_TypeB::ColsAtCompileTime);
60 constexpr
auto rankA =
static_cast<int>(Eigen::JacobiSVD<Matrix_TypeA>::DiagSizeAtCompileTime);
63 static_assert(std::is_same<typename Matrix_TypeA::Scalar, typename Matrix_TypeB::Scalar>::value,
64 "[angle_utils::dampedPseduoInverse] Matrix scalars does not match!");
65 static_assert(rowsA == colsB && colsA == rowsB,
66 "[angle_utils::dampedPseduoInverse] Input and Output matrix dimensions does not match!");
69 Eigen::JacobiSVD<Eigen::Matrix<typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic> > svd(_J, Eigen::ComputeThinU | Eigen::ComputeThinV);
70 const Eigen::Matrix<typename Matrix_TypeA::Scalar, rowsA, rankA> U = svd.matrixU();
71 const Eigen::Matrix<typename Matrix_TypeA::Scalar, rankA, 1> SV = svd.singularValues();
72 const Eigen::Matrix<typename Matrix_TypeA::Scalar, colsA, rankA> V = svd.matrixV();
75 Eigen::Matrix<typename Matrix_TypeA::Scalar, rankA, 1> damped_inv_SV;
76 for (
size_t i = 0; i < rankA; ++i)
78 if (std::fabs(SV(i) > _epsilon))
80 damped_inv_SV(i) = 1 / SV(i);
84 damped_inv_SV(i) = SV(i) / ( std::pow(SV(i),2) + std::pow(_lambda, 2) );
89 _dPinvJ = V * damped_inv_SV.asDiagonal() * U.transpose();
103 template<
typename Matrix_TypeA,
typename Matrix_TypeB>
106 const double _alpha = 1)
108 constexpr
auto rowsA =
static_cast<int>(Matrix_TypeA::RowsAtCompileTime);
109 constexpr
auto colsA =
static_cast<int>(Matrix_TypeA::ColsAtCompileTime);
110 constexpr
auto rowsB =
static_cast<int>(Matrix_TypeB::RowsAtCompileTime);
111 constexpr
auto colsB =
static_cast<int>(Matrix_TypeB::ColsAtCompileTime);
114 static_assert(std::is_same<typename Matrix_TypeA::Scalar, typename Matrix_TypeB::Scalar>::value,
115 "[angle_utils::nullSpaceProjector] Matrix scalars does not match!");
116 static_assert(colsA == rowsB && colsA == colsB,
117 "[angle_utils::nullSpaceProjector] Input and Output matrix dimensions does not match!");
120 Eigen::Matrix<typename Matrix_TypeA::Scalar, colsA, rowsA> pinvA;
122 kindr::pseudoInverse(_A, pinvA);
125 Eigen::Matrix<typename Matrix_TypeA::Scalar, colsA, colsA> I = Eigen::Matrix<typename Matrix_TypeA::Scalar, colsA, colsA>::Identity();
128 _N = I - _alpha * pinvA * _A;
143 template<
typename Matrix_TypeA>
144 Eigen::Matrix<typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic>
SVDNullSpaceProjector(
const Matrix_TypeA &_A)
147 Eigen::Matrix<typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic> N;
150 const auto rowsA = _A.rows();
151 const auto colsA = _A.cols();
154 Eigen::JacobiSVD< Eigen::Matrix<typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic> > svd(_A, Eigen::ComputeThinU | Eigen::ComputeFullV);
157 const auto rankA = svd.rank();
167 N.resize(colsA, colsA - rankA);
168 N = svd.matrixV().rightCols(colsA - rankA);
179 template<
typename Vector_TypeA,
typename Vector_TypeB>
180 Eigen::Matrix<typename Vector_TypeA::Scalar, Eigen::Dynamic, 1>
boxMinus(
const Vector_TypeA &_a,
const Vector_TypeB &_b)
183 constexpr
auto rowsA =
static_cast<int>(Vector_TypeA::RowsAtCompileTime);
184 constexpr
auto colsA =
static_cast<int>(Vector_TypeA::ColsAtCompileTime);
185 constexpr
auto rowsB =
static_cast<int>(Vector_TypeB::RowsAtCompileTime);
186 constexpr
auto colsB =
static_cast<int>(Vector_TypeB::ColsAtCompileTime);
189 static_assert(std::is_same<typename Vector_TypeA::Scalar, typename Vector_TypeB::Scalar>::value,
190 "[math_utils::boxMinus] Vectors must be of the same Scalar type!");
191 static_assert(rowsA == rowsB && colsA == 1 && colsB == 1,
"[math_utils::boxMinus] Inputs has wrong size!");
194 Eigen::Matrix<typename Vector_TypeA::Scalar, rowsA, 1> res;
197 for (
size_t i = 0; i < rowsA; i++)
199 res(i) = std::log( _a(i) / _b(i) );
Eigen::Matrix< typename Vector_TypeA::Scalar, Eigen::Dynamic, 1 > boxMinus(const Vector_TypeA &_a, const Vector_TypeB &_b)
The boxMinus function calculates the box-minus operation between two vectors of equal size.
Eigen::Matrix< typename Matrix_TypeA::Scalar, Eigen::Dynamic, Eigen::Dynamic > SVDNullSpaceProjector(const Matrix_TypeA &_A)
The SVDNullSpaceProjector function calculates the null-space projector of a given matrix....
static bool nullSpaceProjector(const Matrix_TypeA &_A, Matrix_TypeB &_N, const double _alpha=1)
The nullSpaceProjector function calculates the null-space projector of a given matrix....
static bool dampedPseudoInverse(const Matrix_TypeA &_J, Matrix_TypeB &_dPinvJ, const double _lambda=0, const double _epsilon=std::numeric_limits< typename Matrix_TypeA::Scalar >::epsilon())
The dampedPseudoInverse function calculates the damped pseudo-inverse of a matrix using SVD.