cpdbench.examples.ExampleMetrics

 1def metric_accuracy_in_allowed_windows(indexes, scores, ground_truth, *, window_size):
 2    """Calculate the accuracy with a small deviation window.
 3    The result is the percentage of ground truth values, for which the algorithm got at least one fitting index in the
 4    surrounding window. The scores are ignored.
 5    """
 6    accuracy = 0
 7    for gt in ground_truth:
 8        range_of_gt = range(int(gt - (window_size / 2)), int(gt + (window_size / 2)))
 9        hits = [i for i in indexes if i in range_of_gt]
10        if len(hits) > 0:
11            accuracy += (1 / len(ground_truth))
12    return accuracy
def metric_accuracy_in_allowed_windows(indexes, scores, ground_truth, *, window_size):
 3def metric_accuracy_in_allowed_windows(indexes, scores, ground_truth, *, window_size):
 4    """Calculate the accuracy with a small deviation window.
 5    The result is the percentage of ground truth values, for which the algorithm got at least one fitting index in the
 6    surrounding window. The scores are ignored.
 7    """
 8    accuracy = 0
 9    for gt in ground_truth:
10        range_of_gt = range(int(gt - (window_size / 2)), int(gt + (window_size / 2)))
11        hits = [i for i in indexes if i in range_of_gt]
12        if len(hits) > 0:
13            accuracy += (1 / len(ground_truth))
14    return accuracy

Calculate the accuracy with a small deviation window. The result is the percentage of ground truth values, for which the algorithm got at least one fitting index in the surrounding window. The scores are ignored.