Isomap算法的matlab实现
本人最近为了完成机器学习这门课的作业,查阅了Isomap的相关资料。现把matlab官网给出的Isomap代码贴在下面,方便新手使用。
同时把网址附在这里,https://www.mathworks.com/matlabcentral/fileexchange/62449-isomap-d-n_fcn-n_size-options。
function [Y, R, E] = Isomap(D, n_fcn, n_size, options);
% ISOMAP Computes Isomap embedding using the algorithm of
% Tenenbaum, de Silva, and Langford (2000).
%
% [Y, R, E] = isomap(D, n_fcn, n_size, options);
%
% Input:
% D = N x N matrix of distances (where N is the number of data points)
% n_fcn = neighborhood function (‘epsilon’ or ‘k’)
% n_size = neighborhood size (value for epsilon or k)
%
% options.dims = (row) vector of embedding dimensionalities to use
% (1:10 = default)
% options.comp = which connected component to embed, if more than one.
% (1 = largest (default), 2 = second largest, …)
% options.display = plot residual variance and 2-D embedding?
% (1 = yes (default), 0 = no)
% options.overlay = overlay graph on 2-D embedding?
% (1 = yes (default), 0 = no)
% options.verbose = display progress reports?
% (1 = yes (default), 0 = no)
%
% Output:
% Y = Y.coords is a cell array, with coordinates for d-dimensional embeddings
% in Y.coords{d}. Y.index contains the indices of the points embedded.
% R = residual variances for embeddings in Y
% E = edge matrix for neighborhood graph
%
% BEGIN COPYRIGHT NOTICE
%
% Isomap code – © 1998-2000 Josh Tenenbaum
%
% This code is provided as is, with no guarantees except that
% bugs are almost surely present. Published reports of research
% using this code (or a modified version) should cite the
% article that describes the algorithm:
%
% J. B. Tenenbaum, V. de Silva, J. C. Langford (2000). A global
% geometric framework for nonlinear dimensionality reduction.
% Science 290 (5500): 2319-2323, 22 December 2000.
%
% Comments and bug reports are welcome. Email to jbt@psych.stanford.edu.
% I would also appreciate hearing about how you used this code,
% improvements that you have made to it, or translations into other
% languages.
%
% You are free to modify, extend or distribute this code, as long
% as this copyright notice is included whole and unchanged.
%
% END COPYRIGHT NOTICE
%%%%% Step 0: Initialization and Parameters %%%%%
N = size(D,1);
if ~(Nsize(D,2))
error(‘D must be a square matrix’);
end;
if n_fcn
’k’
K = n_size;
if ~(Kround(K))
error(‘Number of neighbors for k method must be an integer’);
end
elseif n_fcn
’epsilon’
epsilon = n_size;
else
error(‘Neighborhood function must be either epsilon or k’);
end
if nargin < 3
error(‘Too few input arguments’);
elseif nargin < 4
options = struct(‘dims’,1:10,‘overlay’,1,‘comp’,1,‘display’,1,‘verbose’,1);
end
INF = 1000*max(max(D))N; %% effectively infinite distance
if ~isfield(options,‘dims’)
options.dims = 1:10;
end
if ~isfield(options,‘overlay’)
options.overlay = 1;
end
if ~isfield(options,‘comp’)
options.comp = 1;
end
if ~isfield(options,‘display’)
options.display = 1;
end
if ~isfield(options,‘verbose’)
options.verbose = 1;
end
dims = options.dims;
comp = options.comp;
overlay = options.overlay;
displ = options.display;
verbose = options.verbose;
Y.coords = cell(length(dims),1);
R = zeros(1,length(dims));
%%%%% Step 1: Construct neighborhood graph %%%%%
disp(‘Constructing neighborhood graph…’);
if n_fcn == ‘k’
[tmp, ind] = sort(D);
for i=1:N
D(i,ind((2+K):end,i)) = INF;
end
elseif n_fcn == ‘epsilon’
warning off %% Next line causes an unnecessary warning, so turn it off
D = D./(D<=epsilon);
D = min(D,INF);
warning on
end
D = min(D,D’); %% Make sure distance matrix is symmetric
if (overlay == 1)
E = int8(1-(DINF)); %% Edge information for subsequent graph overlay
end
% Finite entries in D now correspond to distances between neighboring points.
% Infinite entries (really, equal to INF) in D now correspond to
% non-neighoring points.
%%%%% Step 2: Compute shortest paths %%%%%
disp(‘Computing shortest paths…’);
% We use Floyd’s algorithm, which produces the best performance in Matlab.
% Dijkstra’s algorithm is significantly more efficient for sparse graphs,
% but requires for-loops that are very slow to run in Matlab. A significantly
% faster implementation of Isomap that calls a MEX file for Dijkstra’s
% algorithm can be found in isomap2.m (and the accompanying files
% dijkstra.c and dijkstra.dll).
tic;
for k=1:N
D = min(D,repmat(D(:,k),[1 N])+repmat(D(k,:),[N 1]));
if ((verbose == 1) & (rem(k,20) == 0))
disp([’ Iteration: ', num2str(k), ’ Estimated time to completion: ‘, num2str((N-k)*toc/k/60), ’ minutes’]);
end
end
%%%%% Remove outliers from graph %%%%%
disp(‘Checking for outliers…’);
n_connect = sum(~(D
INF)); %% number of points each point connects to
[tmp, firsts] = min(DINF); %% first point each point connects to
[comps, I, J] = unique(firsts); %% represent each connected component once
size_comps = n_connect(comps); %% size of each connected component
[tmp, comp_order] = sort(size_comps); %% sort connected components by size
comps = comps(comp_order(end?1));
size_comps = size_comps(comp_order(end?1));
n_comps = length(comps); %% number of connected components
if (comp>n_comps)
comp=1; %% default: use largest component
end
disp([’ Number of connected components in graph: ‘, num2str(n_comps)]);
disp([’ Embedding component ', num2str(comp), ’ with ‘, num2str(size_comps(comp)), ’ points.’]);
Y.index = find(firsts
comps(comp));
D = D(Y.index, Y.index);
N = length(Y.index);
%%%%% Step 3: Construct low-dimensional embeddings (Classical MDS) %%%%%
disp(‘Constructing low-dimensional embeddings (Classical MDS)…’);
opt.disp = 0;
[vec, val] = eigs(-.5
(D.^2 - sum(D.^2)’*ones(1,N)/N - ones(N,1)sum(D.^2)/N + sum(sum(D.2))/(N2)), max(dims), ‘LR’, opt);
h = real(diag(val));
[foo,sorth] = sort(h); sorth = sorth(end?1);
val = real(diag(val(sorth,sorth)));
vec = vec(:,sorth);
D = reshape(D,N^2,1);
for di = 1:length(dims)
if (dims(di)<=N)
Y.coords{di} = real(vec(:,1:dims(di)).
(ones(N,1)*sqrt(val(1:dims(di)))’))’;
r2 = 1-corrcoef(reshape(real(L2_distance(Y.coords{di}, Y.coords{di})),N2,1),D).2;
R(di) = r2(2,1);
if (verbose == 1)
disp([’ Isomap on ', num2str(N), ’ points with dimensionality ', num2str(dims(di)), ’ --> residual variance = ‘, num2str(R(di))]);
end
end
end
clear D;
%%%%%%%%%%%%%%%%%% Graphics %%%%%%%%%%%%%%%%%%
if (displ1)
%%%%% Plot fall-off of residual variance with dimensionality %%%%%
figure;
hold on
plot(dims, R, ‘bo’);
plot(dims, R, ‘b-’);
hold off
ylabel(‘Residual variance’);
xlabel(‘Isomap dimensionality’);
%%%%% Plot two-dimensional configuration %%%%%
twod = find(dims
2);
if ~isempty(twod)
figure;
hold on;
plot(Y.coords{twod}(1,:), Y.coords{twod}(2,:), ‘ro’);
if (overlay == 1)
plot(E(Y.index, Y.index), [Y.coords{twod}(1,:); Y.coords{twod}(2,:)]’);
title(‘Two-dimensional Isomap embedding (with neighborhood graph).’);
else
title(‘Two-dimensional Isomap.’);
end
hold off;
end
end
return;

另:想要跟大家交流一下,n_fcn应该如何定义。

Isomap算法的matlab实现相关推荐

  1. fcm算法的MATLAB实现,FCM算法的matlab程序(初步)

    FCM算法的matlab程序 1.采用iris数据库 iris_data.txt 5.1 3.5 1.4 0.2 4.9 3 1.4 0.2 4.7 3.2 1.3 0.2 4.6 3.1 1.5 0 ...

  2. 2018-4-8蚁群算法---包子阳《智能优化算法以及Matlab实现》第五章

    资料来源: <智能优化算法以及matlab实现>包子阳  余继周 编著 第五章-----蚁群算法 是一种元启发式优化算法(自己理解:就是作为群体的单位个体也就是元,在里面充当着随机的选择搜 ...

  3. matlab dfp法,DFP算法及Matlab程序.docx

    DFP算法及Matlab程序 作业二 用DFP算法求解,取,.一.求解:求迭代点x1令,得的极小值点,所以得:于是,由DFP修正公式有下一个搜索方向为求迭代点x2令,得的极小值点于是得:,所以:,因H ...

  4. matlab整定串级pid,PID算法在Matlab串级控制中的应用

    PID算法在Matlab串级控制中的应用 自114 1112002039 陈艳 前言:这个专题是由王娟老师给我们授课,我感觉收获挺大的,尤其是matlab仿真软件的使用,为我以后的实验课打下良好的基础 ...

  5. PSO-LSSVM算法及其MATLAB代码

    挺完整的一篇博客,这里转载记录一下. 原文链接:PSO-LSSVM算法及其MATLAB代码 一.PSO 1.概念 粒子群优化算法(PSO:Particle swarm optimization)是一种 ...

  6. matlab hist函数_算法工匠MATLAB专训营:Matlab绘图,小试牛刀

    作者 | 蔡老师 仿真秀专栏作者 首发 | 仿真秀平台 导读:正文之前,我在此详细说明一下,因为本文包含的程序太难得,网上肯定找不到这样的程序.随着讲课的越来越深入,我给出的程序会越来越实用,接近于实 ...

  7. matlab音频基频的提取,(620512681) 自相关基频提取算法的MATLAB实现

    第31卷总第80期 西北民族大学学报(自然科学版) V01.31.No.4 1 0年1 2 0 2月 Journal of Nonhw铭t University for Nationalities(N ...

  8. fdtd算法的matlab程序,FDTD算法的Matlab程序

    <FDTD算法的Matlab程序>由会员分享,可在线阅读,更多相关<FDTD算法的Matlab程序(6页珍藏版)>请在人人文库网上搜索. 1.* 5= T$h;O % 3-D ...

  9. hilbert曲线序编码matlab,Hilbert曲线扫描矩阵的生成算法及其MATLAB程序代码

    Hilbert曲线扫描矩阵的生成算法及其MATLAB程序代码 王笋,徐小双(华中科技大学控制科学与工程系,武汉 430074) 摘 要 Hilbert曲线是一种重要的图像处理工具,在图像处理,特别是图 ...

最新文章

  1. java调用python的函数_java如何调用python的.py文件,以及如何执行里面的函数,和创建...
  2. java同步通信方式_java多线程同步与通信示例(synchronized方式)
  3. C语言输出长方柱的体积,需要求3个长方柱的体积,请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、 height(高)。要求用成员函数实现以下功能...
  4. mysql能否在手机端运行_在手机上安装linux并部署mysql,jupyter用于数据探索
  5. python中event的用法_Python编程之event对象的用法实例分析
  6. 基于节点类的二叉树实现及部分操作函数
  7. 后缀自动机SAM详解
  8. 【ML小结11】高斯混合模型GMM
  9. MYSQL建立数据库的步骤
  10. linux命令之文件和目录操作
  11. android 国际电话区号,中国国际区号_电话区号_中国区号是多少-中国区号查询
  12. 名帖236 俞和 行书《次韵韩伯清见寄之什凡五首》
  13. python转json的函数_python将字符串转换成json的方法小结
  14. 1000句英语经典口语(10)
  15. ajax+JS实现分页
  16. Protocol Buffers和JSON相互转换
  17. 分布式数据库发展历程SequoiaDB 简介
  18. 游戏输入控制的五条黄金法则
  19. 计算机系过程控制专业毕业论文,计算机系毕业论文(范文).doc
  20. Markdown格式

热门文章

  1. 安全轻量化股票看盘盯盘软件需要实现的功能和基本要求是什么?
  2. python口令加密啥意思,什么是最安全的python“密码”加密
  3. Love Love Love
  4. 在Win8下无法拖动文件的解决办法
  5. 美国SigmasTek泰克免维护蓄电池的设计寿命_优点
  6. 2018创新创业赛事排行
  7. linux常用的快捷命令,linux 常用命令快捷键
  8. app.json中json注释问题
  9. 在华硕玩家国度魔霸新锐2021的Windows 11操作系统中禁用BitLocker设备加密
  10. div的onblur事件