本人在其他文章前面已经写过LLE的原理,在这里写一下LLE的代码,一个是网上其他大神的程序,一个是参考后自己写的的。
一,
% LLE ALGORITHM (using K nearest neighbors)
% [Y] = lle(X,K,dmax)
% X :data as D x N matrix (D = dimensionality, N = #points)
% K :number of neighbors
% dmax :max embedding dimensionality
% Y :embedding as dmax x N matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Y] = lle(X,K,d)
[D,N] = size(X);
fprintf(1,'LLE running on %d points in %d dimensions\n',N,D);
%% Step1: compute pairwise distances & find neighbour
fprintf(1,'-->Finding %d nearest neighbours.\n',K);
X2 = sum(X.^2,1);
distance = repmat(X2,N,1)+repmat(X2',1,N)-2*X'*X;
[sorted,index] = sort(distance);
neighborhood = index(2:(1+K),:);
% Step2: solve for recinstruction weights
fprintf(1,'-->Solving for reconstruction weights.\n');
if(K>D)
fprintf(1,' [note: K>D; regularization will be used]\n');
tol=1e-3; % regularlizer in case constrained fits are ill conditioned
els