diff options
author | Théo de la Hogue | 2023-05-24 10:21:24 +0200 |
---|---|---|
committer | Théo de la Hogue | 2023-05-24 10:21:24 +0200 |
commit | 952c2981598800f399fd09448e478df94aa7703c (patch) | |
tree | 35cb16eff05ee46b62178ddf3e323bc20dbbaea9 /src/argaze/GazeFeatures.py | |
parent | 40dab72aa46c253e76fb75a1228407d745e7a13a (diff) | |
download | argaze-952c2981598800f399fd09448e478df94aa7703c.zip argaze-952c2981598800f399fd09448e478df94aa7703c.tar.gz argaze-952c2981598800f399fd09448e478df94aa7703c.tar.bz2 argaze-952c2981598800f399fd09448e478df94aa7703c.tar.xz |
Computing transiton matrix directly during AOIScanStep creation. Computing probabilities and density inside TransitionMatrix class.
Diffstat (limited to 'src/argaze/GazeFeatures.py')
-rw-r--r-- | src/argaze/GazeFeatures.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py index a098dc4..21841ac 100644 --- a/src/argaze/GazeFeatures.py +++ b/src/argaze/GazeFeatures.py @@ -548,18 +548,22 @@ AOIScanPathType = TypeVar('AOIScanPathType', bound="AOIScanPathType") # Type definition for type annotation convenience class AOIScanPath(list): - """List of aoi scan steps over successive AOI.""" + """List of aoi scan steps over successive aoi.""" - def __init__(self): + def __init__(self, expected_aois: list[str] = []): super().__init__() + self.__expected_aois = expected_aois self.__movements = TimeStampedGazeMovements() self.__current_aoi = '' self.__index = ord('A') self.__aoi_letter = {} self.__letter_aoi = {} + size = len(self.__expected_aois) + self.__transition_matrix = pandas.DataFrame(numpy.zeros((size, size)), index=self.__expected_aois, columns=self.__expected_aois) + def __repr__(self): """String representation.""" @@ -593,11 +597,23 @@ class AOIScanPath(list): return sequence @property + def expected_aois(self): + """List of all expected aoi.""" + + return self.__expected_aois + + @property def current_aoi(self): """AOI name of aoi scan step under construction""" return self.__current_aoi + @property + def transition_matrix(self) -> pandas.DataFrame: + """Pandas DataFrame where indexes are transition departures and columns are transition destinations.""" + + return self.__transition_matrix + def append_saccade(self, ts, saccade): """Append new saccade to aoi scan path.""" @@ -612,6 +628,10 @@ class AOIScanPath(list): .. warning:: It could raise AOIScanStepError""" + if looked_aoi not in self.__expected_aois: + + raise AOIScanStepError('AOI not expected', looked_aoi) + # Is it fixation onto a new aoi? if looked_aoi != self.__current_aoi and len(self.__movements) > 0: @@ -626,6 +646,12 @@ class AOIScanPath(list): # Edit new step new_step = AOIScanStep(self.__movements, self.__current_aoi, letter) + # Edit transition matrix + if len(self) > 0: + + # Increment [index: source, columns: destination] value + self.__transition_matrix.loc[self[-1].aoi, self.__current_aoi,] += 1 + # Append new step super().append(new_step) |