-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimecorr.asv
62 lines (57 loc) · 1.4 KB
/
timecorr.asv
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
% timecorr
clc;clear;close all;
%% Read data
[ym,labels,data]=read_binary_data(); % read data and labels
numLabels=numel(unique(labels));
% sampling
sampleRate = 1;
[y,ym,dataLength]=sampleData(ym,sampleRate);
[yy,yms]=sortdata(ym,labels); % sort data according to labels
%% Cross Validation
crossIdx=crossvalind('Kfold',size(ym,2),10);
GRlabels=[];
TTlabels=[];
for k=1:10
% Training
ytrain=ym(:,crossIdx~=k);
trainLabels=labels(:,crossIdx~=k);
for i=1:numLabels
template(:,i)=mean(ytrain(:,trainLabels==i),2);
end
% Testing
ytest=ym(:,crossIdx==k);
testLabels=labels(crossIdx==k);
lb=zeros(size(testLabels));
for i=1:size(ytest,2)
d_all=sum((repmat(ytest(:,i),1,numLabels)-template).^2);
[Y,I]=min(d_all);
lb(i)=I;
end
GRlabels=[GRlabels testLabels];
TTlabels=[TTlabels lb];
end
%% Display results
[GRlabels;TTlabels]
precisionMat=zeros(numLabels);
for j=1:numLabels
for i=1:numLabels
precisionMat(i,j)=nnz(TTlabels(GRlabels==j)==i)/nnz(GRlabels==j);
end
end
precisionMat
% for ind=1:266
% ytest=data(ind+16662:ind+16662+266-1,2);
% d_all=sum((repmat(ytest,1,numLabels)-template).^2);
% [Y,I]=min(d_all);
% result(ind)=I;
% end
% result
% sum(result==3)
ytest=ym;
ytest=
for i=1:size(ytest,2)
d_all=sum((repmat(ytest(:,i),1,numLabels)-template).^2);
[Y,I]=min(d_all);
lb(i)=I;
end
sum(lb==labels)/260