aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/NearestNeighborIndex.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze/GazeAnalysis/NearestNeighborIndex.py')
-rw-r--r--src/argaze/GazeAnalysis/NearestNeighborIndex.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/argaze/GazeAnalysis/NearestNeighborIndex.py b/src/argaze/GazeAnalysis/NearestNeighborIndex.py
index b9654de..cf29169 100644
--- a/src/argaze/GazeAnalysis/NearestNeighborIndex.py
+++ b/src/argaze/GazeAnalysis/NearestNeighborIndex.py
@@ -24,13 +24,18 @@ from scipy.spatial.distance import cdist
@dataclass
class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer):
"""Implementation of Nearest Neighbor Index (NNI) as described in Di Nocera et al., 2006
+
+ Parameters:
+ size: screen dimension.
"""
+ size: tuple[float, float]
+
def __post_init__(self):
- pass
+ self.__nearest_neighbor_index = 0
- def analyze(self, scan_path: GazeFeatures.ScanPathType, screen_dimension: tuple[float, float]) -> float:
+ def analyze(self, scan_path: GazeFeatures.ScanPathType):
"""Analyze scan path."""
assert(len(scan_path) > 1)
@@ -50,6 +55,12 @@ class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer):
dNN = numpy.sum(minimums / len(fixations_focus))
# Mean random distance
- dran = 0.5 * numpy.sqrt(screen_dimension[0] * screen_dimension[1] / len(fixations_focus))
+ dran = 0.5 * numpy.sqrt(self.size[0] * self.size[1] / len(fixations_focus))
+
+ self.__nearest_neighbor_index = dNN / dran
- return dNN / dran
+ @property
+ def nearest_neighbor_index(self) -> float:
+
+ return self.__nearest_neighbor_index
+