blob: e92baf333ef6c9e69bbbbb3d3584a99c08d5b1aa (
plain)
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
|
#!/usr/bin/env python
"""Implementation of transition matrix probabilities and density algorithm as described in:
**Krejtz K., Szmidt T., Duchowski A.T. (2014).**
*Entropy-based statistical analysis of eye movement transitions.*
Proceedings of the Symposium on Eye Tracking Research and Applications, (ETRA'14, 159-166).
[https://doi.org/10.1145/2578153.2578176](https://doi.org/10.1145/2578153.2578176)
"""
__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from typing import Tuple
from dataclasses import dataclass
from argaze import GazeFeatures
import pandas
import numpy
@dataclass
class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer):
def __post_init__(self):
pass
def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType) -> Tuple[pandas.DataFrame, float]:
"""Analyze aoi scan path.
* **Returns:**
- transition matrix probabilities
- transition matrix density"""
assert(len(aoi_scan_path) > 1)
# Sum transitions starting from each aoi
row_sum = aoi_scan_path.transition_matrix.apply(lambda row: row.sum(), axis=1)
# Editing transition matrix probabilities
# Note: when no transiton starts from an aoi, destination probabilites is equal to 1/S where S is the number of aois
transition_matrix_probabilities = aoi_scan_path.transition_matrix.apply(lambda row: row.apply(lambda p: p / row_sum[row.name] if row_sum[row.name] > 0 else 1 / row_sum.size), axis=1)
# Calculate matrix density
transition_matrix_density = (transition_matrix_probabilities != 0.).astype(int).sum(axis=1).sum() / transition_matrix_probabilities.size
return transition_matrix_probabilities, transition_matrix_density
|