-
Notifications
You must be signed in to change notification settings - Fork 0
/
DimReduc.m
47 lines (36 loc) · 827 Bytes
/
DimReduc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function varargout=DimReduc(varargin)
%
%__________________________________________________________________________
%
% _________________________________________________________________________
% Habib Ganjgahi
% Statistic Department, The univeristy of Warwick
% July/2015
fields = {'M','S'};
for a = 1:nargin
eval(sprintf('%s = varargin{a};',fields{a}))
end
nS = size(M,1);
%EVD
%hat = eye(size(M,1))-M*inv(M'*M)*M';
hat = eye(size(M,1))-M*pinv(M);
hat = (hat+hat')/2;
if ~isempty(S)
if iscell(S)
tt = hat*S{1}*hat;
else
tt = hat*S*hat;
end
else
tt = hat;
end
tt = (tt+tt')/2;
%EVD
[vector,value] = eig(tt);
%Project to lower dimension
nC = max(find(diag(value)<1e-6))+1
vec = vector(:,nC:nS);
value = value(nC:nS,nC:nS);
varargout{1} = vec;
varargout{2} = value;
end