How to define a covariance matrix that is positive semi definite?

2 次查看(过去 30 天)
mu = [80 130 200];
sigma = [1 1.5 4; 1.5 3 2; 4 2 1];
rng('default') % For reproducibility
R = mvnrnd(mu,sigma,200);

回答(2 个)

the cyclist
the cyclist 2019-9-30
编辑:the cyclist 2019-9-30
First, let me explain why sigma has to be positive semidefinite.
Take this correlation matrix as an example:
sigma = [1.0 0.9 0.9;
0.9 1.0 0.2;
0.9 0.2 1.0];
Imagine that this represents the correlation of the stock prices of three companies: A, B, and C (corresponding to the 1st, 2nd, and 3rd columns, respectively).
Notice that companies A and B are correlated at 0.9 -- their stocks prices are very highly correlated. Similarly, companies A and C are very highly correlated.
From those two facts, we can see that companies B and C must also be pretty highly correlated. If A and B move together, and A and C move together, then B and C must move together.
But, according to this matrix, B and C are only correlated 0.2. This is not possible. There is an inconsistency among these correlation coefficients!
That inconsistency is why this matrix is not positive semidefinite, and why it is not possible to simulate correlated values based on this matrix.
===
Now, to your question. Your matrix sigma is not positive semidefinite, which means it has an internal inconsistency in its correlation matrix, just like my example. It's not always easy to see exactly why.
It is also not clear how to fix it, while still solving the problem you want to solve.
If you simply want to generate a matrix that will work, then you can take any real-valued matrix M, and do the following:
sigma = M'*M;
sigma is guaranteed to be positive semidefinite in this case.
But if the sigma you used is actually supposed to be meaningful for some reason, then you need to figure out why it is invalid.
I hope that helps!

Bruno Luong
Bruno Luong 2019-9-30
L=randn(3);
sigma=L'*L

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by