-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc_RMSE.m
76 lines (57 loc) · 1.42 KB
/
calc_RMSE.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
function [rmse, t, f] = calc_RMSE(t1, f1, t2, f2)
t1_len = length(t1);
t2_len = length(t2);
t_len = t1_len + t2_len;
t = zeros(t_len, 1);
f = zeros(t_len, 1);
i = 1;
j = 1;
k = 1;
while i <= t1_len && j <= t2_len,
if t1(i) == t2(j),
t(k) = t1(i);
f(k) = f1(i) - f2(j);
i = i + 1;
j = j + 1;
k = k + 1;
elseif t1(i) < t2(j),
% interpolate f2
f2_intp = intp([t2(j - 1), t2(j)], [f2(j - 1), f2(j)], t1(i));
t(k) = t1(i);
f(k) = f1(i) - f2_intp;
i = i + 1;
k = k + 1;
else
% interpolate f1
f1_intp = intp([t1(i - 1), t1(i)], [f1(i - 1), f1(i)], t2(j));
t(k) = t2(j);
f(k) = f1_intp - f2(j);
j = j + 1;
k = k + 1;
end
end
while i <= t1_len,
% interpolate f2
f2_intp = intp([t2(t2_len - 1), t2(t2_len)], [f2(t2_len - 1), f2(t2_len)], t1(i));
t1(k) = t1(i);
f(k) = f1(i) - f2_intp;
i = i + 1;
k = k + 1;
end
while j <= t2_len,
% interpolate f1
f1_intp = intp([t1(t1_len - 1), t1(t1_len)], [f1(t1_len - 1), f1(t1_len)], t2(j));
t(k) = t2(j);
f(k) = f1_intp - f2(j);
j = j + 1;
k = k + 1;
end
t_len = k - 1;
t = t(1:t_len);
f = f(1:t_len);
mse = sum(f.*f)/t_len;
rmse = sqrt(mse);
function y_i = intp(x, y, x_i)
y_i = (y(2) - y(1)) / (x(2) - x(1)) * (x_i - x(1)) + y(1);
end
end