参考资料:
https://blog.csdn.net/m0_37772174/article/details/104766317
正文:
L是A的下三角矩阵,对L进行cholesky分解
最终得到的L是对A cholesky分解的结果
// covMatrixL = cholesky( covMatrix )
if (dataType_ == CV_64F) {
choleskyDecomposition<double>(
covMatrix.ptr<double>(), covMatrix.step, covMatrix.rows,
covMatrixL.ptr<double>(), covMatrixL.step);
} else if (dataType_ == CV_32F) {
choleskyDecomposition<float>(
covMatrix.ptr<float>(), covMatrix.step, covMatrix.rows,
covMatrixL.ptr<float>(), covMatrixL.step);
} else {
}
template<typename _Tp> bool
inline choleskyDecomposition(const _Tp* A, size_t astep,
int asize, _Tp* L, size_t lstep) {
bool success = false;
astep /= sizeof(_Tp);
lstep /= sizeof(_Tp);
for (int i = 0; i < asize; i++) {
for (int j = 0; j <= i; j++) {
L[i*lstep + j] = A[i*astep + j];
}
}
success = callHalCholesky(L, lstep * sizeof(_Tp), asize);
if (success) {
for (int i = 0; i < asize; i++) {
#if CV_VERSION_MINOR < 4
L[i*asize + i] = 1.0f / L[i*asize + i];
#endif
for (int j = i + 1; j < asize; j++) {
L[i*lstep + j] = 0.0;
}
}
}
return success;
}
/* Cholesky decomposition
The function performs Cholesky decomposition
<https://en.wikipedia.org/wiki/Cholesky_decomposition>.
A - the Hermitian, positive-definite matrix,
astep - size of row in A,
asize - number of cols and rows in A,
L - the lower triangular matrix, A = L*Lt.
*/
template<typename _Tp> bool
inline callHalCholesky(_Tp* L, size_t lstep, int lsize);
template<> bool
inline callHalCholesky<float>(float* L, size_t lstep, int lsize) {
return cv::hal::Cholesky32f(L, lstep, lsize, NULL, 0, 0);
}
网友评论