/usr/share/octave/site/m/vlfeat/toolbox/demo/vl_demo_kmeans_ann_speed.m is in octave-vlfeat 0.9.17+dfsg0-6+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | % VL_DEMO_KMEANS_ANN_SPEED Compares Lloyd's, Elkan, and ANN k-means
numCenters = 200 ;
numTrials = 3 ;
maxNumIterations = 10 ;
initialization = 'randsel' ;
%initialization = 'plusplus';
distance = 'l2' ;
%% Create an example dataset
dimension = 32 ;
numData = 50000 ;
X = randn(dimension,numData);
%% Run various k-means algorithms on the data
algorithms = {'Lloyd','Elkan','ANN 1/4','ANN 1/10','ANN 1/50' } ;
options = {{'Algorithm', 'Lloyd'}, ...
{'Algorithm', 'Elkan'}, ...
{'Algorithm', 'ANN', 'MaxNumComparisons', ceil(numCenters / 4)}, ...
{'Algorithm', 'ANN', 'MaxNumComparisons', ceil(numCenters / 10)}, ...
{'Algorithm', 'ANN', 'MaxNumComparisons', ceil(numCenters / 50)}} ;
numCpus = [1 0] ;
clear time energy ;
for n = 1:2
for a = 1:numel(algorithms)
for t = 1:numTrials
vl_threads(numCpus(n)) ;
start = tic ;
[C, A, E] = vl_kmeans(X, ...
numCenters, 'Verbose', ...
'Distance', distance, ...
'MaxNumIterations', maxNumIterations, ...
options{a}{:}) ;
if vl_isoctave()
time(t,a,n) = (tic() - start) / 1e6 ;
else
time(t,a,n) = toc(start) ;
end
energy(t,a,n) = E ;
end
end
end
% average over tirals
time = squeeze(mean(time,1)) ;
energy = squeeze(mean(energy,1)) ;
figure(1) ; clf ;
for n=1:2
if n == 1
str = 'Serial' ;
else
str = 'Parallel' ;
end
subplot(3,2,(n-1)+1) ;
bar(time(:,n)) ;
set(gca,'XTickLabel',algorithms);
set(gca,'FontSize',8),
xlabel('Algorithm');
ylabel('Time [s]');
title(str) ;
subplot(3,2,(n-1)+3) ;
bar(energy(:,n));
set(gca,'XTickLabel',algorithms);
set(gca,'FontSize',8),
xlabel('Algorithm');
ylabel('Energy');
title(str) ;
subplot(3,2,(n-1)+5) ;
bar(time(1,1)./time(:,n)) ;
set(gca,'XTickLabel',algorithms);
set(gca,'FontSize',8),
xlabel('Algorithm');
ylabel('Speedup');
title(str) ;
end
vl_demo_print('kmeans_speed',1);
|