-
Notifications
You must be signed in to change notification settings - Fork 0
/
stded.m
79 lines (69 loc) · 1.91 KB
/
stded.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
function means = stded(gt, sim, w, h)
% Scaled Time Delay Embedding Distance
%
% Parameters
%
% gt (n,2) matrix of fixations from human scanpath
% sim (n,2) matrix of fixations from simulated scanpath
% w width of the stimulus image
% h height of the stimulus image
%
% Results:
%
% means similarity measure
%
% Author Vittorio Cuculo
% Date April 2019
%
% MATLAB porting from https://github.com/dariozanca/FixaTons/
%
% Normalize scanpaths coordinates
max_dim = max(w,h);
gt = gt / max_dim;
sim = sim / max_dim;
% Scanpath similarity is computed for all possible k
max_k = min(length(gt), length(sim));
similarities = zeros(1, max_k);
for k = 1:max_k
s = tded(gt, sim, k, "Mean");
similarities(k) = exp(-s);
disp(similarities(k));
end
% Return the average similarity measure
means = mean(similarities);
end
function s = tded(gt, sim, k, mode)
% K must be smaller or equal then the length of scanpaths
if (length(gt) < k || length(sim) < k)
error('ERROR: Too large value for the time-embedding vector dimension');
end
% Create time-embedding vectors for both scanpaths
n_gtvec = length(gt) - k + 1;
gt_vectors = cell(n_gtvec, 1);
for i = 1:n_gtvec
gt_vectors{i} = gt(i:i+k-1,:);
end
n_simvec = length(sim) - k + 1;
sim_vectors = cell(n_simvec, 1);
for i = 1:n_simvec
sim_vectors{i} = sim(i:i+k-1,:);
end
% Find the nearest vector between the k vectors from simulated scanpaths
% and the k vectors from human scanpaths
distances = zeros(n_simvec, 1);
for i = 1:n_simvec
norms = zeros(n_gtvec, 1);
for j = 1:n_gtvec
d = norm(diag(pdist2(gt_vectors{j}, sim_vectors{i})));
norms(j) = d;
end
distances(i) = min(norms) / k;
end
if mode == "Mean"
s = mean(distances);
elseif mode == "Hausdorff"
s = max(distances);
else
error('ERROR: distance mode not defined.')
end
end