-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JeffsanC
committed
Nov 23, 2017
1 parent
09612b5
commit 1141737
Showing
18 changed files
with
1,461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
WARD1.0 | ||
*.asv | ||
data.mat | ||
results.mat | ||
performances.mat | ||
*.mat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function results = activity_recognition(lambda, sigma) | ||
close all | ||
load('data.mat'); | ||
|
||
if nargin < 2 | ||
lambda = 0.0015; | ||
sigma = 1; | ||
end | ||
|
||
sequence = 76:125; | ||
time_kcc = zeros(13,1); | ||
time_dtw = zeros(13,1); | ||
|
||
%% examples | ||
for subject = 1:size(data,1) | ||
for activity = 1:size(data, 2) | ||
for samples = 1:5%size(data, 3) %only one subject has the 6th sample in only one activity | ||
if isempty(data{subject, activity, samples}) | ||
continue; | ||
end | ||
|
||
train = data{subject, activity, samples}(sequence, :); | ||
tic | ||
correlator = kcc_train(train, lambda, sigma); | ||
time_kcc(activity) = time_kcc(activity) + toc; | ||
|
||
for activity_test = 1:size(data, 2) | ||
for samples_test = 1:5%size(data, 3) %only one subject has the 6th sample in only one activity | ||
if isempty(data{subject, activity_test, samples_test}) | ||
continue; | ||
end | ||
|
||
test = data{subject, activity_test, samples_test}(sequence, :); | ||
|
||
tic | ||
response(subject, 5*(activity-1)+ samples, 5*(activity_test-1)+ samples_test) = kcc(test, correlator); | ||
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 | ||
end | ||
end | ||
end | ||
end | ||
|
||
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', ... | ||
results(1), results(2), results(3), results(4), results(5), results(6)); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
% clc | ||
% clear | ||
load('performances_refine_refin.mat'); | ||
plot3(performances(:,end-1), performances(:,end), performances(:,2),'.') | ||
performances(:,[end-1,end,2]) | ||
max(performances(:,2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
\begin{tabular}{|l|l|l|l|} | ||
\hline | ||
74&63.5&119.0911&161.0318\\\hline | ||
75.5&66&116.525&156.9842\\\hline | ||
72&72.5&116.66&157.161\\\hline | ||
96&87&116.6862&157.8734\\\hline | ||
93&80&116.7369&157.3694\\\hline | ||
94.5&84&113.9792&153.9453\\\hline | ||
95.5&80&115.4979&155.2064\\\hline | ||
95&83&116.6258&157.0647\\\hline | ||
94.5&80&116.5067&157.0048\\\hline | ||
99.5&79&116.4776&157.2347\\\hline | ||
100&95&116.5865&157.0245\\\hline | ||
97&86&116.4139&157.0018\\\hline | ||
92.5&69&115.3224&155.4016\\\hline | ||
90.6923&78.8462&116.393&156.9464\\\hline | ||
\end{tabular} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
clear; clc | ||
% You need to download the WARD dataset to current folder. | ||
% | ||
folder = './WARD1.0/'; | ||
addpath('./natsortfiles/') | ||
files = dir(folder); | ||
fileIndex = find([files.isdir]); | ||
fileIndex = fileIndex(3:end); | ||
files = files(fileIndex); | ||
data={}; | ||
|
||
files = natsortfiles({files(:).name}); | ||
|
||
for i = 1:length(files) | ||
subfolder = files(i); | ||
matfolders = dir(strcat(folder,subfolder{1})); | ||
matIndex = find(~[matfolders.isdir]); | ||
matfolders = matfolders(matIndex); | ||
matfolder_files = natsortfiles({matfolders(:).name}); | ||
|
||
for j = 1:length(matfolder_files) | ||
matfiles = matfolder_files(j); | ||
filename = strcat(folder, subfolder,'/',matfiles{1}); | ||
wd = load(filename{1}); | ||
reading=[]; | ||
for k=1:5 | ||
col = wd.WearableData.Reading{k}; | ||
col(isinf (col))=0; | ||
col(isnan (col))=0; | ||
tran = col-mean(col); | ||
reading = [reading, tran./2./max(abs(tran))+0.5]; | ||
reading(isnan(reading))=0; | ||
end | ||
number = sscanf(filename{1},'./WARD1.0/Subject%d/a%dt%d.mat'); | ||
data{number(1),number(2), number(3)} = reading; | ||
% data{i,j}.name = filename; | ||
end | ||
end | ||
|
||
save('data.mat', 'data'); | ||
clear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
clc | ||
clear | ||
lambda = 0.0014:0.0001:0.0020; | ||
sigma = 0.5:0.1:1.1; | ||
|
||
performances=[]; | ||
for i = 1:numel(lambda) | ||
for j = 1:numel(sigma) | ||
performance = activity_recognition(lambda(i), sigma(j)); | ||
performances = [performance; performances]; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function kf = gaussian_kernel(xf, yf, sigma) | ||
% Calculating the gaussian kernel vertor | ||
% Copyright Wang Chen, Nanyang Technoglogical University | ||
|
||
N = numel(xf); | ||
xx = xf(:)' * xf(:) / N; | ||
yy = yf(:)' * yf(:) / N; | ||
xy = mean((ifft(xf .* conj(yf))),2); | ||
kf = exp(-1 / sigma^2 * (xx + yy - 2 * xy) / N); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function [response, output] = kcc(test, correlator) | ||
% Calculating the response | ||
% Copyright Wang Chen, Nanyang Technoglogical University | ||
test_fft = fft(test); | ||
kernel_fft = fft(gaussian_kernel(test_fft, correlator.sample_fft, correlator.sigma)); | ||
output = abs(ifft(correlator.correlator_fft.*kernel_fft)); | ||
response = max(output);%/sum(output); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function correlator = kcc_train(sample, lambda, sigma) | ||
% Training the correlator based on one sample | ||
% Copyright Wang Chen, Nanyang Technoglogical University | ||
if nargin < 3 | ||
sigma = 0.3; | ||
end | ||
if nargin < 2 | ||
lambda = 0.1; | ||
end | ||
|
||
correlator.sigma = sigma; | ||
target_fft = ones(size(sample,1),1); | ||
correlator.sample_fft = fft(sample); | ||
kernel_fft = fft(gaussian_kernel(correlator.sample_fft, correlator.sample_fft, correlator.sigma)); | ||
correlator.correlator_fft = target_fft./(kernel_fft + lambda); | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Copyright (c) 2009, Moritz Koehler | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
Oops, something went wrong.