3
14
2013
1

matlab cov()得到的协方差矩阵不是正定矩阵怎么办

实验中,matlab用cov()得到协方差矩阵,这个矩阵作为多维高斯分布的gamma参数,结果gamma参数要求该矩阵为正定矩阵,而该矩阵只能保证为对称矩阵。http://stackoverflow.com/questions/11269715/matlabs-sigma-must-be-symmetric-and-positive-definite-error-sometimes-not-mak

给出了解决方案

This happens if the diagonal values of the covariance matrix are (very close to) zero. A simple fix is add a very small constant number to c.

err_cnt = 0;

for i = 1:1000
    try 
        a = rand(3); 
        c = cov(a) + .0001 * eye(3); 
        m = mean(a); 
        mvnpdf(a, m, c);
    catch me
        err_cnt = err_cnt + 1;
    end
end

Results in 0 errors.

Category: C/C++ | Tags: | Read Count: 12315

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

| Theme: Aeros 2.0 by TheBuckmaker.com