From 92d2722beae47709492c2e622f43e9b64ac83a9f Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 24 May 2023 14:43:08 +0200 Subject: Renaming CoefficientK file by KCoefficient file. --- src/argaze/GazeAnalysis/CoefficientK.py | 96 ------------------------------ src/argaze/GazeAnalysis/KCoefficient.py | 96 ++++++++++++++++++++++++++++++ src/argaze/GazeAnalysis/__init__.py | 2 +- src/argaze/utils/demo_gaze_features_run.py | 50 ++++++++-------- 4 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 src/argaze/GazeAnalysis/CoefficientK.py create mode 100644 src/argaze/GazeAnalysis/KCoefficient.py diff --git a/src/argaze/GazeAnalysis/CoefficientK.py b/src/argaze/GazeAnalysis/CoefficientK.py deleted file mode 100644 index 0bc4395..0000000 --- a/src/argaze/GazeAnalysis/CoefficientK.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python - -""" """ - -__author__ = "Théo de la Hogue" -__credits__ = [] -__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" -__license__ = "BSD" - -from typing import TypeVar, Tuple, Any -from dataclasses import dataclass, field -import math - -from argaze import GazeFeatures - -import numpy - -@dataclass -class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): - """Implementation of Coefficient K algorithm as proposed by A. Duchowski and Krejtz, 2017. - """ - - def __post_init__(self): - - pass - - def analyze(self, scan_path: GazeFeatures.ScanPathType) -> Any: - """Analyze scan path.""" - - assert(len(scan_path) > 1) - - durations = [] - amplitudes = [] - - for scan_step in scan_path: - - durations.append(scan_step.duration) - amplitudes.append(scan_step.last_saccade.amplitude) - - durations = numpy.array(durations) - amplitudes = numpy.array(amplitudes) - - duration_mean = numpy.mean(durations) - amplitude_mean = numpy.mean(amplitudes) - - duration_std = numpy.std(durations) - amplitude_std = numpy.std(amplitudes) - - Ks = [] - for scan_step in scan_path: - - Ks.append(((scan_step.duration - duration_mean) / duration_std) - ((scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std)) - - K = numpy.array(Ks).mean() - - return K - -@dataclass -class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): - """Implementation of AOI based Coefficient K algorithm as described by Christophe Lounis in its thesis "Monitor the monitoring: pilot assistance through gaze tracking and aoi scanning analyses". - """ - - def __post_init__(self): - - pass - - def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType) -> Any: - """Analyze aoi scan path.""" - - assert(len(aoi_scan_path) > 1) - - durations = [] - amplitudes = [] - - for aoi_scan_step in aoi_scan_path: - - durations.append(aoi_scan_step.duration) - amplitudes.append(aoi_scan_step.last_saccade.amplitude) - - durations = numpy.array(durations) - amplitudes = numpy.array(amplitudes) - - duration_mean = numpy.mean(durations) - amplitude_mean = numpy.mean(amplitudes) - - duration_std = numpy.std(durations) - amplitude_std = numpy.std(amplitudes) - - Ks = [] - for aoi_scan_step in aoi_scan_path: - - Ks.append(((aoi_scan_step.duration - duration_mean) / duration_std) - ((aoi_scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std)) - - K = numpy.array(Ks).mean() - - return K \ No newline at end of file diff --git a/src/argaze/GazeAnalysis/KCoefficient.py b/src/argaze/GazeAnalysis/KCoefficient.py new file mode 100644 index 0000000..0bc4395 --- /dev/null +++ b/src/argaze/GazeAnalysis/KCoefficient.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +""" """ + +__author__ = "Théo de la Hogue" +__credits__ = [] +__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" +__license__ = "BSD" + +from typing import TypeVar, Tuple, Any +from dataclasses import dataclass, field +import math + +from argaze import GazeFeatures + +import numpy + +@dataclass +class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): + """Implementation of Coefficient K algorithm as proposed by A. Duchowski and Krejtz, 2017. + """ + + def __post_init__(self): + + pass + + def analyze(self, scan_path: GazeFeatures.ScanPathType) -> Any: + """Analyze scan path.""" + + assert(len(scan_path) > 1) + + durations = [] + amplitudes = [] + + for scan_step in scan_path: + + durations.append(scan_step.duration) + amplitudes.append(scan_step.last_saccade.amplitude) + + durations = numpy.array(durations) + amplitudes = numpy.array(amplitudes) + + duration_mean = numpy.mean(durations) + amplitude_mean = numpy.mean(amplitudes) + + duration_std = numpy.std(durations) + amplitude_std = numpy.std(amplitudes) + + Ks = [] + for scan_step in scan_path: + + Ks.append(((scan_step.duration - duration_mean) / duration_std) - ((scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std)) + + K = numpy.array(Ks).mean() + + return K + +@dataclass +class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): + """Implementation of AOI based Coefficient K algorithm as described by Christophe Lounis in its thesis "Monitor the monitoring: pilot assistance through gaze tracking and aoi scanning analyses". + """ + + def __post_init__(self): + + pass + + def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType) -> Any: + """Analyze aoi scan path.""" + + assert(len(aoi_scan_path) > 1) + + durations = [] + amplitudes = [] + + for aoi_scan_step in aoi_scan_path: + + durations.append(aoi_scan_step.duration) + amplitudes.append(aoi_scan_step.last_saccade.amplitude) + + durations = numpy.array(durations) + amplitudes = numpy.array(amplitudes) + + duration_mean = numpy.mean(durations) + amplitude_mean = numpy.mean(amplitudes) + + duration_std = numpy.std(durations) + amplitude_std = numpy.std(amplitudes) + + Ks = [] + for aoi_scan_step in aoi_scan_path: + + Ks.append(((aoi_scan_step.duration - duration_mean) / duration_std) - ((aoi_scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std)) + + K = numpy.array(Ks).mean() + + return K \ No newline at end of file diff --git a/src/argaze/GazeAnalysis/__init__.py b/src/argaze/GazeAnalysis/__init__.py index f955856..21753c1 100644 --- a/src/argaze/GazeAnalysis/__init__.py +++ b/src/argaze/GazeAnalysis/__init__.py @@ -2,4 +2,4 @@ .. include:: README.md """ __docformat__ = "restructuredtext" -__all__ = ['DispersionThresholdIdentification', 'VelocityThresholdIdentification', 'TransitionMatrix', 'CoefficientK', 'LempelZivComplexity', 'NGram', 'Entropy', 'NearestNeighborIndex'] \ No newline at end of file +__all__ = ['DispersionThresholdIdentification', 'VelocityThresholdIdentification', 'TransitionMatrix', 'KCoefficient', 'LempelZivComplexity', 'NGram', 'Entropy', 'NearestNeighborIndex'] \ No newline at end of file diff --git a/src/argaze/utils/demo_gaze_features_run.py b/src/argaze/utils/demo_gaze_features_run.py index 0e247e2..9264707 100644 --- a/src/argaze/utils/demo_gaze_features_run.py +++ b/src/argaze/utils/demo_gaze_features_run.py @@ -87,12 +87,12 @@ def main(): tm_density = 0. enable_tm_analysis = False - raw_cK_analyzer = CoefficientK.ScanPathAnalyzer() - raw_cK_analysis = 0 - aoi_cK_analyzer = CoefficientK.AOIScanPathAnalyzer() - aoi_cK_analysis = 0 - ck_mode = 'raw' - enable_ck_analysis = False + raw_kc_analyzer = KCoefficient.ScanPathAnalyzer() + raw_kc_analysis = 0 + aoi_kc_analyzer = KCoefficient.AOIScanPathAnalyzer() + aoi_kc_analysis = 0 + kc_mode = 'raw' + enable_kc_analysis = False lzc_analyzer = LempelZivComplexity.AOIScanPathAnalyzer() lzc_analysis = 0 @@ -125,8 +125,8 @@ def main(): nonlocal clear_sum_and_buffer nonlocal tm_probabilities nonlocal tm_density - nonlocal raw_cK_analysis - nonlocal aoi_cK_analysis + nonlocal raw_kc_analysis + nonlocal aoi_kc_analysis nonlocal lzc_analysis nonlocal ngram_analysis nonlocal entropy_analysis @@ -203,9 +203,9 @@ def main(): tm_probabilities, tm_density = tm.analyze(aoi_scan_path) - if enable_ck_analysis: + if enable_kc_analysis: - aoi_cK_analysis = aoi_cK_analyzer.analyze(aoi_scan_path) + aoi_kc_analysis = aoi_kc_analyzer.analyze(aoi_scan_path) if enable_lzc_analysis: @@ -231,9 +231,9 @@ def main(): # Analyse scan path if new_step and len(raw_scan_path) > 1: - if enable_ck_analysis: + if enable_kc_analysis: - raw_cK_analysis = raw_cK_analyzer.analyze(raw_scan_path) + raw_kc_analysis = raw_kc_analyzer.analyze(raw_scan_path) if enable_nni_analysis: @@ -283,10 +283,10 @@ def main(): display_hide = 'hide' if enable_tm_analysis else 'display' cv2.putText(aoi_matrix, f'Transition matrix: {on_off} (Press \'t\' key to {display_hide})', (20, 120), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255) if enable_tm_analysis else (255, 255, 255), 1, cv2.LINE_AA) - # Write cK help - on_off = 'on' if enable_ck_analysis else 'off' - display_hide = 'hide' if enable_ck_analysis else 'display' - cv2.putText(aoi_matrix, f'coefficient K: {on_off} (Press \'k\' key to {display_hide})', (20, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255) if enable_ck_analysis else (255, 255, 255), 1, cv2.LINE_AA) + # Write Kc help + on_off = 'on' if enable_kc_analysis else 'off' + display_hide = 'hide' if enable_kc_analysis else 'display' + cv2.putText(aoi_matrix, f'coefficient K: {on_off} (Press \'k\' key to {display_hide})', (20, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255) if enable_kc_analysis else (255, 255, 255), 1, cv2.LINE_AA) # Write LZC help on_off = 'on' if enable_lzc_analysis else 'off' @@ -373,23 +373,23 @@ def main(): cv2.line(aoi_matrix, start_line, to_center, color, int(probability*10) + 2) cv2.line(aoi_matrix, from_center, to_center, [55, 55, 55], 2) - if enable_ck_analysis: + if enable_kc_analysis: - # Write raw cK analysis - if raw_cK_analysis < 0.: + # Write raw Kc analysis + if raw_kc_analysis < 0.: cv2.putText(aoi_matrix, f'Raw: Ambient attention', (20, window_size[1]-120), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA) - elif raw_cK_analysis > 0.: + elif raw_kc_analysis > 0.: cv2.putText(aoi_matrix, f'Raw: Focal attention', (20, window_size[1]-120), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 1, cv2.LINE_AA) - # Write aoi cK analysis - if aoi_cK_analysis < 0.: + # Write aoi Kc analysis + if aoi_kc_analysis < 0.: cv2.putText(aoi_matrix, f'AOI: Ambient attention', (20, window_size[1]-80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA) - elif aoi_cK_analysis > 0.: + elif aoi_kc_analysis > 0.: cv2.putText(aoi_matrix, f'AOI: Focal attention', (20, window_size[1]-80), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 1, cv2.LINE_AA) @@ -451,10 +451,10 @@ def main(): if enable_heatmap_buffer: clear_sum_and_buffer = True - # Enable cK analysis with 'k' key + # Enable Kc analysis with 'k' key if key_pressed == 107: - enable_ck_analysis = not enable_ck_analysis + enable_kc_analysis = not enable_kc_analysis # Enable TPM analysis with 't' key if key_pressed == 116: -- cgit v1.1