ComputeRegressors.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. % ComputeRegressors.m
  2. %
  3. % This function gets an ARFF as input and segments it in intervals. For each
  4. % interval we assign a SP value and a saccade value.
  5. %
  6. % input:
  7. % arffFile - arffFile to load
  8. % attName - attribute name to use for eye movement intervals
  9. % saccShare - saccade percentage for given subject
  10. % spShare - Sp percentage for given subject
  11. %
  12. % output:
  13. % intStart - start time of intervals
  14. % intDur - duration of intervals
  15. % spValues - parameter values for SP
  16. % saccValues - parameter values for sacade
  17. function [intStart, intDur, spValues, saccValues] = ComputeRegressors(arffFile, attName, saccShare, spShare)
  18. c_blockDur = 2000000; % 2 seconds
  19. c_spShare = 5*spShare;
  20. c_saccShare = 1.5*saccShare;
  21. [data, metadata, attributes] = LoadArff(arffFile);
  22. timeInd = GetAttPositionArff(attributes, 'time');
  23. spIntervals = GetIntervalsArff(data, attributes, attName, 3);
  24. saccIntervals = GetIntervalsArff(data, attributes, attName, 2);
  25. spIntervals = ConcatenateIntervals(spIntervals);
  26. spIntervals = ConcatenateIntervals(spIntervals);
  27. saccIntervals = ClearInts(saccIntervals, spIntervals);
  28. spDur = spIntervals(:,4) - spIntervals(:,1);
  29. saccDur = saccIntervals(:,4) - saccIntervals(:,1);
  30. curTime = 0;
  31. recTime = data(end,timeInd);
  32. intStart = [];
  33. intDur = [];
  34. spValues = [];
  35. saccValues = [];
  36. while (curTime < recTime)
  37. spValidInts = (spIntervals(:,1) > curTime & spIntervals(:,1) < curTime+c_blockDur) | ...
  38. (spIntervals(:,4) > curTime & spIntervals(:,4) < curTime+c_blockDur);
  39. spTmpInts = spIntervals(spValidInts,:);
  40. spTmpInts(spTmpInts(:,4) > curTime+c_blockDur,4) = curTime+c_blockDur;
  41. spTmpInts(spTmpInts(:,1) < curTime,1) = curTime;
  42. spTmpDur = spTmpInts(:,4) - spTmpInts(:,1);
  43. saccValidInts = saccIntervals(:,1) > curTime & saccIntervals(:,1) < curTime+c_blockDur;
  44. spShare = sum(spTmpDur) / c_blockDur;
  45. spIntNum = sum(spValidInts);
  46. saccShare = sum(saccDur(saccValidInts)) / c_blockDur;
  47. saccIntNum = sum(saccValidInts);
  48. intStart = [intStart; curTime];
  49. intDur = [intDur; c_blockDur];
  50. spValues = [spValues; spShare/c_spShare];
  51. saccValues = [saccValues; saccShare/c_saccShare];
  52. curTime = curTime + c_blockDur;
  53. end
  54. spValues = spValues - mean(spValues);
  55. spValues(spValues > 1) = 1;
  56. spValues(spValues < -1) = -1;
  57. saccValues = saccValues - mean(saccValues);
  58. saccValues(saccValues > 1) = 1;
  59. saccValues(saccValues < -1) = -1;
  60. function l_ints = ConcatenateIntervals(intervals)
  61. c_spGap = 100000; % 100ms
  62. l_ints = [];
  63. duration = intervals(:,4) - intervals(:,1);
  64. timeGap = intervals(2:end,1) - intervals(1:end-1,4);
  65. first = 1;
  66. second = 1;
  67. for i=1:size(intervals,1)-1
  68. if (timeGap(i) < c_spGap || duration(i+1) > timeGap(i) || duration(i) > timeGap(i))
  69. second = i+1;
  70. else
  71. l_ints = [l_ints; intervals(first,1:3) intervals(second, 4:6)];
  72. first = i+1;
  73. second = i+1;
  74. end
  75. end
  76. end
  77. function saccInts = ClearInts(saccInts, spInts)
  78. c_displace = 100000;
  79. for i = 1:size(spInts,1)
  80. saccInts(saccInts(:,1) > spInts(i,1) - c_displace & saccInts(:,1) < spInts(i,4) + c_displace, :) = [];
  81. saccInts(saccInts(:,4) > spInts(i,1) - c_displace & saccInts(:,4) < spInts(i,4) + c_displace, :) = [];
  82. end
  83. end
  84. end