-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot_HMM_Coutrot.m
67 lines (56 loc) · 2.07 KB
/
Plot_HMM_Coutrot.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
%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/Frames_Coutrot/ % where the stimuli are stored
addpath(genpath('emhmm-toolbox'))
load EyeData_Coutrot % contains eye positions from Coutrot & Guyader, 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=3;
frame_name=['clip_' num2str(istim) '.jpg'];
frame= imread(frame_name);
%% Learn 1 HMM per scanpath
for isub=1:9
% Extract scanpath of observer isub
scanpath = extract_scanpath(example_EyeData_Coutrot,'with_os',isub,istim,K);
if ~isempty(scanpath{1,1})
% Compute corresponding HMM
vbopt=initialize_HMM_computation(frame);
vbopt.do_constrain_var=1; %Tie covariance matrices (identical circle distributions)
[hmm,~] = vbhmm_learn(scanpath, K, vbopt);%Learn 1 HMM from each scanpath
% sort states from left to right
hmm = sort_hmm_state(hmm);
if isplotHMM
subplot(3,3,isub)
plot_hmm_state(hmm,scanpath,frame)
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_Coutrot,'with_os',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(frame);
vbopt.do_constrain_var=1; %Tie covariance matrices (identical circle distributions)
[hmm,~] = vbhmm_learn(scanpath, K, vbopt); %Learn HMM from all scanpaths
% sort states from left to right
hmm = sort_hmm_state(hmm);
if isplotHMM
vbhmm_plot(hmm,scanpath,frame_name)
pause(0.01)
end
end