-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtutorial_mmds_failed.m
63 lines (52 loc) · 1.81 KB
/
tutorial_mmds_failed.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
% A. M. Bronstein, M. M. Bronstein, R. Kimmel, Numerical geometry of
% non-rigid shapes, Springer, 2008
%
% http://tosca.cs.technion.ac.il/book
%
% TUTORIAL
% Demonstration of multidimensional scaling using SMACOF algorithm
% with multigrid acceleration
%
% This tutorial is based on MDS RRE code, distributed as part of
% TOSCA = Toolbox for Surface Comparison and Analysis
% Web: http://tosca.cs.technion.ac.il
%
% (C) Copyright Michael Bronstein, 2008
% All rights reserved.
% load and display Swiss roll dataset
load swissroll
figure(1), trisurf(swiss.TRIV,swiss.X,swiss.Y,swiss.Z); axis image;
title('Swiss roll surface');
drawnow
% embed using SMACOF
disp('Embedding the intrinsic geometry of the Swiss roll swiss into R^3 using SMACOF (no acceleration)...')
options.X0 = [swiss.X,swiss.Y,swiss.Z];
options.method = 'smacof';
options.xhistory = 'on';
[X_smacof,hist_smacof] = mds(swiss.D,options);
pause;
% load multigrid matrices
load mg_matrices
% embed using SMACOF with multigrid
disp('Embedding the intrinsic geometry of the Swiss roll swiss into R^3 using SMACOF with MG acceleration...')
options.method = 'mg';
options.atol = hist_smacof.s(end); % stop when reaching the same stress as SMACOF
options.DOWNMTX = DOWNMTX;
options.UPMTX = UPMTX;
options.IND = IND;
[X_mg,hist_mg] = mds(swiss.D,options);
pause
% show result at each iteration
for k = 1:length(hist_mg.time),
figure(2), trisurf(swiss.TRIV,hist_mg.X{k}(:,1),hist_mg.X{k}(:,2),hist_mg.X{k}(:,3)); axis image;
title(sprintf('Iteration %d, Stress=%g',k,hist_smacof.s(k)));
drawnow
pause(0.25);
end
pause;
% plot convergence
figure(3), semilogy(cumsum(hist_smacof.time),hist_smacof.s,'k:',...
cumsum(hist_mg.time),hist_mg.s,'r');
xlabel('CPU time (sec)'); ylabel('stress');
title('Convergence speed');
legend('SMACOF','MG');