LLE(局部线性嵌入)matlab代码实现

本文提供了两种LLE(局部线性嵌入)的MATLAB实现,包括降维效果的展示。对比了不同程序的差异,尤其是在K大于d时对C矩阵的调整,该调整能提升降维效果。对于调整的原理,作者表示还在学习理解中,欢迎读者交流指正。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本人在其他文章前面已经写过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
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值