-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsomrowdtw.m
106 lines (82 loc) · 3.23 KB
/
somrowdtw.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
%INIT
clear;
%load('\\10.50.128.199\store\projects\SKILLS\ROW\ML\Energy analysis\Sessions\session_2_2.mat');
%load('\\10.50.128.199\store\projects\SKILLS\ROW\ML\Energy analysis\Sessions\energies_2_2.mat');
load('session_1_2.mat');
load('energies_1_2.mat');
is_map = 0;
recordstart = 0;
thisstroke = [];
sprint = session.sprint;
labellist = genvarname(labels(sprint));
for k = 1:32
temp = data(sprint);
eval([labellist{k} '= temp(k,:);']);
end
varmax = 0.01;
nrnodes = 50;
%Run data with classification
for tpos = 2000:(length(energy.phases))
if((energy.phases(tpos-1) == 4) && (energy.phases(tpos) == 1))
if length(thisstroke) >= nrnodes
if recordstart == 0
recordstart = 1;
else
if is_map == 0;
%Init som
somlength = length(thisstroke);
map = somdtw(thisstroke, nrnodes);
map.wl = 30;
map.ewmal = 0.96;
map.lr = 0.03;
clf;
scatter(map.nodes(1,:), map.nodes(2,:)), hold on;
plot(thisstroke(1,:), thisstroke(2,:));
axis([0, 0.5, -1.2, 0.8]);
pause(0.01);
end
%Save stroke and train
map = map.add(thisstroke);
for ii = 1:1
map = map.adaptDTW(2);
map = map.adapt(10);
end
is_map = 1;
clf;
plot(thisstroke(1,:), thisstroke(2,:)), hold on;
scatter(map.nodes(1,:), map.nodes(2,:),'b');
length(thisstroke(1,:))
for i = 1:(map.nrnodes-1)
varmax = max(map.segvar);
varmin = min(map.segvar);
vardelta = varmax-varmin;
colour = [max(min( ((map.segvar(i)-varmin)/vardelta)^(1/2),1),0), 0,0];
thisplot = plot([map.nodes(1,i),map.nodes(1,i+1)], [map.nodes(2,i),map.nodes(2,i+1)]);
set(thisplot,'Color', colour, 'LineWidth',3);
end
axis([0, 0.5, -1.2, 0.8]);
pause(0.001);
end
end
%Start new stroke
thisstroke = [];
end
thisstroke = [thisstroke,[L_alpha(tpos),L_phi(tpos)]'];
end
for i = 1:1
clf;
map.lr = 0.001;
map = map.adaptDTW(75);
plot(thisstroke(1,:), thisstroke(2,:));
scatter(map.nodes(1,:), map.nodes(2,:), 'b'), hold on;
for i = 1:(map.nrnodes-1)
varmax = max(map.segvar);
varmin = min(map.segvar);
vardelta = varmax-varmin;
colour = [max(min( ((map.segvar(i)-varmin)/vardelta)^(1/2),1),0), 0,0];
thisplot = plot([map.nodes(1,i),map.nodes(1,i+1)], [map.nodes(2,i),map.nodes(2,i+1)]), hold on;
set(thisplot,'Color', colour, 'LineWidth',3);
end
axis([0, 0.5, -1.2, 0.8]);
pause(0.01);
end