pcaerr.m

来自「image separation using neural net」· M 代码 · 共 24 行

M
24
字号
function [err, minerr, evals] = pcaerr(A, W)
% PCAERR    Compute the average reconstruction error for a PCA matrix.
%
% [err, minerr] = pcaerr(A, W)
%   A is the data matrix where each column is a data point
%   W is the eigenvector matrix, each column is an eigenvector
%   err is the average reconstruction error
%   minerr is the minimum reconstruction error (from SVD)   

%
% David Gleich
% CS 152 - Neural Networks
% 12 December 2003
%

err = mean(sum((A - W*(W'*A)).^2));

if (nargout > 1)
    C = cov(A');
    [V D] = eig(C);
    k = size(W,2);
    evals = -sort(-diag(D));
    minerr = sum(evals(k+1:end));
end;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?