-
Notifications
You must be signed in to change notification settings - Fork 0
/
getErrorMetric.m
76 lines (66 loc) · 1.57 KB
/
getErrorMetric.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 eta = getErrorMetric(v1,v2,metric,t1,t2,options)
if nargin < 3
metric = 'rms';
end
if nargin < 6
options = [];
end
if isfield(options,'tmax')
v1 = v1( t1 <= options.tmax);
t1 = t1( t1 <= options.tmax);
v2 = v2( t2 <= options.tmax);
t2 = t2( t2 <= options.tmax);
end
if isfield(options,'vmin')
v_=max(abs(v1),abs(v2));
to_remove = v_<options.vmin;
v1(to_remove) = [];
t1(to_remove) = [];
v2(to_remove) = [];
t2(to_remove) = [];
end
if any(isnan(v1)) || any(isnan(v1))
disp('Warning, removing NaN entries');
vnan = isnan(v1) | isnan(v2);
v1(vnan) = [];
v2(vnan) = [];
t1(vnan) = [];
t2(vnan) = [];
if isempty(v1)
disp('Warning, no non-NaN entries to compares.');
eta = nan;
return;
else
fprintf('Removed %d NaN entries.\n',sum(vnan));
fprintf('Calculating error metric with the %d non-NaN entries.\n',sum(~vnan));
end
end
switch metric
case 'rms'
eta = sqrt(mean( abs(v1-v2).^2 ));
case 'root-max'
eta = sqrt(max( abs(v1-v2).^2 ));
case 'max-abs'
eta = max(abs(v1-v2));
case 'mean-abs'
eta = mean(abs(v1-v2));
case '1/e'
TM1 = getTM(t1,v1);
TM2 = getTM(t2,v2);
eta = abs( 2*(TM1-TM2)/(TM1+TM2) );
case '1/e 2'
TM1 = getTM(t1,v1);
TM2 = getTM(t2,v2);
eta = abs( (TM1-TM2)/TM2);
case '1/e 1'
TM1 = getTM(t1,v1);
TM2 = getTM(t2,v2);
eta = abs( (TM1-TM2)/TM1);
case 'max(rms,1/e)'
eta_rms = sqrt(mean( abs(v1-v2).^2 ));
TM1 = getTM(t1,v1);
TM2 = getTM(t2,v2);
eta_e = abs( 2*(TM1-TM2)/(TM1+TM2) );
eta = max(eta_rms,eta_e);
end
end