tsadmetrics 0.1.13__py3-none-any.whl → 0.1.15__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
docs/conf.py CHANGED
@@ -1,13 +1,9 @@
1
1
  # Configuration file for the Sphinx documentation builder.
2
2
  #
3
- # For the full list of built-in configuration values, see the documentation:
4
- # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
3
 
6
- # -- Project information -----------------------------------------------------
7
- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
4
  import os
9
5
  import sys
10
- sys.path.insert(0, os.path.abspath('../../'))
6
+ sys.path.insert(0, os.path.abspath('../'))
11
7
 
12
8
 
13
9
  project = 'TSADmetrics'
@@ -18,26 +14,54 @@ release = 'MIT'
18
14
  # -- General configuration ---------------------------------------------------
19
15
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
20
16
 
21
- extensions = [
22
- 'sphinx.ext.autodoc',
23
- 'sphinx.ext.viewcode',
24
- 'sphinx.ext.napoleon'
25
- ]
26
17
 
27
- intersphinx_mapping = {
28
- 'python': ('https://docs.python.org/3/', None),
29
- 'sphinx': ('https://www.sphinx-doc.org/en/master/', None),
30
- }
31
- intersphinx_disabled_domains = ['std']
18
+ extensions = ['sphinx.ext.duration', 'sphinx.ext.doctest', 'sphinx.ext.autodoc',]
19
+
20
+
32
21
 
33
22
  templates_path = ['_templates']
34
- exclude_patterns = []
23
+ exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
35
24
 
36
- epub_show_urls = 'footnote'
37
- html_theme = 'sphinx_rtd_theme'
25
+ html_theme = 'furo'
38
26
  html_static_path = ['_static']
27
+ html_theme_options = {
28
+ #"sidebar_hide_name": True,
29
+ "light_css_variables": {
30
+ "color-brand-primary": "#2e5c7d",
31
+ "color-brand-content": "#2e5c7d",
32
+ "codebgcolor": "red",
33
+ "codetextcolor": "red",
34
+ },
35
+ "dark_css_variables": {
36
+ "color-brand-primary": "#6998b4",
37
+ "color-brand-content": "#6998b4",
38
+ "codebgcolor": "green",
39
+ "codetextcolor": "green",
40
+ },
41
+ "navigation_with_keys": True
42
+
43
+ }
44
+ html_baseurl = ''
45
+
46
+ html_css_files = [
47
+ 'css/custom.css',
48
+ ]
49
+
50
+ epub_show_urls = 'footnote'
51
+
39
52
  # -- Options for HTML output -------------------------------------------------
40
53
  # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
41
54
 
42
- html_theme = 'sphinx_rtd_theme'
43
- html_static_path = ['_static']
55
+
56
+
57
+
58
+ ### -- LaTeX options -------------------------------------------------
59
+
60
+ # comando para compilar: make latexpdf LATEXMKOPTS="-xelatex"
61
+
62
+ latex_elements = {
63
+ 'maxlistdepth': '10', # Aumenta el límite de anidamiento
64
+ 'papersize': 'a4paper',
65
+ 'pointsize': '10pt',
66
+
67
+ }
@@ -91,7 +91,7 @@ def point_adjusted_recall(y_true: np.array, y_pred: np.array):
91
91
  are marked as correctly detected. The adjusted predictions are then compared to the ground-truth
92
92
  labels using the standard point-wise recall formulation.
93
93
 
94
- Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
94
+
95
95
 
96
96
  Parameters:
97
97
  y_true (np.array):
@@ -272,8 +272,7 @@ def point_adjusted_at_k_recall(y_true: np.array, y_pred: np.array, k: float):
272
272
  This metric is based on the standard recall score, but applies a temporal adjustment
273
273
  to the predictions before computing it. Specifically, for each ground-truth anomalous segment,
274
274
  if at least K% of the points within that segment are predicted as anomalous, all points in
275
- the segment are marked as correctly detected. Otherwise, the entire segment is treated as
276
- missed, even if some points were correctly predicted. The adjusted predictions are then used
275
+ the segment are marked as correctly detected. The adjusted predictions are then used
277
276
  to compute the standard point-wise recall.
278
277
 
279
278
  Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
@@ -301,8 +300,7 @@ def point_adjusted_at_k_precision(y_true: np.array, y_pred: np.array, k: float):
301
300
  This metric is based on the standard precision score, but applies a temporal adjustment
302
301
  to the predictions before computing it. Specifically, for each ground-truth anomalous segment,
303
302
  if at least K% of the points within that segment are predicted as anomalous, all points in
304
- the segment are marked as correctly detected. Otherwise, the entire segment is treated as
305
- missed, even if some points were correctly predicted. The adjusted predictions are then used
303
+ the segment are marked as correctly detected. The adjusted predictions are then used
306
304
  to compute the standard point-wise precision.
307
305
  Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
308
306
 
@@ -329,8 +327,7 @@ def point_adjusted_at_k_f_score(y_true: np.array, y_pred: np.array, k: float, be
329
327
  This metric is based on the standard F-Score, but applies a temporal adjustment
330
328
  to the predictions before computing it. Specifically, for each ground-truth anomalous segment,
331
329
  if at least K% of the points within that segment are predicted as anomalous, all points in
332
- the segment are marked as correctly detected. Otherwise, the entire segment is treated as
333
- missed, even if some points were correctly predicted. The adjusted predictions are then used
330
+ the segment are marked as correctly detected. The adjusted predictions are then used
334
331
  to compute the standard F-Score precision.
335
332
 
336
333
  Implementation of https://link.springer.com/article/10.1007/s10618-023-00988-8
@@ -402,6 +399,7 @@ def latency_sparsity_aw_precision(y_true: np.array, y_pred: np.array, ni: int):
402
399
  scattered false positives, predictions are subsampled using a sparsity factor n, so that
403
400
  only one prediction is considered every n time steps. The adjusted predictions are then used
404
401
  to compute the standard point-wise precision.
402
+
405
403
  Implementation of https://dl.acm.org/doi/10.1145/3447548.3467174
406
404
 
407
405
  Parameters:
@@ -595,7 +593,7 @@ def time_tolerant_recall(y_true: np.array, y_pred: np.array, t: int) -> float:
595
593
  Calculate time tolerant recall for anomaly detection in time series.
596
594
  This metric is based on the standard recall, but applies a temporal adjustment
597
595
  to the predictions before computing it. Specifically, a predicted anomalous point is considered
598
- a true positive if it lies within a temporal window of size τ around any ground-truth anomalous point.
596
+ a true positive if it lies within a temporal window of size :math:`{\\tau}` around any ground-truth anomalous point.
599
597
  This allows for small temporal deviations in the predictions to be tolerated. The adjusted predictions are then used
600
598
  to compute the standard point-wise recall.
601
599
 
@@ -623,7 +621,7 @@ def time_tolerant_precision(y_true: np.array, y_pred: np.array, t: int) -> float
623
621
  Calculate time tolerant precision for anomaly detection in time series.
624
622
  This metric is based on the standard precision, but applies a temporal adjustment
625
623
  to the predictions before computing it. Specifically, a predicted anomalous point is considered
626
- a true positive if it lies within a temporal window of size τ around any ground-truth anomalous point.
624
+ a true positive if it lies within a temporal window of size :math:`{\\tau}` around any ground-truth anomalous point.
627
625
  This allows for small temporal deviations in the predictions to be tolerated. The adjusted predictions are then used
628
626
  to compute the standard point-wise precision.
629
627
 
@@ -651,7 +649,7 @@ def time_tolerant_f_score(y_true: np.array, y_pred: np.array, t: int, beta=1):
651
649
  Calculate time tolerant F-score for anomaly detection in time series.
652
650
  This metric is based on the standard F-score, but applies a temporal adjustment
653
651
  to the predictions before computing it. Specifically, a predicted anomalous point is considered
654
- a true positive if it lies within a temporal window of size τ around any ground-truth anomalous point.
652
+ a true positive if it lies within a temporal window of size :math:`{\\tau}` around any ground-truth anomalous point.
655
653
  This allows for small temporal deviations in the predictions to be tolerated.The adjusted predictions are then used
656
654
  to compute the standard point-wise F-Score.
657
655
 
@@ -687,7 +685,7 @@ def range_based_recall(y_true: np.array, y_pred: np.array, alpha: float, bias='f
687
685
  rather than individual points. For each true anomaly range, it computes a score that rewards
688
686
  (1) detecting the existence of the range, (2) the proportion of overlap, and (3) penalties or
689
687
  bonuses based on the position and fragmentation of predicted segments. These components are
690
- weighted by α (existence vs. overlap) and further shaped by customizable bias functions
688
+ weighted by :math:`{\\alpha}` (existence vs. overlap) and further shaped by customizable bias functions
691
689
  for positional and cardinality factors.
692
690
 
693
691
  For more information, see the original paper:
@@ -699,7 +697,7 @@ def range_based_recall(y_true: np.array, y_pred: np.array, alpha: float, bias='f
699
697
  y_pred (np.array):
700
698
  The predicted binary labels for the time series data.
701
699
  alpha (float):
702
- Relative importance of existence reward. 0 alpha 1.
700
+ Relative importance of existence reward. 0 \\leq alpha \\leq 1.
703
701
  bias (str):
704
702
  Positional bias. This should be "flat", "front", "middle", or "back".
705
703
  cardinality_mode (str, optional):
@@ -723,6 +721,8 @@ def range_based_precision(y_true: np.array, y_pred: np.array, alpha: float, bias
723
721
  predicted anomaly range is evaluated for (1) overlap with any true ranges, (2) the size of
724
722
  that overlap, and (3) positional and fragmentation effects via bias functions. Cardinality
725
723
  penalties can be applied when a single true range is covered by multiple predicted ranges.
724
+ These components are weighted by :math:`{\\alpha}` (existence vs. overlap) and further shaped by customizable bias functions
725
+ for positional and cardinality factors.
726
726
 
727
727
  For more information, see the original paper:
728
728
  https://proceedings.neurips.cc/paper_files/paper/2018/file/8f468c873a32bb0619eaeb2050ba45d1-Paper.pdf
@@ -733,7 +733,7 @@ def range_based_precision(y_true: np.array, y_pred: np.array, alpha: float, bias
733
733
  y_pred (np.array):
734
734
  The predicted binary labels for the time series data.
735
735
  alpha (float):
736
- Relative importance of existence reward. 0 alpha 1.
736
+ Relative importance of existence reward. 0 \\leq alpha \\leq 1.
737
737
  bias (str):
738
738
  Positional bias. This should be "flat", "front", "middle", or "back".
739
739
  cardinality_mode (str, optional):
@@ -766,21 +766,23 @@ def range_based_f_score(y_true: np.array, y_pred: np.array, p_alpha: float, r_al
766
766
 
767
767
 
768
768
  Parameters:
769
- y_true (np.array):
770
- The ground truth binary labels for the time series data.
771
- y_pred (np.array):
772
- The predicted binary labels for the time series data.
773
- alpha (float):
774
- Relative importance of existence reward. 0 alpha 1.
775
- p_bias (str):
776
- Positional bias for precision. This should be "flat", "front", "middle", or "back".
777
- r_bias (str):
778
- Positional bias for recall. This should be "flat", "front", "middle", or "back".
779
- cardinality_mode (str, optional):
780
- Cardinality type. This should be "one", "reciprocal" or "udf_gamma".
781
- beta (float):
782
- The beta value, which determines the weight of precision in the combined score.
783
- Default is 1, which gives equal weight to precision and recall.
769
+ y_true (np.array):
770
+ The ground truth binary labels for the time series data.
771
+ y_pred (np.array):
772
+ The predicted binary labels for the time series data.
773
+ p_alpha (float):
774
+ Relative importance of existence reward for precision. 0 \\leq alpha \\leq 1.
775
+ r_alpha (float):
776
+ Relative importance of existence reward for recall. 0 \\leq alpha \\leq 1.
777
+ p_bias (str):
778
+ Positional bias for precision. This should be "flat", "front", "middle", or "back".
779
+ r_bias (str):
780
+ Positional bias for recall. This should be "flat", "front", "middle", or "back".
781
+ cardinality_mode (str, optional):
782
+ Cardinality type. This should be "one", "reciprocal" or "udf_gamma".
783
+ beta (float):
784
+ The beta value, which determines the weight of precision in the combined score.
785
+ Default is 1, which gives equal weight to precision and recall.
784
786
 
785
787
  Returns:
786
788
  float: The range-based F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
@@ -799,8 +801,8 @@ def ts_aware_recall(y_true: np.array, y_pred: np.array, alpha: float, delta: flo
799
801
 
800
802
  This metric is based on the range_based_recall, but introduces two key modifications.
801
803
  First, a predicted anomalous segment is only counted as a true positive if it covers at least a fraction
802
- θ of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
803
- length δ at its end, within which any overlap contribution decays linearly from full weight down to zero.
804
+ :math:`{\\theta}` of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
805
+ length :math:`{\\delta}` at its end, within which any overlap contribution decays linearly from full weight down to zero.
804
806
  Unlike the original range-based formulation, this variant omits cardinality and positional bias terms,
805
807
  focusing solely on overlap fraction and end‑tolerance decay.
806
808
 
@@ -810,20 +812,20 @@ def ts_aware_recall(y_true: np.array, y_pred: np.array, alpha: float, delta: flo
810
812
  y_pred (np.array):
811
813
  The predicted binary labels for the time series data.
812
814
  alpha (float):
813
- Relative importance of the existence reward versus overlap reward (0 α 1).
815
+ Relative importance of the existence reward versus overlap reward (0 \\leq :math:`{\\alpha}` \\leq 1).
814
816
  delta (float):
815
817
  Tolerance window length at the end of each true anomaly segment.
816
- - If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
817
- length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
818
- - If past_range is False, δ must be a non-negative integer, representing an absolute number of
818
+ - If past_range is True, :math:`{\\delta}` must be a float in (0, 1], representing the fraction of the segment’s
819
+ length to extend. E.g., :math:`{\\delta}` = 0.5 extends a segment of length 10 by 5 time steps.
820
+ - If past_range is False, :math:`{\\delta}` must be a non-negative integer, representing an absolute number of
819
821
  time steps to extend each segment.
820
822
  theta (float):
821
- Minimum fraction (0 θ 1) of the true anomaly range that must be overlapped by
823
+ Minimum fraction (0 \\leq :math:`{\\theta}` \\leq 1) of the true anomaly range that must be overlapped by
822
824
  predictions for the segment to count as detected.
823
825
  past_range (bool):
824
- Determines how δ is interpreted.
825
- - True: δ is treated as a fractional extension of each segment’s length.
826
- - False: δ is treated as an absolute number of time steps.
826
+ Determines how :math:`{\\delta}` is interpreted.
827
+ - True: :math:`{\\delta}` is treated as a fractional extension of each segment’s length.
828
+ - False: :math:`{\\delta}` is treated as an absolute number of time steps.
827
829
 
828
830
  Returns:
829
831
  float: The time series aware recall score.
@@ -840,8 +842,8 @@ def ts_aware_precision(y_true: np.array, y_pred: np.array,alpha: float, delta: f
840
842
 
841
843
  This metric is based on the range_based_precision, but introduces two key modifications.
842
844
  First, a predicted anomalous segment is only counted as a true positive if it covers at least a fraction
843
- θ of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
844
- length δ at its end, within which any overlap contribution decays linearly from full weight down to zero.
845
+ :math:`{\\theta}` of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
846
+ length :math:`{\\delta}` at its end, within which any overlap contribution decays linearly from full weight down to zero.
845
847
  Unlike the original range-based formulation, this variant omits cardinality and positional bias terms,
846
848
  focusing solely on overlap fraction and end‑tolerance decay.
847
849
 
@@ -851,20 +853,20 @@ def ts_aware_precision(y_true: np.array, y_pred: np.array,alpha: float, delta: f
851
853
  y_pred (np.array):
852
854
  The predicted binary labels for the time series data.
853
855
  alpha (float):
854
- Relative importance of the existence reward versus overlap reward (0 α 1).
856
+ Relative importance of the existence reward versus overlap reward (0 \\leq :math:`{\\alpha}` \\leq 1).
855
857
  delta (float):
856
858
  Tolerance window length at the end of each true anomaly segment.
857
- - If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
858
- length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
859
- - If past_range is False, δ must be a non-negative integer, representing an absolute number of
859
+ - If past_range is True, :math:`{\\delta}` must be a float in (0, 1], representing the fraction of the segment’s
860
+ length to extend. E.g., :math:`{\\delta}` = 0.5 extends a segment of length 10 by 5 time steps.
861
+ - If past_range is False, :math:`{\\delta}` must be a non-negative integer, representing an absolute number of
860
862
  time steps to extend each segment.
861
863
  theta (float):
862
- Minimum fraction (0 θ 1) of the true anomaly range that must be overlapped by
864
+ Minimum fraction (0 \\leq :math:`{\\theta}` \\leq 1) of the true anomaly range that must be overlapped by
863
865
  predictions for the segment to count as detected.
864
866
  past_range (bool):
865
- Determines how δ is interpreted.
866
- - True: δ is treated as a fractional extension of each segment’s length.
867
- - False: δ is treated as an absolute number of time steps.
867
+ Determines how :math:`{\\delta}` is interpreted.
868
+ - True: :math:`{\\delta}` is treated as a fractional extension of each segment’s length.
869
+ - False: :math:`{\\delta}` is treated as an absolute number of time steps.
868
870
 
869
871
  Returns:
870
872
  float: The time series aware precision score.
@@ -882,8 +884,8 @@ def ts_aware_f_score(y_true: np.array, y_pred: np.array, beta: float, alpha: flo
882
884
 
883
885
  This metric is based on the range_based_f_score, but introduces two key modifications.
884
886
  First, a predicted anomalous segment is only counted as a true positive if it covers at least a fraction
885
- θ of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
886
- length δ at its end, within which any overlap contribution decays linearly from full weight down to zero.
887
+ :math:`{\\theta}` of the ground‑truth anomaly range. Second, each labeled anomaly is extended by a tolerance window of
888
+ length :math:`{\\delta}` at its end, within which any overlap contribution decays linearly from full weight down to zero.
887
889
  Unlike the original range-based formulation, this variant omits cardinality and positional bias terms,
888
890
  focusing solely on overlap fraction and end‑tolerance decay.
889
891
 
@@ -892,21 +894,24 @@ def ts_aware_f_score(y_true: np.array, y_pred: np.array, beta: float, alpha: flo
892
894
  The ground truth binary labels for the time series data.
893
895
  y_pred (np.array):
894
896
  The predicted binary labels for the time series data.
897
+ beta (float):
898
+ The beta value, which determines the weight of precision in the combined score.
899
+ Default is 1, which gives equal weight to precision and recall.
895
900
  alpha (float):
896
- Relative importance of the existence reward versus overlap reward (0 α 1).
901
+ Relative importance of the existence reward versus overlap reward (0 \\leq :math:`{\\alpha}` \\leq 1).
897
902
  delta (float):
898
903
  Tolerance window length at the end of each true anomaly segment.
899
- - If past_range is True, δ must be a float in (0, 1], representing the fraction of the segment’s
900
- length to extend. E.g., δ = 0.5 extends a segment of length 10 by 5 time steps.
901
- - If past_range is False, δ must be a non-negative integer, representing an absolute number of
904
+ - If past_range is True, :math:`{\\delta}` must be a float in (0, 1], representing the fraction of the segment’s
905
+ length to extend. E.g., :math:`{\\delta}` = 0.5 extends a segment of length 10 by 5 time steps.
906
+ - If past_range is False, :math:`{\\delta}` must be a non-negative integer, representing an absolute number of
902
907
  time steps to extend each segment.
903
908
  theta (float):
904
- Minimum fraction (0 θ 1) of the true anomaly range that must be overlapped by
909
+ Minimum fraction (0 \\leq :math:`{\\theta}` \\leq 1) of the true anomaly range that must be overlapped by
905
910
  predictions for the segment to count as detected.
906
911
  past_range (bool):
907
- Determines how δ is interpreted.
908
- - True: δ is treated as a fractional extension of each segment’s length.
909
- - False: δ is treated as an absolute number of time steps.
912
+ Determines how :math:`{\\delta}` is interpreted.
913
+ - True: :math:`{\\delta}` is treated as a fractional extension of each segment’s length.
914
+ - False: :math:`{\\delta}` is treated as an absolute number of time steps.
910
915
 
911
916
  Returns:
912
917
  float: The time series aware F-score, which is the harmonic mean of precision and recall, adjusted by the beta value.
@@ -929,10 +934,8 @@ def enhanced_ts_aware_recall(y_true: np.array, y_pred: np.array, theta: float):
929
934
  Calculate enhanced time series aware recall for anomaly detection in time series.
930
935
 
931
936
  This metric is similar to the range-based recall in that it accounts for both detection existence
932
- and overlap proportion. Additionally, it requires that a significant fraction θ of each true anomaly
933
- segment be detected, and that a significant fraction γ of each predicted segment overlaps with the
934
- ground truth. Finally, recall contributions from each event are weighted by the square root of the
935
- true segment’s length, providing a compromise between point-wise and segment-wise approaches.
937
+ and overlap proportion. Additionally, it requires that a significant fraction :math:`{\\theta}` of each true anomaly
938
+ segment be detected.
936
939
 
937
940
  Parameters:
938
941
  y_true (np.array):
@@ -940,7 +943,7 @@ def enhanced_ts_aware_recall(y_true: np.array, y_pred: np.array, theta: float):
940
943
  y_pred (np.array):
941
944
  The predicted binary labels for the time series data.
942
945
  theta (float):
943
- Minimum fraction (0 θ 1) of a true segment that must be overlapped
946
+ Minimum fraction (0 \\leq :math:`{\\theta}` \\leq 1) of a true segment that must be overlapped
944
947
  by predictions to count as detected.
945
948
 
946
949
  Returns:
@@ -958,11 +961,9 @@ def enhanced_ts_aware_precision(y_true: np.array, y_pred: np.array, theta: float
958
961
  """
959
962
  Calculate enhanced time series aware precision for anomaly detection in time series.
960
963
 
961
- This metric is similar to the range-based precision in that it accounts for both detection existence
962
- and overlap proportion. Additionally, it requires that a significant fraction θ of each true anomaly
963
- segment be detected, and that a significant fraction γ of each predicted segment overlaps with the
964
- ground truth. Finally, precision contributions from each event are weighted by the square root of the
965
- true segment’s length, providing a compromise between point-wise and segment-wise approaches.
964
+ This metric is similar to the range-based precision. Additionally, it requires that a significant fraction :math:`{\\theta}`
965
+ of each predicted segment overlaps with the ground truth. Finally, precision contributions from each event are weighted by
966
+ the square root of the true segment’s length, providing a compromise between point-wise and segment-wise approaches.
966
967
 
967
968
  Parameters:
968
969
  y_true (np.array):
@@ -970,8 +971,8 @@ def enhanced_ts_aware_precision(y_true: np.array, y_pred: np.array, theta: float
970
971
  y_pred (np.array):
971
972
  The predicted binary labels for the time series data.
972
973
  theta (float):
973
- Minimum fraction (0 θ 1) of a true segment that must be overlapped
974
- by predictions to count as detected.
974
+ Minimum fraction (0 \\leq :math:`{\\theta}` \\leq 1) of a predicted segment that must be overlapped
975
+ by ground truth to count as detected.
975
976
 
976
977
  Returns:
977
978
  float: The time series aware precision score.
@@ -990,8 +991,8 @@ def enhanced_ts_aware_f_score(y_true: np.array, y_pred: np.array, theta_p: float
990
991
  Calculate enhanced time series aware F-score for anomaly detection in time series.
991
992
 
992
993
  This metric is similar to the range-based F-score in that it accounts for both detection existence
993
- and overlap proportion. Additionally, it requires that a significant fraction θ of each true anomaly
994
- segment be detected, and that a significant fraction γ of each predicted segment overlaps with the
994
+ and overlap proportion. Additionally, it requires that a significant fraction :math:`{\\theta_r}` of each true anomaly
995
+ segment be detected, and that a significant fraction :math:`{\\theta_p}` of each predicted segment overlaps with the
995
996
  ground truth. Finally, F-score contributions from each event are weighted by the square root of the
996
997
  true segment’s length, providing a compromise between point-wise and segment-wise approaches.
997
998
 
@@ -1000,8 +1001,11 @@ def enhanced_ts_aware_f_score(y_true: np.array, y_pred: np.array, theta_p: float
1000
1001
  The ground truth binary labels for the time series data.
1001
1002
  y_pred (np.array):
1002
1003
  The predicted binary labels for the time series data.
1003
- theta (float):
1004
- Minimum fraction (0 θ 1) of a true segment that must be overlapped
1004
+ theta_p (float):
1005
+ Minimum fraction (0 \\leq :math:`{\\theta_p}` \\leq 1) of a predicted segment that must be overlapped
1006
+ by ground truth to count as detected.
1007
+ theta_r (float):
1008
+ Minimum fraction (0 \\leq :math:`{\\theta_r}` \\leq 1) of a true segment that must be overlapped
1005
1009
  by predictions to count as detected.
1006
1010
 
1007
1011
  Returns:
@@ -1068,7 +1072,7 @@ def affiliation_based_f_score(y_true: np.array, y_pred: np.array, beta=1):
1068
1072
  Calculate affiliation based F-score for anomaly detection in time series.
1069
1073
 
1070
1074
  This metric combines the affiliation-based precision and recall into a single score
1071
- using the harmonic mean, adjusted by a weight β to control the relative importance
1075
+ using the harmonic mean, adjusted by a weight :math:`{\\beta}` to control the relative importance
1072
1076
  of recall versus precision. Since both precision and recall are distance-based,
1073
1077
  the F-score reflects a balance between how well predicted anomalies align with true
1074
1078
  anomalies and vice versa.
@@ -1145,8 +1149,8 @@ def average_detection_count(y_true: np.array, y_pred: np.array):
1145
1149
  """
1146
1150
  Calculate average detection count for anomaly detection in time series.
1147
1151
 
1148
- This metric computes, for each ground-truth anomalous segment, how many points within that segment
1149
- are predicted as anomalous. It then averages these counts across all true anomaly events,
1152
+ This metric computes, for each ground-truth anomalous segment, the percentage of points within that segment
1153
+ that are predicted as anomalous. It then averages these percentages across all true anomaly events,
1150
1154
  providing an estimate of detection coverage per event.
1151
1155
 
1152
1156
  For more information, see the original paper:
@@ -1165,7 +1169,7 @@ def average_detection_count(y_true: np.array, y_pred: np.array):
1165
1169
 
1166
1170
  b = Binary_detection(len(y_true),y_true,y_pred)
1167
1171
  azs = b.get_gt_anomalies_segmentwise()
1168
- a_points = b.get_gt_anomalies_ptwise()
1172
+ a_points = b.get_predicted_anomalies_ptwise()
1169
1173
 
1170
1174
  counts = []
1171
1175
  for az in azs:
@@ -1173,7 +1177,7 @@ def average_detection_count(y_true: np.array, y_pred: np.array):
1173
1177
  for ap in a_points:
1174
1178
  if ap >= az[0] and ap <= az[1]:
1175
1179
  count+=1
1176
- counts.append(count)
1180
+ counts.append(count/(az[1] - az[0] + 1)) # Normalize by segment length
1177
1181
 
1178
1182
  return np.mean(counts)
1179
1183
 
@@ -1182,7 +1186,7 @@ def absolute_detection_distance(y_true: np.array, y_pred: np.array):
1182
1186
  Calculate absolute detection distance for anomaly detection in time series.
1183
1187
 
1184
1188
  This metric computes, for each predicted anomaly point that overlaps a ground-truth anomaly segment,
1185
- the distance from that point to the temporal center of the corresponding segment. It then sums all
1189
+ the relative distance from that point to the temporal center of the corresponding segment. It then sums all
1186
1190
  those distances and divides by the total number of such matching predicted points, yielding the
1187
1191
  mean distance to segment centers for correctly detected points.
1188
1192
 
@@ -1202,14 +1206,15 @@ def absolute_detection_distance(y_true: np.array, y_pred: np.array):
1202
1206
 
1203
1207
  b = Binary_detection(len(y_true),y_true,y_pred)
1204
1208
  azs = b.get_gt_anomalies_segmentwise()
1205
- a_points = b.get_gt_anomalies_ptwise()
1206
-
1209
+ a_points = b.get_predicted_anomalies_ptwise()
1210
+ if len(a_points) == 0:
1211
+ return float('inf')
1207
1212
  distance = 0
1208
1213
  for az in azs:
1209
1214
  for ap in a_points:
1210
1215
  if ap >= az[0] and ap <= az[1]:
1211
1216
  center = int((az[0] + az[1]) / 2)
1212
- distance+=abs(ap - center)
1217
+ distance+=abs(ap - center)/max(1,int((az[0] + az[1]) / 2))
1213
1218
 
1214
1219
  return distance/len(a_points)
1215
1220
 
@@ -1220,14 +1225,20 @@ def total_detected_in_range(y_true: np.array, y_pred: np.array, k: int):
1220
1225
 
1221
1226
  This metric measures the proportion of true anomaly events that are correctly detected.
1222
1227
  It is defined as:
1223
- TDIR = (EM + DA) / (EM + DA + MA)
1228
+
1229
+ .. math::
1230
+ \\text{TDIR} = \\frac{EM + DA}{EM + DA + MA}
1224
1231
 
1225
1232
  Where:
1226
- EM (Exact Match) = number of predicted anomaly segments that exactly match a true anomaly segment.
1227
- DA (Detected Anomaly)= number of true anomaly points not exactly matched where at least one prediction falls
1228
- within a window [i-k, i+k] around the true point index i or within the true segment range.
1229
- FA (False Anomaly) = number of predicted anomaly segments that do not overlap any true anomaly segment
1230
- even within a k-step tolerance window around true points.
1233
+
1234
+ - EM (Exact Match):
1235
+ Number of predicted anomaly segments that exactly match a true anomaly segment.
1236
+ - DA (Detected Anomaly):
1237
+ Number of true anomaly points not exactly matched where at least one prediction falls
1238
+ within a window [i-k, i+k] around the true point index i or within the true segment range.
1239
+ - MA (Missed Anomaly):
1240
+ Number of true anomaly segments that do not overlap any predicted anomaly segment
1241
+ even within a k-step tolerance window around true points.
1231
1242
 
1232
1243
  For more information, see the original paper:
1233
1244
  https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
@@ -1258,14 +1269,20 @@ def detection_accuracy_in_range(y_true: np.array, y_pred: np.array, k: int):
1258
1269
 
1259
1270
  This metric measures the proportion of predicted anomaly events that correspond to true anomalies.
1260
1271
  It is defined as:
1261
- DAIR = (EM + DA) / (EM + DA + FA)
1272
+
1273
+ .. math::
1274
+ \\text{DAIR} = \\frac{EM + DA}{EM + DA + FA}
1262
1275
 
1263
1276
  Where:
1264
- EM (Exact Match) = number of predicted anomaly segments that exactly match a true anomaly segment.
1265
- DA (Detected Anomaly)= number of true anomaly points not exactly matched where at least one prediction falls
1266
- within a window [i-k, i+k] around the true point index i or within the true segment range.
1267
- FA (False Anomaly) = number of predicted anomaly segments that do not overlap any true anomaly segment
1268
- even within a k-step tolerance window around true points.
1277
+
1278
+ - EM (Exact Match):
1279
+ Number of predicted anomaly segments that exactly match a true anomaly segment.
1280
+ - DA (Detected Anomaly):
1281
+ Number of true anomaly points not exactly matched where at least one prediction falls
1282
+ within a window [i-k, i+k] around the true point index i or within the true segment range.
1283
+ - FA (False Anomaly):
1284
+ Number of predicted anomaly segments that do not overlap any true anomaly segment
1285
+ even within a k-step tolerance window around true points.
1269
1286
 
1270
1287
  For more information, see the original paper:
1271
1288
  https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
@@ -1280,7 +1297,7 @@ def detection_accuracy_in_range(y_true: np.array, y_pred: np.array, k: int):
1280
1297
  time steps of a true point counts toward detection.
1281
1298
 
1282
1299
  Returns:
1283
- float: The total detected in range.
1300
+ float: The detection accuracy in range score.
1284
1301
  """
1285
1302
  if np.sum(y_pred) == 0:
1286
1303
  return 0
@@ -1305,13 +1322,21 @@ def weighted_detection_difference(y_true: np.array, y_pred: np.array, k: int):
1305
1322
  not overlap any true anomaly segment (within the same extension).
1306
1323
 
1307
1324
  The final score is:
1308
- WDD = WS - WF*FA
1325
+
1326
+ .. math::
1327
+ \\text{WDD} = \\text{WS} - \\text{WF} \\cdot \\text{FA}
1309
1328
 
1310
1329
  Where:
1311
- WS = Σ weights_true_predictions
1312
- WF = Σ weights_false_positives
1313
- FA (False Anomaly) = number of predicted anomaly segments that do not overlap any true anomaly segment
1314
- even within a k-step tolerance window around true points.
1330
+
1331
+ - WS:
1332
+ Sum of Gaussian weights for all predicted anomaly points that fall
1333
+ within any true anomaly segment (extended by delta time steps at the ends).
1334
+ - WF:
1335
+ Sum of Gaussian weights for all predicted anomaly points that do not
1336
+ overlap any true anomaly segment (within the same extension).
1337
+ - FA (False Anomaly):
1338
+ Number of predicted anomaly segments that do not overlap any true anomaly segment
1339
+ even within a k-step tolerance window around true points.
1315
1340
 
1316
1341
  For more information, see the original paper:
1317
1342
  https://acta.sapientia.ro/content/docs/evaluation-metrics-for-anomaly-detection.pdf
@@ -1398,10 +1423,13 @@ def mean_time_to_detect(y_true: np.array, y_pred: np.array):
1398
1423
 
1399
1424
  This metric quantifies the average detection delay across all true anomaly events.
1400
1425
  For each ground-truth anomaly segment, let i be the index where the segment starts,
1401
- and let j i be the first index within that segment where the model predicts an anomaly.
1426
+ and let :math:`{j \geq i}` be the first index within that segment where the model predicts an anomaly.
1402
1427
  The detection delay for that event is defined as:
1403
- Δ = j - i
1404
- The MTTD is the mean of all such Δ values, one per true anomaly segment, and expresses
1428
+
1429
+ .. math::
1430
+ \Delta t = j - i
1431
+
1432
+ The MTTD is the mean of all such :math:`{\Delta t}` values, one per true anomaly segment, and expresses
1405
1433
  the average number of time steps between the true onset of an anomaly and its first detection.
1406
1434
 
1407
1435
  Parameters:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tsadmetrics
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: =?unknown-8bit?q?Librer=C3=ADa_para_evaluaci=C3=B3n_de_detecci=C3=B3n_de_anomal=C3=ADas?= en series temporales
5
5
  Home-page: https://github.com/pathsko/TSADmetrics
6
6
  Author: Pedro Rafael Velasco Priego
@@ -1,4 +1,4 @@
1
- docs/conf.py,sha256=skVqctOiByesc7wNDW5DpjyTxUCP0wxlpWA1fsJYZhk,1384
1
+ docs/conf.py,sha256=UvAyr0jPk75vQyREMEG3TIs96Pk-hslOgLQUpySp2tw,1645
2
2
  entorno/bin/activate_this.py,sha256=45dnJsdtOWIt5LtVSBmBfB8E7AlKcnhnZe9e3WGclak,1199
3
3
  entorno/bin/rst2html.py,sha256=h4RydG-iAectsUra0lNFGwB4_1mngxrtPPgQrxUWQ3A,643
4
4
  entorno/bin/rst2html4.py,sha256=Xiv3Zb1gk4jT7DYFVlf5w4LJtI5ZI3pW3b1KLxyPS5A,765
@@ -16,7 +16,7 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  tests/test_binary.py,sha256=dj9BsKBo5rpWw4JGiKKoVkg4rIW4YylTie2VxH2DAGo,29787
17
17
  tests/test_non_binary.py,sha256=syANlwm0DKsL6geGeq6nQI6ZVe6T_YXWTyk2-Hmck4s,11308
18
18
  tsadmetrics/__init__.py,sha256=MTWOa43fgOdkMNo5NglCReRnB8hoF0ob2PIvDziCNHw,1575
19
- tsadmetrics/binary_metrics.py,sha256=UdXoITIATf585Kvz5i3xhdqEVUogrUHMmJgxj-HoeB0,62477
19
+ tsadmetrics/binary_metrics.py,sha256=XK1HSkCwg7lIYN0KHrSNDWSFBxlWfubp6U-2fgdCIrU,63587
20
20
  tsadmetrics/metric_utils.py,sha256=fm8v0X37_AlqWpkcUT9r3680QsjLljrHe2YuXkRLAZ4,10873
21
21
  tsadmetrics/non_binary_metrics.py,sha256=O6AqceHrjCVV1kJPBzXQIgtiu6afzoiJz2biNsxf3_4,13389
22
22
  tsadmetrics/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -53,7 +53,7 @@ tsadmetrics/_tsadeval/prts/time_series_metrics/fscore.py,sha256=pJz4iuPyVGNvwsaR
53
53
  tsadmetrics/_tsadeval/prts/time_series_metrics/precision.py,sha256=jLkcMg7UNl25SHtZUBGkP-RV8HsvaZCtjakryl7PFWU,3204
54
54
  tsadmetrics/_tsadeval/prts/time_series_metrics/precision_recall.py,sha256=OhUJSm_I7VZ_gX_SSg8AYUq3_NW9rMIy7lAVsnOFw4Q,417
55
55
  tsadmetrics/_tsadeval/prts/time_series_metrics/recall.py,sha256=LL-0pPer3ymovVRlktaHo5XDzpgiDhWOVfdPOzKR6og,3152
56
- tsadmetrics-0.1.13.dist-info/METADATA,sha256=k3BVjOM_Ife2-uXsEWu3o-6tRTUXUqLDd9I9NBV-61g,831
57
- tsadmetrics-0.1.13.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
58
- tsadmetrics-0.1.13.dist-info/top_level.txt,sha256=s2VIr_ePl-WZbYt9FsYbsDGM7J-Qc5cgpwEOeQ3FVpM,31
59
- tsadmetrics-0.1.13.dist-info/RECORD,,
56
+ tsadmetrics-0.1.15.dist-info/METADATA,sha256=Ks2Kq9EAPqiV8kPwnYUY4Ytzgq4_ig7TwvpcC94Zmjg,831
57
+ tsadmetrics-0.1.15.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
58
+ tsadmetrics-0.1.15.dist-info/top_level.txt,sha256=s2VIr_ePl-WZbYt9FsYbsDGM7J-Qc5cgpwEOeQ3FVpM,31
59
+ tsadmetrics-0.1.15.dist-info/RECORD,,