regularize.m
来自「These Matlab files are a convenient inte」· M 代码 · 共 30 行
M
30 行
% REGULARIZE - Regularizes a matrix so that it is positive definite.
%
%
%
%
function s = regularize(s)
if (isempty(s))
return;
end
thresh = sqrt(eps);
span = 1e5;
[V, D] = eig(full(s));
% Eliminate imaginary and negative eigenvalues.
d = real(diag(D));
d(find(d < 0)) = 0;
% Compute the condition number of the matrix.
if ~min(d)
cond = Inf;
else
cond = max(d) / min(d);
end
% If the condition number is greater than a threshold, then
% regularize the matrix by filling out its eigenspectrum.
if (cond > span)
min_eig = max(d) / span;
d = d + min_eig;
end
s = V * diag(d) * V';
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?