-
Notifications
You must be signed in to change notification settings - Fork 1
/
testcoe.m
200 lines (162 loc) · 4.75 KB
/
testcoe.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
global PNUM;
PNUM = 6;
debug = 0;
NORM = 1; %flag=1 normalise for hip centroid
%Hip centre is first joint
for i=1:PNUM
path = ['C:\Users\liam\Desktop\KINECT\kbox\data\freshdata\' num2str(i) '\'];
%path = ['C:\Users\liam\Desktop\KINECT\kbox\data\1\'];
%path = ['C:\Users\liam\Desktop\KINECT\kbox\data\jabtest\' num2str(i) '\'];
data = loadKinectData(path,NORM); %flag=1 normalise for hip centroid
%data = diff(data,1,2); %Columnwise Differentiation - Remove effect of distance from Kinect
dataAll(i).data = data;
%dataAll(i).labels to do
if 0
close all
for i=1:size(data,2)
cla
a = data(:,i);
for j=1:3:length(a)
plot3(a(j),a(j+2),a(j+1),'.');
hold on
end
set(gca,'XLim',[-1 1]);
set(gca,'YLim',[-1 1]);
set(gca,'ZLim',[-1 1]);
pause
end
end
end
% Big data matrix
M=[];
for i = 1:length(dataAll(i))
M = [M, dataAll(i).data];
end
[Xm1,EV1,Ev1]=createES(M,3); %Create Eigenspace., New data !contribute to eigenspace
%close all
for i=1:PNUM
dataAll(i).jred=reconstructPose(dataAll(i).data,Xm1,EV1);
dataAll(i).jredSmooth = kinsmooth2(dataAll(i).jred);
[valmax,imax,valmin, imin] = getminmax(dataAll(i).jredSmooth(1,:),i,NORM);
% distance = pythagoras(sort(imax)); Going to put in getminmax
[dataAll(i).imax, a]= sort(imax);
end
F=[];
S=[];
for i = 1:length(dataAll(i))
F = [F, dataAll(i).jred];
S = [S, dataAll(i).jredSmooth];
end
%DRcomp(dataAll(1).jredSmooth());
% for i=1:PNUM
% figure
% hold on;
% plot(dataAll(i).jred(1,:),'-r');
% %plot(M(1,:),'y');
% %plot(dataAll(i).jred(1,:),'b');
% %plot(dataAll(i).imax, dataAll(i).jred(1,dataAll(i).imax),'.g');
% end
%
% for i=1:PNUM
% figure
% hold on;
% % plot(dataAll(i).jred(1,:),'-r');
% plot(dataAll(i).jredSmooth(1,:),'b');
% plot(dataAll(i).imax, dataAll(i).jredSmooth(1,dataAll(i).imax),'.g');
% end
% figure
% hold on
% plot(dataAll(4).jred(1,:),'-r');
% plot(dataAll(4).jredSmooth(1,:),'b');
% plot(dataAll(4).imax, dataAll(4).jredSmooth(1,dataAll(4).imax),'.g');
tilefigs();
pause;
close all;
nsamples = 15;
ncomponents = 3;
X = [];
Y = [];
lbl = [];
%close all
for i=1:PNUM
nelem = length(dataAll(i).imax);
dataAll(i).labels = ones(nelem,1) * i;
dataAll(i).features = zeros(nelem,nsamples * ncomponents);%HERE
for j = 1:nelem - 1
inds = round(linspace(dataAll(i).imax(j), dataAll(i).imax(j+1), nsamples));
%dataAll(i).features(j,:) = dataAll(i).jred(1,inds);
foo = dataAll(i).jred(1:ncomponents,inds);%HERE
dataAll(i).features(j,:) = foo(:);%HERE
if debug
plot(dataAll(i).features(j,:))
pause
end
end
X = [X;dataAll(i).features];
Y = [Y;dataAll(i).labels];
lbl = [lbl;ceil(0.2*(length(dataAll(i).labels)))]; %for labels
%lbl = ceil(lbl);
end
trainPercent = 0.8;
trainInds = randperm(length(Y));
trainInds(round(length(Y)*0.8):end) = [];
testInds = 1:length(Y);
testInds(trainInds) = [];
%'autoscale' is true by default 'kernel_function' 'rbf'
% svmStruct = svmtrain(X(trainInds,:),Y(trainInds),'kernel_function', 'rbf','autoscale','true');
svmStruct = svmtrain(Y(trainInds),X(trainInds,:),['-b 1']);
%labels = zeros(182,1);
[predicted_label, accuracy, probest] = svmpredict(Y(testInds),X(testInds,:),svmStruct,['-b 1']);
%close all
%%
%Random forest label generation.
testlabels = [];
for i=1:6 %should be 6
temp = repmat(dataAll(i).labels(i,1),lbl(i,1),1);
testlabels = vertcat(testlabels,temp);
end
%NVarToSample, 'all' deciscion tree, otherwise random forest
%X = M'; %Changed this, this is full pose pose.
B = TreeBagger(75,X(trainInds,:),Y(trainInds),'OOBPred','On');
C = B.predict(X(testInds,:));
C = cellfun(@str2num,C);
testlabels(end,:) = [];
diff = size(testlabels,1) - size(C,1);
if diff < 0
for i=1:abs(diff)
testlabels = vertcat(testlabels,6);
end
end
if diff > 0
testlabels(end-(diff-1):end,:) = [];
end
chklbl = horzcat(testlabels,C);
count=0;
for i=1:length(C)
if chklbl(i,1) == chklbl(i,2)
count = count+1;
end
end
correct = (count/length(C))*100;
sprintf('Random Forest Correct: %f%%', correct)
X = X';
for i=1:length(X)
drel(i) = dtw(X(:,1),X(:,i));
end
% close all
%Diffusion Maps
%dtw
close all
mappedX = diffusion_maps(X,3,1,1);
%mappedA = compute_mapping(A, type, no_dims, parameters)
% C = svmclassify(svmStruct,X(testInds,:),'showplot',true);
%[C, Y(testInds)]
% ty = Y(testInds);
% count = 0;
% for i=1:length(C)
% if C(i) == ty(i)
% count = count+1;
% end
% end
% correct = (count/length(C))*100
% sprintf('Correct: %f%%', correct)