资源简介
可直接实现的2DPCA算法代码,有数据mat,代码
代码片段和文件信息
function [eigvector eigvalue meandatanew_dim] = pca2drow(Xoptions)
% PCA2dd 2D row Principal Component Analysis.
%
% Synopsis:
% model = pca2dd(X)
% model = pca2dd(Xnew_dim)
% model = pca2dd(Xvar)
%
% Description:
% It computes 2D row Principal Component Analysis
%
% model = pca2dd(Xnew_dim) use to specify explicitely output
% dimension where new_dim >= 1.
%
% model = pca2dd(Xvar) use to specify a portion of discarded
% variance in data where 0 <= var < 1. The new_dim is
% selected be as small as possbile and to satisfy
% var >= MsErr(new_dim)/MaxMsErr
%
% where MaxMsErr = sum(sum(X.^2)).
%
% Input:
% X[xaxanumtr] training data xa--rowxa--ranknumtr--train num
%
% new_dim [1x1] Output dimension; new_dim > 1 (default new_dim = dim);
% var [1x1] Portion of discarded variance in data.
%
% Ouputs:
% model [struct] Linear projection:
% .W [dim x new_dim] Projection matrix.
% .b [new_dim x 1] Bias.
%
% .eigval [dim x 1] eigenvalues.
% .mse [real] Mean square representation error.
% .MsErr [dim x 1] Mean-square errors with respect to number
% of basis vectors; mse=MsErr(new_dim).
% .mean_X [dim x 1] mean of training data.
%
%%
% get dimensions
[xa~numtr]=size(X);
% process input arguments
if nargin < 2
options.PCARatio = 0.99;
end
% centering data
meandata = mean(X3);
X=X-repmat(meandata[1 1 numtr]);
% covariance
Gt = zeros(xaxa);
for j=1:numtr
Gt = Gt + X(: : j)*X(: : j)‘/numtr;
end
% eigenvalue decomposition
[VD]=eig(Gt);
[eigvalueindexv]=sort(-diag(D));
sortV= V(:indexv);
% decide about the new_dimension
if options.PCARatio >= 1
new_dim = options.PCARatio; % new_dim enterd explicitely
else
new_dim=options.PCARatio*numtr;
end
% take new_dim most important eigenvectors
eigvector=sortV(:1:new_dim);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-11-10 20:09 2DPCA\
文件 1829 2013-10-08 21:52 2DPCA\2DPCA_knn.asv
文件 2914492 2013-10-08 16:27 2DPCA\AR2D_data.mat
文件 3729559 2013-10-08 16:25 2DPCA\ORL2D_data.mat
文件 2145 2013-10-11 18:44 2DPCA\PCA2D_knn.asv
文件 2220 2014-11-10 20:08 2DPCA\PCA2D_knn.m
文件 1396287 2013-10-08 16:15 2DPCA\Yale2D_data.mat
文件 1806 2013-10-08 19:58 2DPCA\pca2dd.asv
文件 1817 2013-10-08 21:44 2DPCA\pca2dr.asv
文件 1819 2013-10-08 21:54 2DPCA\pca2drow.m
- 上一篇:onvif rtsp流对接
- 下一篇:可实现的LPP算法代码
评论
共有 条评论