通俗易懂理解opencv cholesky decomposition

參考資料:

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);
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內容