This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_distributions.m
196 lines (175 loc) · 5.86 KB
/
plot_distributions.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
%% Statistics of MS2
fig = figure;
ax = [];
ax(1) = subplot(cols+1,1,1); plot(data); title('DATA', 'FontWeight', 'bold', 'FontSize', 11)
colors = get(gca,'ColorOrder');
number_of_colors = size(colors,1);
for i=1:cols
ax(i+1) = subplot(cols+1,1,i+1);
if i>number_of_colors
c = mod(i,number_of_colors);
else
c = i;
end
plot(statistic_ms2{i}, 'Color', colors(c,:), 'LineWidth', 1.5)
title(sprintf('Sensor %i', i), 'FontWeight', 'bold', 'FontSize', 11)
end
linkaxes(ax,'x');
axis tight
%% Statistics of methods
fig = figure;
ax = [];
num_methods = 6;
ax(1) = subplot(num_methods,1,1); plot(data); title('DATA', 'FontWeight', 'bold', 'FontSize', 11)
ax(2) = subplot(num_methods,1,2); plot(statistic_mei, 'LineWidth', 1.5); title('MEI', 'FontWeight', 'bold', 'FontSize', 11)
ax(3) = subplot(num_methods,1,3); plot(statistic_tv, 'LineWidth', 1.5); title('TV', 'FontWeight', 'bold', 'FontSize', 11)
ax(4) = subplot(num_methods,1,4); plot(statistic_xs1, 'LineWidth', 1.5); title('XS1', 'FontWeight', 'bold', 'FontSize', 11)
ax(5) = subplot(num_methods,1,5); plot(statistic_xs2, 'LineWidth', 1.5); title('XS2', 'FontWeight', 'bold', 'FontSize', 11)
%ax(6) = subplot(8,1,6); plot(statistic_zh, 'LineWidth', 1.5); title('ZH', 'FontWeight', 'bold', 'FontSize', 11)
ax(6) = subplot(num_methods,1,6); plot(statistic_ms, 'LineWidth', 1.5); title('SGZ', 'FontWeight', 'bold', 'FontSize', 11)
%ax(8) = subplot(8,1,8); plot(statistic_ms2_active, 'LineWidth', 1.5); title('MS2', 'FontWeight', 'bold', 'FontSize', 11)
linkaxes(ax,'x');
axis tight
%% Historical weights
fig = figure;
ax = [];
plot_cols = ceil(sqrt(cols+1));
ax(1) = subplot(plot_cols,plot_cols,1:plot_cols); plot(data); title('DATA', 'FontWeight', 'bold', 'FontSize', 11)
colors = get(gca,'ColorOrder');
number_of_colors = size(colors,1);
for i=1:cols
ax(i+1) = subplot(plot_cols,plot_cols,i+plot_cols);
if i>number_of_colors
c = mod(i,number_of_colors);
else
c = i;
end
area(historicalWeights(:,i), 'FaceColor', colors(c,:))
title(sprintf('Sensor %i', i), 'FontWeight', 'bold', 'FontSize', 11)
end
linkaxes(ax,'x');
axis tight
%% Correlation over time
k=500;
correlations = [];
for t=1:rows
if t<=k
c = ones(1,cols);
else
c = sum(corr(data(t-k:t,:)))/cols;
end
correlations = [correlations
c];
end
fig = figure;
ax = [];
for i=1:cols
ax(i) = subplot(cols, 1, i);
plot(correlations(:,i))
end
linkaxes(ax,'x');
axis tight
%% Thresholds
sensor = 1;
range = 1:TRAINING_WINDOW;
fig = figure;
ax = [];
rows = range(end);
ax(1) = subplot(3,2,1);
hold on
title('median +- 3*1.4826*MAD')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit(sensor) upperLimit(sensor)])
line([1 rows], [innerLimit(sensor) innerLimit(sensor)])
hold off
ax(2) = subplot(3,2,2);
hold on
title('median +- 3*MAD')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_hampel(sensor) upperLimit_hampel(sensor)])
line([1 rows], [innerLimit_hampel(sensor) innerLimit_hampel(sensor)])
hold off
ax(3) = subplot(3,2,3);
hold on
title('mean +- 3*std')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_standard(sensor) upperLimit_standard(sensor)])
line([1 rows], [innerLimit_standard(sensor) innerLimit_standard(sensor)])
hold off
ax(4) = subplot(3,2,4);
hold on
title('median +- 3*std')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_mix1(sensor) upperLimit_mix1(sensor)])
line([1 rows], [innerLimit_mix1(sensor) innerLimit_mix1(sensor)])
hold off
ax(5) = subplot(3,2,5);
hold on
title('mean +- 3*MAD')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_mix2(sensor) upperLimit_mix2(sensor)])
line([1 rows], [innerLimit_mix2(sensor) innerLimit_mix2(sensor)])
hold off
ax(6) = subplot(3,2,6);
hold on
title('mean +- 3*std (from gmdistribution)')
upperLimit_gm = mean_vector_active + 3*std_vector_active;
innerLimit_gm = mean_vector_active - 3*std_vector_active;
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_gm(sensor) upperLimit_gm(sensor)])
line([1 rows], [innerLimit_gm(sensor) innerLimit_gm(sensor)])
hold off
linkaxes(ax,'x');
axis tight
%% Two thresholds
sensor = 4;
range = 1:TRAINING_WINDOW;
range_test = TRAINING_WINDOW+1:size(data,1);
fig = figure;
ax = [];
rows = range(end);
ax(1) = subplot(2,2,1);
hold on
title('TRAINING ---- median +- 3*1.4826*MAD')
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit(sensor) upperLimit(sensor)])
line([1 rows], [innerLimit(sensor) innerLimit(sensor)])
hold off
ax(2) = subplot(2,2,2);
hold on
title('TRAINING ---- mean +- 3*std (from gmdistribution)')
upperLimit_gm = mean_vector_active(sensor) + 3*std_vector_active(sensor);
innerLimit_gm = mean_vector_active(sensor) - 3*std_vector_active(sensor);
plot(data(range,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_gm upperLimit_gm])
line([1 rows], [innerLimit_gm innerLimit_gm])
hold off
ax(1) = subplot(2,2,3);
hold on
title('TEST ---- median +- 3*1.4826*MAD')
plot(data(range_test,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit(sensor) upperLimit(sensor)])
line([1 rows], [innerLimit(sensor) innerLimit(sensor)])
hold off
ax(2) = subplot(2,2,4);
hold on
title('TEST ---- mean +- 3*std (from gmdistribution)')
upperLimit_gm = mean_vector_active(sensor) + 3*std_vector_active(sensor);
innerLimit_gm = mean_vector_active(sensor) - 3*std_vector_active(sensor);
plot(data(range_test,sensor), 'Color', [0.5 0.5 0.5])
line([1 rows], [upperLimit_gm upperLimit_gm])
line([1 rows], [innerLimit_gm innerLimit_gm])
hold off
linkaxes(ax,'x');
axis tight
%% REAL CHANGES
fig=figure;
hax=axes;
hold on
plot(data(TRAINING_WINDOW+1:end,:))
title('Data')
for i=1:numel(real_changes)
%line([changes(i) changes(i)],get(hax,'YLim'),'Color',[1 0 0])
line([real_changes(i) real_changes(i)],get(hax,'YLim'),'Color',[1 0 0])
end
hold off