From 54257f80aaee28c833afb8858e507bdec45c2eef Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Mon, 5 Aug 2024 13:10:33 +0100 Subject: [PATCH] feat: add _nonoverlap_mean() Take the mean of non-overlapping windows of scores Input: list of tuples in the format (time, score) Output: list of tuples in the format (time, mean_score) (reduced set) --- pipeline/feature_extractors.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pipeline/feature_extractors.py b/pipeline/feature_extractors.py index 4fff274..6e5eead 100644 --- a/pipeline/feature_extractors.py +++ b/pipeline/feature_extractors.py @@ -282,6 +282,28 @@ class VideoActivityFeatureExtractor(FeatureExtractor): ) return scores + def _nonoverlap_mean(self, scores, window_size=0.500) -> list: + """Take the mean of non-overlapping windows of scores + + Input: list of tuples in the format (time, score) + Output: list of tuples in the format (time, mean_score) (reduced set) + """ + means = [] + current_window = [] + current_window_start = 0.0 + + for time, score in scores: + if time - current_window_start > window_size: + # calculate mean of current window + mean_score = sum([s for _, s in current_window]) / len(current_window) + means.append((current_window_start, round(mean_score, 3))) + # reset window + current_window = [] + current_window_start = time + current_window.append((time, score)) + + return means + def _drop_lowest(self, scores, percent=33): """Drop the lowest n% scores from the list""" scores = sorted(scores, key=lambda x: x[1], reverse=True)