Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
dcnieho committed Oct 17, 2017
2 parents ef84da8 + 2fa36a2 commit 5cd88ec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 3 additions & 2 deletions functions/I2MC/I2MCfunc.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
par.maxerrors = 100; % maximum number of errors allowed in k-means clustering procedure before proceeding to next file
% FIXATION DETERMINATION
par.cutoffstd = 2; % number of standard deviations above mean k-means weights will be used as fixation cutoff
par.onoffsetThresh = 3; % number of MAD away from median fixation duration. Will be used to walk forward at fixation starts and backward at fixation ends to refine their placement and stop algorithm from eating into saccades
par.maxMergeDist = 30; % maximum Euclidean distance in pixels between fixations for merging
par.maxMergeTime = 30; % maximum time in ms between fixations for merging
par.minFixDur = 40; % minimum fixation duration (ms) after merging, fixations with shorter duration are removed from output
Expand All @@ -51,7 +52,7 @@
end
value = varargin{p+1};
switch key
case {'xres','yres','freq','missingx','missingy','disttoscreen','windowtimeInterp','maxdisp','windowtime','steptime','cutoffstd','maxMergeDist','maxMergeTime','minFixDur'}
case {'xres','yres','freq','missingx','missingy','disttoscreen','windowtimeInterp','maxdisp','windowtime','steptime','cutoffstd','onoffsetThresh','maxMergeDist','maxMergeTime','minFixDur'}
checkNumeric(value,key);
checkScalar(value,key);
par.(key) = value;
Expand Down Expand Up @@ -195,6 +196,6 @@

%% DETERMINE FIXATIONS BASED ON FINALWEIGHTS_AVG
fprintf('Determining fixations based on clustering weight mean for averaged signal and separate eyes + 2*std \n')
[fix.cutoff,fix.start,fix.end,fix.startT,fix.endT,fix.dur,fix.xpos,fix.ypos,fix.flankdataloss,fix.fracinterped] = getFixations(data.finalweights,data.time,xpos,ypos,missing,par.cutoffstd,par.maxMergeDist,par.maxMergeTime,par.minFixDur);
[fix.cutoff,fix.start,fix.end,fix.startT,fix.endT,fix.dur,fix.xpos,fix.ypos,fix.flankdataloss,fix.fracinterped] = getFixations(data.finalweights,data.time,xpos,ypos,missing,par.cutoffstd,par.onoffsetThresh,par.maxMergeDist,par.maxMergeTime,par.minFixDur);
[fix.RMSxy,fix.BCEA,fix.fixRangeX,fix.fixRangeY] = getFixStats(xpos,ypos,missing,fix.start,fix.end,pixperdeg);

38 changes: 37 additions & 1 deletion functions/I2MC/getFixations.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [cutoff,fixstart,fixend,starttime,endtime,fixdur,xmedian,ymedian,flankdataloss,fracinterped] = getFixations(finalweights,timestamp,xpos,ypos,missing,cutoffstd,maxMergeDist,maxMergeTime,minFixDur)
function [cutoff,fixstart,fixend,starttime,endtime,fixdur,xmedian,ymedian,flankdataloss,fracinterped] = getFixations(finalweights,timestamp,xpos,ypos,missing,cutoffstd,onoffsetThresh,maxMergeDist,maxMergeTime,minFixDur)
% determine fixations based on finalweights from 2-means clustering

% Roy Hessels - 2014
Expand All @@ -12,6 +12,8 @@
% missing (originally, before interpolation!)
% cutoffstd = number of std above mean clustering-weight to
% use as fixation cutoff
% onoffsetThresh = threshold (x*MAD of fixation) for walking
% forward/back for saccade off- and onsets
% maxMergeDist = maximum Euclidean distance in pixels between fixations for merging
% maxMergeTime = maximum time in ms between fixations for merging

Expand Down Expand Up @@ -43,6 +45,40 @@
% get indices of where fixations start and end
[fixstart,fixend] = bool2bounds(fixbool);

% for each fixation start, walk forward until recorded position is below a
% threshold of lambda*MAD away from median fixation position.
% same for each fixation end, but walk backward
for p=1:length(fixstart)
xmedThis = median(xpos(fixstart(p):fixend(p)));
ymedThis = median(ypos(fixstart(p):fixend(p)));
% MAD = median(abs(x_i-median({x}))). For the 2D version, I'm using
% median 2D distance of a point from the median fixation position. Not
% exactly MAD, but makes more sense to me for 2D than city block,
% especially given that we use 2D distance in our walk here
MAD = median(hypot(xpos(fixstart(p):fixend(p))-xmedThis, ypos(fixstart(p):fixend(p))-ymedThis));

thresh = MAD*onoffsetThresh;

% walk until distance less than threshold away from median fixation
% position. No walking occurs when we're already below threshold.
i = fixstart(p);
if i>1 % don't walk when fixation starting at start of data
while hypot(xpos(i)-xmedThis,ypos(i)-ymedThis)>thresh
i = i+1;
end
fixstart(p) = i;
end

% and now fixation end.
i = fixend(p);
if i<length(xpos) % don't walk when fixation ending at end of data
while hypot(xpos(i)-xmedThis,ypos(i)-ymedThis)>thresh
i = i-1;
end
fixend(p) = i;
end
end

% get start time, end time, and fix duration
starttime = timestamp(fixstart);
endtime = timestamp(fixend);
Expand Down

0 comments on commit 5cd88ec

Please sign in to comment.