-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_toolbox.m
149 lines (133 loc) · 5.22 KB
/
test_toolbox.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function test_toolbox
%TEST_TOOLBOX Tests all functionalities of the dimension reduction toolbox
%
% test_toolbox
%
% Tests all functionalities of the dimension reduction toolbox.
%
%
% This file is part of the Matlab Toolbox for Dimensionality Reduction.
% The toolbox can be obtained from http://homepage.tudelft.nl/19j49
% You are free to use, change, or redistribute this code in any way you
% want for non-commercial purposes. However, it is appreciated if you
% maintain the name of the original author.
%
% (C) Laurens van der Maaten, Delft University of Technology
% Generate data
disp('Testing data generation functions...');
datasets = {'helix', 'twinpeaks', '3d_clusters', 'intersect', 'swiss'};
for i=1:length(datasets)
try
X = generate_data(datasets{i}, 500);
catch e
disp(e);
warning(['Generation of data set ' datasets{i} ' failed! Press any key to continue tests...']);
pause
end
end
% Test prewhitening
disp('Testing prewhitening...');
try
X = prewhiten(X);
catch e
disp(e);
warning('Prewhitening failed! Press any key to continue tests...');
pause
end
unscaled_X = X;
X = X - min(X(:));
X = X / max(X(:));
% Test all intrinsic dimensionality estimators
disp('Testing intrinsic dimensionality estimators...');
techniques = {'CorrDim', 'NearNbDim', 'GMST', 'PackingNumbers', 'EigValue', 'MLE'};
for i=1:length(techniques)
try
intrinsic_dim(X, techniques{i});
catch e
disp(e);
warning(['Intrinsic dimensionality estimation using ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
end
% Test all unsupervised dimension reduction techniques
disp('Testing dimensionality reduction techniques...');
techniques = {'PCA', 'MDS', 'ProbPCA', 'FactorAnalysis', 'GPLVM', 'Sammon', 'Isomap', ...
'LandmarkIsomap', 'LLE', 'Laplacian', 'HessianLLE', 'LTSA', 'MVU', 'CCA', 'LandmarkMVU', ...
'FastMVU', 'DiffusionMaps', 'KernelPCA', 'GDA', 'SNE', 'SymSNE', 'tSNE', 'LPP', 'NPE', ...
'LLTSA', 'SPE', 'Autoencoder', 'LLC', 'ManifoldChart', 'CFA'};
for i=1:length(techniques)
% Test the dimension reduction technique
try
if any(strcmpi(techniques{i}, {'GPLVM', 'CFA'}))
[mappedX, mapping] = compute_mapping(unscaled_X, techniques{i}, 2);
else
[mappedX, mapping] = compute_mapping(X, techniques{i}, 2);
end
if any(strcmpi(techniques{i}, {'Isomap', 'LandmarkIsomap', 'LLE', 'Laplacian', 'MVU', 'CCA', 'FastMVU', 'LPP', 'NPE', 'LLTSA'}))
[mappedX, mapping] = compute_mapping(X, techniques{i}, 2, 'adaptive');
end
catch e
disp(e);
warning(['Technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
% Test the out-of-sample extension code
if any(strcmpi(techniques{i}, {'PCA', 'LPP', 'NPE', 'LLTSA', 'SPCA', 'PPCA', 'FA'}))
try
out_of_sample(X, mapping);
catch e
disp(e);
warning(['Out-of-sample extension for technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
end
% Test reconstruction code
if any(strcmpi(techniques{i}, {'PCA', 'LPP', 'NPE', 'LLTSA', 'SPCA', 'PPCA', 'FA', 'Autoencoder'}))
try
reconstruct_data(mappedX, mapping);
catch e
disp(e);
warning(['Reconstruction for technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
end
end
% Test approximate out-of-sample function
try
out_of_sample_est(X, X, mappedX);
catch e
disp(e);
warning(['Approximate out-of-sample extension failed! Press any key to continue tests...']);
pause
end
% Test all supervised dimension reduction techniques
labels = double(X(:,1) > .5) + 1;
X = [labels X];
techniques = {'LDA', 'NCA', 'MCML', 'LMNN'};
for i=1:length(techniques)
% Test the actual technique
try
[mappedX, mapping] = compute_mapping(X, techniques{i}, 2);
catch e
disp(e);
warning(['Technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
% Test out-of-sample extension
try
out_of_sample(X(:,2:end), mapping);
catch e
disp(e);
warning(['Out-of-sample extension for technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
% Test reconstruction code
try
reconstruct_data(mappedX, mapping);
catch e
disp(e);
warning(['Reconstruction for technique ' techniques{i} ' failed! Press any key to continue tests...']);
pause
end
end
disp('All tests completed!');