找到你要的答案

Q:on symmetric positive semi-definiteness of covariance matrices in matlab

Q:对称半正定协方差矩阵的MATLAB

Hi everybody I have this problem:

  • I have Dataset of n vectors each has D dimensions.
  • I also have a covariance matrix of size D*D, Let It be C.

I perform the following action:

  • I choose K vectors from the dataset, and also choose E dimensions randomly. Let M be the sample covariance of the selected data on the selected dimensions.so M is a E*E matrix.
  • let P be the partial covariance matrix corresponding to the dimensions E of C, ie. C(E,E) in matlab

is the following matrix positive semi definite?:

X = (1-a)P + aM

where a is a constant like 0.2.

I sometimes get the following error when using mvnrnd(mean,X) : SIGMA must be a symmetric positive semi-definite matrix

My code is:

%%%Dims are randomly choosen dimensions
%%%Inds are randomly choosen Indexes form {1, 2, ...,n}
%%% PP are n D dimensional vectors, composing my data set PP is n*D
%%% Sigmaa is a D*D covariance matrix
co = cov(PP(Inds,Dims));
me = mean(PP(Inds,Dims));
Bettaa = 0.2;
sigmaaDims = sigmaa(Dims,Dims);
sigmaaDims = (1-Bettaa)*sigmaaDims + (co)*Bettaa;
Tem = mvnrnd(me,sigmaaDims);

大家好我有这个问题:

  • I have Dataset of n vectors each has D dimensions.
  • I also have a covariance matrix of size D*D, Let It be C.

我执行以下动作:

  • I choose K vectors from the dataset, and also choose E dimensions randomly. Let M be the sample covariance of the selected data on the selected dimensions.so M is a E*E matrix.
  • let P be the partial covariance matrix corresponding to the dimensions E of C, ie. C(E,E) in matlab

下列矩阵正半正定吗?:

x =(1-a)p是

A是常数0.2。

I sometimes get the following error when using mvnrnd(mean,X) : SIGMA must be a symmetric positive semi-definite matrix

我的代码是:

%%%Dims are randomly choosen dimensions
%%%Inds are randomly choosen Indexes form {1, 2, ...,n}
%%% PP are n D dimensional vectors, composing my data set PP is n*D
%%% Sigmaa is a D*D covariance matrix
co = cov(PP(Inds,Dims));
me = mean(PP(Inds,Dims));
Bettaa = 0.2;
sigmaaDims = sigmaa(Dims,Dims);
sigmaaDims = (1-Bettaa)*sigmaaDims + (co)*Bettaa;
Tem = mvnrnd(me,sigmaaDims);
answer1: 回答1:

Simply looking at the matrix dimensions It is not possible to tell if a matrix is positive semi-definite.

To find out if a given matrix is positive semi-definite, you must check if It's eigenvalues are non-negative and it's symmetry:

symmetry = issymmetric(X);
[~,D]=eig(X);
eigenvalues = diag(D);
if all(eigenvalues>0) & symmetry
    disp('Positive semi-definite matrix.')
else
     disp('Non positive semi-definite matrix.')
end

Where X is the matrix you are interested in.

Note that if you use the weaker definition of a positive definite matrix (see Extention for non symmetric matrices section), X does not need to be symmetric and you would end up with:

[~,D]=eig(X);
eigenvalues = diag(D);
if all(eigenvalues>=0)
    disp('Positive semi-definite matrix.')
else
     disp('Non positive semi-definite matrix.')
end

简单地看矩阵的维数,它是不可能的,如果一个矩阵是正定半正定。

要确定一个给定的矩阵是半正定的,你必须检查它的特征值是非负的,它的对称性:

symmetry = issymmetric(X);
[~,D]=eig(X);
eigenvalues = diag(D);
if all(eigenvalues>0) & symmetry
    disp('Positive semi-definite matrix.')
else
     disp('Non positive semi-definite matrix.')
end

其中x是你感兴趣的矩阵。

注意,如果你使用一个正定矩阵的定义弱(见非对称矩阵部分的延伸),X不需要对称的和你结束了:

[~,D]=eig(X);
eigenvalues = diag(D);
if all(eigenvalues>=0)
    disp('Positive semi-definite matrix.')
else
     disp('Non positive semi-definite matrix.')
end
matlab  matrix  covariance