-
Notifications
You must be signed in to change notification settings - Fork 185
/
calcError.m
70 lines (60 loc) · 1.66 KB
/
calcError.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
function e = calcError(odf1,odf2,varargin)
% calculate approximation error between two ODFs
%
% Syntax
% e = calcError(odf1,odf2)
% e = calcError(odf,pf,'RP')
%
% Input
% odf1, odf2 - @ODF
% pf - @PoleFigure
% S3G - @SO3Grid of quadrature nodes (optional)
%
% Options
% L0 - measure of the orientation space where $|odf1 -- odf2|>\epsilon|
% L1 - L^1 error
% L2 - L^2 error
% RP - RP error (default)
% resolution - resolution used for calculation of the error
%
% See also
% PoleFigure/calcODF PoleFigure/calcError
% compare with a pole figure
if isa(odf2,'PoleFigure'), e = calcError(odf2,odf1,varargin{:}); return;end
evaluated = ~check_option([{odf2} varargin],'evaluated');
% compare two odfs
if evaluated
assert(odf1.CS.Laue == odf2.CS.Laue && odf1.SS.Laue == odf2.SS.Laue,...
'Input ODFs does not have same symmetry.');
end
% TODO
% Fourier based algorithm
if check_option(varargin,'L2')
e = norm(odf1 - odf2)./norm(odf2);
% quadrature rule based algorithm
else
% get approximation grid
S3G = extract_SO3grid(odf1,'resolution',5*degree,varargin{:});
% eval ODFs
if evaluated %second ODF allready evaluated
d1 = eval(odf2,S3G,varargin{:});
else
d1 = get_option([{odf2} varargin],'evaluated',[],'double');
end
if isa(odf2,'double')
d2 = odf1;
else
d2 = eval(odf1,S3G,varargin{:});
end
% calculate the error
if check_option(varargin,'L0')
epsilon = get_option(varargin,'L0',1);
for i = 1:length(epsilon)
e(i) = sum(abs(d1(:)-d2(:)) > epsilon(i))/numel(d1);
end
elseif check_option(varargin,'L2')
e = norm(d1(:)-d2(:)) / norm(d2(:));
else
e = sum(abs(d1(:)-d2(:))) / numel(d1) /2;
end
end