Skip to content

Commit

Permalink
validate the recognition codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffsan committed Nov 23, 2017
1 parent 1f1c3b6 commit 7023cd5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
15 changes: 8 additions & 7 deletions recognition/activity_recognition.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
lambda = 0.0015;
sigma = 1;
end

sequence = 76:125;

disp('running recognition...')
sequence = 76:125; % remove first 75 unstable points, cannot be larger, or Index exceeds matrix dimensions
time_kcc = zeros(13,1);
time_dtw = zeros(13,1);

Expand Down Expand Up @@ -37,7 +38,6 @@
time_kcc(activity_test) = time_kcc(activity_test) + toc;

tic
% distance(subject, 5*(activity-1)+ samples, 5*(activity_test-1)+ samples_test) = 0;
distance(subject, 5*(activity-1)+ samples, 5*(activity_test-1)+ samples_test) = dtw(train', test');
time_dtw(activity_test) = time_dtw(activity_test) + toc;
end
Expand All @@ -49,9 +49,10 @@
time_use = [time_kcc, time_dtw];
filename = 'results.mat';
save(filename, 'response', 'distance', 'time_use');
[accuracy_kcc, accuracy_dtw] = show_results(filename);
results = [accuracy_dtw, accuracy_kcc, time_dtw, time_kcc, sigma, lambda];
fprintf('accuracy_dtw: %f; accuracy_kcc: %f; time_dtw: %f, time_kcc: %f; sigma: %f lambda: %f\n', ...
disp('Saved results to results.mat')
[accuracy_kcc, accuracy_dtw] = show_results();
results = [accuracy_dtw, accuracy_kcc, sum(time_dtw), sum(time_kcc), sigma, lambda];
fprintf('accuracy_dtw: %f; accuracy_kcc: %f; time_dtw: %f s, time_kcc: %f s; sigma: %f lambda: %f\n', ...
results(1), results(2), results(3), results(4), results(5), results(6));

disp('Done.')
end
17 changes: 0 additions & 17 deletions recognition/comparison_results.txt

This file was deleted.

24 changes: 24 additions & 0 deletions recognition/data_conversion.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
%
folder = './WARD1.0/';
addpath('./natsortfiles/')

if ~(7==exist(folder,'dir'))
url = 'https://people.eecs.berkeley.edu/~yang/software/WAR/WARD1.zip';
filename = 'WARD1.zip';
disp('Downloading database...')
websave(filename,url);
disp('Extracting files...')
try
unzip(filename, '.');
catch err
disp('Unable to upzip, you may need to download/unzip the database to currently folder manually via link:')
disp(url)
return
end
disp('Extracted.')
end

if (7==exist(folder,'dir'))
disp('Data Conversion...')
else
return
end

files = dir(folder);
fileIndex = find([files.isdir]);
fileIndex = fileIndex(3:end);
Expand Down Expand Up @@ -38,4 +61,5 @@
end

save('data.mat', 'data');
disp('Done. Saved to data.mat')
clear
6 changes: 6 additions & 0 deletions recognition/run_me.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

data_conversion; % convert database to compatible format

activity_recognition; % run recognition demo and show results

%% you may also run show_example after running data_conversion to visulize the signals.
5 changes: 3 additions & 2 deletions recognition/show_results.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@
accuracy_dtw = trace(sum_blocks(fusion_matrix_dtw, 5, 5))/sum(fusion_matrix_dtw(:));

if nargin < 1
fprintf('accuracy kcc: %f; dtw: %f', accuracy_kcc, accuracy_dtw);
fprintf('accuracy kcc: %f; dtw: %f\n', accuracy_kcc, accuracy_dtw);
end

table_comparison = ...
[diag(sum_blocks(fusion_matrix_kcc, 5, 5)./200)*100,...
diag(sum_blocks(fusion_matrix_dtw, 5, 5)./200)*100, results.time_use/65/65*1000*1000];

table_comparison = [table_comparison; mean(table_comparison)]
table_comparison = [table_comparison; mean(table_comparison)];

matrix2latex(table_comparison, 'comparison_results.txt');
% disp('Saved results table to Latex codes into comarison_results.txt')

function out = sum_blocks(A, block_nrows, block_ncols)
out = squeeze(sum(reshape(sum(reshape(A,block_nrows,[])),...
Expand Down

0 comments on commit 7023cd5

Please sign in to comment.