资源简介
机器学习中常用的流行学习算法,对于算法中的各个量都有明确的解释。
代码片段和文件信息
function r=LFDA(XYrmetrickNN)
%
% Local Fisher Discriminant Analysis for Supervised Dimensionality Reduction
%
% Usage:
% [TZ]=LFDA(XYrmetric)
%
% Input:
% X: d x n matrix of original samples
% d --- dimensionality of original samples
% n --- the number of samples
% Y: n dimensional vector of class labels
% r: dimensionality of reduced space (default: d)
% metric: type of metric in the embedding space (default: ‘weighted‘)
% ‘weighted‘ --- weighted eigenvectors
% ‘orthonormalized‘ --- orthonormalized
% ‘plain‘ --- raw eigenvectors
% kNN: parameter used in local scaling method (default: 7)
%
% Output:
% T: d x r transformation matrix (Z=T‘*X)
% Z: r x n matrix of dimensionality reduced samples
%
% (c) Masashi Sugiyama Department of Compter Science Tokyo Institute of Technology Japan.
% sugi@cs.titech.ac.jp http://sugiyama-www.cs.titech.ac.jp/~sugi/software/LFDA/
if nargin<2
error(‘Not enough input arguments.‘)
end
[d n]=size(X);
if nargin<3
r=d;
end
if nargin<4
metric=‘weighted‘;
end
if nargin<5
kNN=17;
end
tSb=zeros(dd);
tSw=zeros(dd);
for c=unique(Y)
Xc=X(:Y==c);
nc=size(Xc2);
% Define classwise affinity matrix
Xc2=sum(Xc.^21);
distance2=repmat(Xc2nc1)+repmat(Xc2‘1nc)-2*Xc‘*Xc;
[sortedindex]=sort(distance2);
kNNdist2=sorted(kNN+1:);
sigma=sqrt(kNNdist2);
localscale=sigma‘*sigma;
flag=(localscale~=0);
A=zeros(ncnc);
A(flag)=exp(-distance2(flag)./localscale(flag));
Xc1=sum(Xc2);
G=Xc*(repmat(sum(A2)[1 d]).*Xc‘)-Xc*A*Xc‘;
tSb=tSb+G/n+Xc*Xc‘*(1-nc/n)+Xc1*Xc1‘/n;
tSw=tSw+G/nc;
end
X1=sum(X2);
tSb=tSb-X1*X1‘/n-tSw;
tSb=(tSb+tSb‘)/2;
tSw=(tSw+tSw‘)/2;
aer=sum(tSb);
ber=sum(tSw);
r=aer./ber;
r=r./20;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1907 2015-04-02 20:08 LFDA.m
----------- --------- ---------- ----- ----
1907 1
- 上一篇:weui案例.zip
- 下一篇:门禁系统设计
评论
共有 条评论