# nearestSPD

バージョン 1.1.0.0 (23.2 KB) 作成者:
Finding the nearest positive definite matrix
ダウンロード: 7.2K

ライセンスの表示

This tool saves your covariance matrices, turning them into something that really does have the property you will need. That is, when you are trying to use a covariance matrix in a tool like mvnrnd, it makes no sense if your matrix is not positive definite. So mvnrnd will fail in that case.

But sometimes, it appears that users end up with matrices that are NOT symmetric and positive definite (commonly abbreviated as SPD) and they still wish to use them to generate random numbers, often in a tool like mvnrnd. A solution is to find the NEAREST matrix (minimizing the Frobenius norm of the difference) that has the desired property of being SPD.

I see the question come up every once in a while, so I looked in the file exchange to see what is up there. All I found was nearest_posdef. While this usually almost works, it could be better. It actually failed completely on most of my test cases, and it was not as fast as I would like, using an optimization. In fact, in the comments to nearest_posdef, a logical alternative was posed. That alternative too has its failures, so I wrote nearestSPD, partly based on what I found in the work of Nick Higham.

nearestSPD works on any matrix, and it is reasonably fast. As a test, randn generates a matrix that is not symmetric nor is it at all positive definite in general.
U = randn(100);

nearestSPD will be able to convert U into something that is indeed SPD, and for a 100 by 100 matrix, do it quickly enough.

tic,Uj = nearestSPD(U);toc
Elapsed time is 0.008964 seconds.

The ultimate test of course, is to use chol. If chol returns a second argument that is zero, then MATLAB (and mvnrnd) will be happy!
[R,p] = chol(Uj);
p
p =
0

### 引用

John D'Errico (2024). nearestSPD (https://www.mathworks.com/matlabcentral/fileexchange/42885-nearestspd), MATLAB Central File Exchange. 取得済み .

すべてのリリースと互換性あり
##### プラットフォームの互換性
Windows macOS Linux
##### カテゴリ
Help Center および MATLAB AnswersMultivariate Normal Distribution についてさらに検索
##### 謝辞

ヒントを与えたファイル: nearestPSD, Control Functionals, iahncajigas/nSTAT

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

#### NearestSymmetricPositiveDefinite/html/

バージョン 公開済み リリース ノート
1.1.0.0

Documentation fix

1.0.0.0