-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot_HMM_Koehler.m
66 lines (55 loc) · 1.84 KB
/
Plot_HMM_Koehler.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
%If you use this toolbox, please cite Coutrot et al.,
%"Scanpath modeling and classification with Hidden Markov Models", Behavior
%Research Methods, 2017
% Compute 1 HMM per scanpath, or 1 HMM for a group of scanpaths
clear
close all
addpath ./stimuli/Images_Koehler/ % where the stimuli are stored
addpath(genpath('emhmm-toolbox'))
load EyeData_Koehler % contains eye positions from Koehler et al., JoV 2014
% variational approach: automatically selects optimal state number from K = 1 to 3
K = 1:3;
%plot the HMM states on the stimuli
isplotHMM=1;
%% Read stimuli
istim=50;
im_name=['image_r_' num2str(istim) '.jpg'];
im_name_struct=['image_r_' num2str(istim)];
im= imread(im_name);
%% Learn 1 HMM per scanpath
for isub=1:9
% Extract scanpath of observer isub
scanpath = extract_scanpath(example_EyeData,'objsearch',isub,istim,K);
if ~isempty(scanpath{1,1})
% Compute corresponding HMM
vbopt=initialize_HMM_computation(im);
[hmm,~] = vbhmm_learn(scanpath, K, vbopt);
% sort states from left to right
hmm = sort_hmm_state(hmm);
if isplotHMM
subplot(3,3,isub)
plot_hmm_state(hmm,scanpath,im)
s=sprintf('observer %u',isub);
title(s)
pause(0.01)
end
end
end
%% Learn 1 HMM from a group of scanpaths
%Select observers
observers=1:19;
% Extract their scanpath
scanpath = extract_scanpath(example_EyeData,'objsearch',observers,istim,K);
%remove empty cell array contents
scanpath=scanpath(~cellfun('isempty',scanpath));
if ~isempty(scanpath{1,1})
% Compute corresponding HMM
vbopt=initialize_HMM_computation(im);
[hmm,~] = vbhmm_learn(scanpath, K, vbopt);
% sort states from left to right
hmm = sort_hmm_state(hmm);
if isplotHMM
vbhmm_plot(hmm,scanpath,im_name)
pause(0.01)
end
end