tsadmetrics 0.1.17__py3-none-any.whl → 1.0.1__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.
Files changed (143) hide show
  1. {docs_api → docs/add_docs/api_doc}/conf.py +3 -26
  2. {docs_manual → docs/add_docs/full_doc}/conf.py +2 -25
  3. docs/add_docs/manual_doc/conf.py +67 -0
  4. docs/conf.py +1 -1
  5. examples/example_direct_data.py +28 -0
  6. examples/example_direct_single_data.py +25 -0
  7. examples/example_file_reference.py +24 -0
  8. examples/example_global_config_file.py +13 -0
  9. examples/example_metric_config_file.py +19 -0
  10. examples/example_simple_metric.py +8 -0
  11. examples/specific_examples/AbsoluteDetectionDistance_example.py +24 -0
  12. examples/specific_examples/AffiliationbasedFScore_example.py +24 -0
  13. examples/specific_examples/AverageDetectionCount_example.py +24 -0
  14. examples/specific_examples/CompositeFScore_example.py +24 -0
  15. examples/specific_examples/DelayThresholdedPointadjustedFScore_example.py +24 -0
  16. examples/specific_examples/DetectionAccuracyInRange_example.py +24 -0
  17. examples/specific_examples/EnhancedTimeseriesAwareFScore_example.py +24 -0
  18. examples/specific_examples/LatencySparsityawareFScore_example.py +24 -0
  19. examples/specific_examples/MeanTimeToDetect_example.py +24 -0
  20. examples/specific_examples/NabScore_example.py +24 -0
  21. examples/specific_examples/PateFScore_example.py +24 -0
  22. examples/specific_examples/Pate_example.py +24 -0
  23. examples/specific_examples/PointadjustedAtKFScore_example.py +24 -0
  24. examples/specific_examples/PointadjustedAucPr_example.py +24 -0
  25. examples/specific_examples/PointadjustedAucRoc_example.py +24 -0
  26. examples/specific_examples/PointadjustedFScore_example.py +24 -0
  27. examples/specific_examples/RangebasedFScore_example.py +24 -0
  28. examples/specific_examples/SegmentwiseFScore_example.py +24 -0
  29. examples/specific_examples/TemporalDistance_example.py +24 -0
  30. examples/specific_examples/TimeTolerantFScore_example.py +24 -0
  31. examples/specific_examples/TimeseriesAwareFScore_example.py +24 -0
  32. examples/specific_examples/TotalDetectedInRange_example.py +24 -0
  33. examples/specific_examples/VusPr_example.py +24 -0
  34. examples/specific_examples/VusRoc_example.py +24 -0
  35. examples/specific_examples/WeightedDetectionDifference_example.py +24 -0
  36. tsadmetrics/__init__.py +0 -21
  37. tsadmetrics/base/Metric.py +188 -0
  38. tsadmetrics/evaluation/Report.py +25 -0
  39. tsadmetrics/evaluation/Runner.py +253 -0
  40. tsadmetrics/metrics/Registry.py +141 -0
  41. tsadmetrics/metrics/__init__.py +2 -0
  42. tsadmetrics/metrics/spm/PointwiseAucPr.py +62 -0
  43. tsadmetrics/metrics/spm/PointwiseAucRoc.py +63 -0
  44. tsadmetrics/metrics/spm/PointwiseFScore.py +86 -0
  45. tsadmetrics/metrics/spm/PrecisionAtK.py +81 -0
  46. tsadmetrics/metrics/spm/__init__.py +9 -0
  47. tsadmetrics/metrics/tem/dpm/DelayThresholdedPointadjustedFScore.py +83 -0
  48. tsadmetrics/metrics/tem/dpm/LatencySparsityawareFScore.py +76 -0
  49. tsadmetrics/metrics/tem/dpm/MeanTimeToDetect.py +47 -0
  50. tsadmetrics/metrics/tem/dpm/NabScore.py +60 -0
  51. tsadmetrics/metrics/tem/dpm/__init__.py +11 -0
  52. tsadmetrics/metrics/tem/ptdm/AverageDetectionCount.py +53 -0
  53. tsadmetrics/metrics/tem/ptdm/DetectionAccuracyInRange.py +66 -0
  54. tsadmetrics/metrics/tem/ptdm/PointadjustedAtKFScore.py +80 -0
  55. tsadmetrics/metrics/tem/ptdm/TimeseriesAwareFScore.py +248 -0
  56. tsadmetrics/metrics/tem/ptdm/TotalDetectedInRange.py +65 -0
  57. tsadmetrics/metrics/tem/ptdm/WeightedDetectionDifference.py +97 -0
  58. tsadmetrics/metrics/tem/ptdm/__init__.py +12 -0
  59. tsadmetrics/metrics/tem/tmem/AbsoluteDetectionDistance.py +48 -0
  60. tsadmetrics/metrics/tem/tmem/EnhancedTimeseriesAwareFScore.py +252 -0
  61. tsadmetrics/metrics/tem/tmem/TemporalDistance.py +68 -0
  62. tsadmetrics/metrics/tem/tmem/__init__.py +9 -0
  63. tsadmetrics/metrics/tem/tpdm/CompositeFScore.py +104 -0
  64. tsadmetrics/metrics/tem/tpdm/PointadjustedAucPr.py +123 -0
  65. tsadmetrics/metrics/tem/tpdm/PointadjustedAucRoc.py +119 -0
  66. tsadmetrics/metrics/tem/tpdm/PointadjustedFScore.py +96 -0
  67. tsadmetrics/metrics/tem/tpdm/RangebasedFScore.py +236 -0
  68. tsadmetrics/metrics/tem/tpdm/SegmentwiseFScore.py +73 -0
  69. tsadmetrics/metrics/tem/tpdm/__init__.py +12 -0
  70. tsadmetrics/metrics/tem/tstm/AffiliationbasedFScore.py +68 -0
  71. tsadmetrics/metrics/tem/tstm/Pate.py +62 -0
  72. tsadmetrics/metrics/tem/tstm/PateFScore.py +61 -0
  73. tsadmetrics/metrics/tem/tstm/TimeTolerantFScore.py +85 -0
  74. tsadmetrics/metrics/tem/tstm/VusPr.py +51 -0
  75. tsadmetrics/metrics/tem/tstm/VusRoc.py +55 -0
  76. tsadmetrics/metrics/tem/tstm/__init__.py +15 -0
  77. tsadmetrics/{_tsadeval/affiliation/_integral_interval.py → utils/functions_affiliation.py} +377 -9
  78. tsadmetrics/utils/functions_auc.py +393 -0
  79. tsadmetrics/utils/functions_conversion.py +63 -0
  80. tsadmetrics/utils/functions_counting_metrics.py +26 -0
  81. tsadmetrics/{_tsadeval/latency_sparsity_aware.py → utils/functions_latency_sparsity_aware.py} +1 -1
  82. tsadmetrics/{_tsadeval/nabscore.py → utils/functions_nabscore.py} +15 -1
  83. tsadmetrics-1.0.1.dist-info/METADATA +83 -0
  84. tsadmetrics-1.0.1.dist-info/RECORD +91 -0
  85. tsadmetrics-1.0.1.dist-info/top_level.txt +3 -0
  86. entorno/bin/activate_this.py +0 -32
  87. entorno/bin/rst2html.py +0 -23
  88. entorno/bin/rst2html4.py +0 -26
  89. entorno/bin/rst2html5.py +0 -33
  90. entorno/bin/rst2latex.py +0 -26
  91. entorno/bin/rst2man.py +0 -27
  92. entorno/bin/rst2odt.py +0 -28
  93. entorno/bin/rst2odt_prepstyles.py +0 -20
  94. entorno/bin/rst2pseudoxml.py +0 -23
  95. entorno/bin/rst2s5.py +0 -24
  96. entorno/bin/rst2xetex.py +0 -27
  97. entorno/bin/rst2xml.py +0 -23
  98. entorno/bin/rstpep2html.py +0 -25
  99. tests/test_binary.py +0 -946
  100. tests/test_non_binary.py +0 -450
  101. tests/test_utils.py +0 -49
  102. tsadmetrics/_tsadeval/affiliation/_affiliation_zone.py +0 -86
  103. tsadmetrics/_tsadeval/affiliation/_single_ground_truth_event.py +0 -68
  104. tsadmetrics/_tsadeval/affiliation/generics.py +0 -135
  105. tsadmetrics/_tsadeval/affiliation/metrics.py +0 -114
  106. tsadmetrics/_tsadeval/auc_roc_pr_plot.py +0 -295
  107. tsadmetrics/_tsadeval/discontinuity_graph.py +0 -109
  108. tsadmetrics/_tsadeval/eTaPR_pkg/DataManage/File_IO.py +0 -175
  109. tsadmetrics/_tsadeval/eTaPR_pkg/DataManage/Range.py +0 -50
  110. tsadmetrics/_tsadeval/eTaPR_pkg/DataManage/Time_Plot.py +0 -184
  111. tsadmetrics/_tsadeval/eTaPR_pkg/DataManage/__init__.py +0 -0
  112. tsadmetrics/_tsadeval/eTaPR_pkg/__init__.py +0 -0
  113. tsadmetrics/_tsadeval/eTaPR_pkg/etapr.py +0 -386
  114. tsadmetrics/_tsadeval/eTaPR_pkg/tapr.py +0 -362
  115. tsadmetrics/_tsadeval/metrics.py +0 -698
  116. tsadmetrics/_tsadeval/prts/__init__.py +0 -0
  117. tsadmetrics/_tsadeval/prts/base/__init__.py +0 -0
  118. tsadmetrics/_tsadeval/prts/base/time_series_metrics.py +0 -165
  119. tsadmetrics/_tsadeval/prts/basic_metrics_ts.py +0 -121
  120. tsadmetrics/_tsadeval/prts/time_series_metrics/__init__.py +0 -0
  121. tsadmetrics/_tsadeval/prts/time_series_metrics/fscore.py +0 -61
  122. tsadmetrics/_tsadeval/prts/time_series_metrics/precision.py +0 -86
  123. tsadmetrics/_tsadeval/prts/time_series_metrics/precision_recall.py +0 -21
  124. tsadmetrics/_tsadeval/prts/time_series_metrics/recall.py +0 -85
  125. tsadmetrics/_tsadeval/tests.py +0 -376
  126. tsadmetrics/_tsadeval/threshold_plt.py +0 -30
  127. tsadmetrics/_tsadeval/time_tolerant.py +0 -33
  128. tsadmetrics/binary_metrics.py +0 -1652
  129. tsadmetrics/metric_utils.py +0 -98
  130. tsadmetrics/non_binary_metrics.py +0 -372
  131. tsadmetrics/scripts/__init__.py +0 -0
  132. tsadmetrics/scripts/compute_metrics.py +0 -42
  133. tsadmetrics/utils.py +0 -124
  134. tsadmetrics/validation.py +0 -35
  135. tsadmetrics-0.1.17.dist-info/METADATA +0 -54
  136. tsadmetrics-0.1.17.dist-info/RECORD +0 -66
  137. tsadmetrics-0.1.17.dist-info/entry_points.txt +0 -2
  138. tsadmetrics-0.1.17.dist-info/top_level.txt +0 -6
  139. {tests → tsadmetrics/base}/__init__.py +0 -0
  140. /tsadmetrics/{_tsadeval → evaluation}/__init__.py +0 -0
  141. /tsadmetrics/{_tsadeval/affiliation → metrics/tem}/__init__.py +0 -0
  142. /tsadmetrics/{_tsadeval/vus_utils.py → utils/functions_vus.py} +0 -0
  143. {tsadmetrics-0.1.17.dist-info → tsadmetrics-1.0.1.dist-info}/WHEEL +0 -0
tests/test_non_binary.py DELETED
@@ -1,450 +0,0 @@
1
- import unittest
2
- from tsadmetrics import *
3
- import numpy as np
4
- import random
5
-
6
-
7
- class TestPrecisionAtK(unittest.TestCase):
8
-
9
- def setUp(self):
10
- """
11
- Configuración inicial para las pruebas.
12
- """
13
-
14
- self.y_true1 = np.array([0,0,1,1])
15
-
16
-
17
- self.y_pred1 = np.array([0.2, 0.9, 0.3, 0.8])
18
-
19
- self.y_pred2 = np.array([1, 2, 3, 4])
20
-
21
- self.y_pred3 = np.array([3, 4, 1, 2])
22
-
23
- self.y_true2 = np.array([1,1,1,0])
24
-
25
- self.y_pred4 = np.array([3, 4, 1, 2])
26
-
27
-
28
-
29
-
30
- def test_precision_at_k_score(self):
31
- """
32
- Prueba para la función precision_at_k_score.
33
- """
34
- score = round(precision_at_k(self.y_true1, self.y_pred1),2)
35
- expected_score = 0.5
36
- self.assertAlmostEqual(score, expected_score, places=4)
37
-
38
- score = round(precision_at_k(self.y_true1, self.y_pred2),2)
39
- expected_score = 1
40
- self.assertAlmostEqual(score, expected_score, places=4)
41
-
42
- score = round(precision_at_k(self.y_true1, self.y_pred3),2)
43
- expected_score = 0
44
- self.assertAlmostEqual(score, expected_score, places=4)
45
-
46
- score = round(precision_at_k(self.y_true2, self.y_pred4),2)
47
- expected_score = round(2/3,2)
48
- self.assertAlmostEqual(score, expected_score, places=4)
49
-
50
- def test_precision_at_k_score_consistency(self):
51
- try:
52
- for _ in range(100):
53
- y_true = np.random.choice([0, 1], size=(100,))
54
- y_pred = np.random.random( size=(100,))
55
-
56
- score = precision_at_k(y_true, y_pred)
57
- except Exception as e:
58
- self.fail(f"precision_at_k_score raised an exception {e}")
59
-
60
-
61
- class TestAUCROCPW(unittest.TestCase):
62
-
63
- def setUp(self):
64
- """
65
- Configuración inicial para las pruebas.
66
- """
67
-
68
- self.y_true1 = np.array([0,0,1,1])
69
-
70
-
71
- self.y_pred1 = np.array([1, 3, 2, 4])
72
-
73
- self.y_pred2 = np.array([1, 2, 3, 4])
74
-
75
- self.y_pred3 = np.array([4, 4, 4, 4])
76
-
77
-
78
- def test_auc_roc_pw(self):
79
- """
80
- Prueba para la función auc_roc_pw.
81
- """
82
- score = round(auc_roc_pw(self.y_true1, self.y_pred1),2)
83
- expected_score = 0.75
84
- self.assertAlmostEqual(score, expected_score, places=4)
85
-
86
- score = round(auc_roc_pw(self.y_true1, self.y_pred2),2)
87
- expected_score = 1
88
- self.assertAlmostEqual(score, expected_score, places=4)
89
-
90
- score = round(auc_roc_pw(self.y_true1, self.y_pred3),2)
91
- expected_score = 0.5
92
- self.assertAlmostEqual(score, expected_score, places=4)
93
-
94
-
95
- def test_auc_roc_pw_consistency(self):
96
- try:
97
- for _ in range(100):
98
- y_true = np.random.choice([0, 1], size=(100,))
99
- y_pred = np.random.random( size=(100,))
100
-
101
- score = auc_roc_pw(y_true, y_pred)
102
- except Exception as e:
103
- self.fail(f"auc_roc_pw raised an exception {e}")
104
-
105
- class TestAUCPRPW(unittest.TestCase):
106
-
107
- def setUp(self):
108
- """
109
- Configuración inicial para las pruebas.
110
- """
111
-
112
- self.y_true1 = np.array([0,0,1,1])
113
-
114
-
115
- self.y_pred1 = np.array([1, 3, 2, 4])
116
-
117
- self.y_pred2 = np.array([1, 2, 3, 4])
118
-
119
- self.y_pred3 = np.array([4, 4, 4, 4])
120
-
121
-
122
- def test_auc_pr_pw(self):
123
- """
124
- Prueba para la función auc_pr_pw.
125
- """
126
- score = round(auc_pr_pw(self.y_true1, self.y_pred1),2)
127
- expected_score = 0.83
128
- self.assertAlmostEqual(score, expected_score, places=4)
129
-
130
- score = round(auc_pr_pw(self.y_true1, self.y_pred2),2)
131
- expected_score = 1
132
- self.assertAlmostEqual(score, expected_score, places=4)
133
-
134
- score = round(auc_pr_pw(self.y_true1, self.y_pred3),2)
135
- expected_score = 0.5
136
- self.assertAlmostEqual(score, expected_score, places=4)
137
-
138
-
139
- def test_auc_pr_consistency(self):
140
- try:
141
- for _ in range(100):
142
- y_true = np.random.choice([0, 1], size=(100,))
143
- y_pred = np.random.random( size=(100,))
144
-
145
- score = auc_pr_pw(y_true, y_pred)
146
- except Exception as e:
147
- self.fail(f"auc_pr raised an exception {e}")
148
-
149
-
150
-
151
- class TestAUCROCPA(unittest.TestCase):
152
-
153
- def setUp(self):
154
- """
155
- Configuración inicial para las pruebas.
156
- """
157
-
158
- self.y_true1 = np.array([0,0,1,1])
159
-
160
-
161
- self.y_pred1 = np.array([1, 3, 2, 4])
162
-
163
- self.y_pred2 = np.array([1, 2, 3, 4])
164
-
165
- self.y_pred3 = np.array([4, 4, 4, 4])
166
-
167
- self.y_true2 = np.array([0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,1,1,0
168
- ,1,1,1,0,0,1,0,0,1,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,1,1,0,1,1
169
- ,1,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,1,0,0,1,0,0,1,0,1,1])
170
-
171
-
172
- self.y_pred4 = [0.1280475, 0.12059283 ,0.29936968 ,0.85866402 ,0.74071874 ,0.22310849
173
- ,0.11281839 ,0.26133246 ,0.33696106 ,0.01442675 ,0.51962876 ,0.07828833
174
- ,0.45337844 ,0.09444483 ,0.91216588 ,0.18847595 ,0.26828481 ,0.65248919
175
- ,0.46291981 ,0.43730757 ,0.78087553 ,0.45031043 ,0.88661033 ,0.56209352
176
- ,0.45029423 ,0.17638205 ,0.9261279 ,0.58830652 ,0.01602648 ,0.73903379
177
- ,0.61831379 ,0.74779903 ,0.42682106 ,0.82583519 ,0.19709012 ,0.44925962
178
- ,0.62752415 ,0.52458327 ,0.46291768 ,0.33937527 ,0.34868777 ,0.12293847
179
- ,0.84477504 ,0.10225254 ,0.37048167 ,0.04476031 ,0.36680499 ,0.11346155
180
- ,0.10583112 ,0.09493136 ,0.54878736 ,0.68514489 ,0.5940307 ,0.14526962
181
- ,0.69385728 ,0.38888727 ,0.61495304 ,0.06795402 ,0.02894603 ,0.08293609
182
- ,0.22865685 ,0.63531487 ,0.97966126 ,0.31418622 ,0.8943095 ,0.22974177
183
- ,0.94402929 ,0.13140625 ,0.80539267 ,0.40160344 ,0.38151339 ,0.65011626
184
- ,0.71657942 ,0.93297398 ,0.32043329 ,0.54667941 ,0.90645979 ,0.98730183
185
- ,0.82351336 ,0.10404812 ,0.6962921 ,0.72890752 ,0.49700666 ,0.47461103
186
- ,0.59696079 ,0.85876179 ,0.247344 ,0.38187879 ,0.23906861 ,0.5266315
187
- ,0.08171512 ,0.27903375 ,0.61112439 ,0.20784267 ,0.90652453 ,0.87575255
188
- ,0.26972245 ,0.78780138 ,0.37649185 ,0.08467683]
189
-
190
-
191
- def test_auc_roc_pa(self):
192
- """
193
- Prueba para la función auc_pr_pa.
194
- """
195
- score = round(auc_roc_pa(self.y_true1, self.y_pred1),2)
196
- expected_score = 0.5
197
- self.assertAlmostEqual(score, expected_score, places=4)
198
-
199
- score = round(auc_roc_pa(self.y_true1, self.y_pred2),2)
200
- expected_score = 0.5
201
- self.assertAlmostEqual(score, expected_score, places=4)
202
-
203
- score = round(auc_roc_pa(self.y_true1, self.y_pred3),2)
204
- expected_score = 0.25
205
- self.assertAlmostEqual(score, expected_score, places=4)
206
-
207
-
208
- score = round(auc_roc_pa(self.y_true2, self.y_pred4),2)
209
- expected_score = 0.33
210
- self.assertAlmostEqual(score, expected_score, places=4)
211
-
212
-
213
- def test_auc_roc_pa_consistency(self):
214
- y_true, y_pred = [],[]
215
- try:
216
- for _ in range(100):
217
- y_true = np.random.choice([0, 1], size=(100,))
218
- y_pred = np.random.random( size=(100,))
219
- score = auc_roc_pa(y_true, y_pred)
220
- except Exception as e:
221
- self.fail(f"auc_roc_pa raised an exception {e}")
222
-
223
-
224
- class TestAUCPRPA(unittest.TestCase):
225
-
226
- def setUp(self):
227
- """
228
- Configuración inicial para las pruebas.
229
- """
230
-
231
- self.y_true1 = np.array([0,0,1,1])
232
-
233
-
234
- self.y_pred1 = np.array([1, 3, 2, 4])
235
-
236
- self.y_pred2 = np.array([1, 2, 3, 4])
237
-
238
- self.y_pred3 = np.array([4, 4, 4, 4])
239
-
240
- self.y_true2 = np.array([0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,1,1,0
241
- ,1,1,1,0,0,1,0,0,1,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,1,1,0,1,1
242
- ,1,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,1,0,0,1,0,0,1,0,1,1])
243
-
244
-
245
- self.y_pred4 = [0.1280475, 0.12059283 ,0.29936968 ,0.85866402 ,0.74071874 ,0.22310849
246
- ,0.11281839 ,0.26133246 ,0.33696106 ,0.01442675 ,0.51962876 ,0.07828833
247
- ,0.45337844 ,0.09444483 ,0.91216588 ,0.18847595 ,0.26828481 ,0.65248919
248
- ,0.46291981 ,0.43730757 ,0.78087553 ,0.45031043 ,0.88661033 ,0.56209352
249
- ,0.45029423 ,0.17638205 ,0.9261279 ,0.58830652 ,0.01602648 ,0.73903379
250
- ,0.61831379 ,0.74779903 ,0.42682106 ,0.82583519 ,0.19709012 ,0.44925962
251
- ,0.62752415 ,0.52458327 ,0.46291768 ,0.33937527 ,0.34868777 ,0.12293847
252
- ,0.84477504 ,0.10225254 ,0.37048167 ,0.04476031 ,0.36680499 ,0.11346155
253
- ,0.10583112 ,0.09493136 ,0.54878736 ,0.68514489 ,0.5940307 ,0.14526962
254
- ,0.69385728 ,0.38888727 ,0.61495304 ,0.06795402 ,0.02894603 ,0.08293609
255
- ,0.22865685 ,0.63531487 ,0.97966126 ,0.31418622 ,0.8943095 ,0.22974177
256
- ,0.94402929 ,0.13140625 ,0.80539267 ,0.40160344 ,0.38151339 ,0.65011626
257
- ,0.71657942 ,0.93297398 ,0.32043329 ,0.54667941 ,0.90645979 ,0.98730183
258
- ,0.82351336 ,0.10404812 ,0.6962921 ,0.72890752 ,0.49700666 ,0.47461103
259
- ,0.59696079 ,0.85876179 ,0.247344 ,0.38187879 ,0.23906861 ,0.5266315
260
- ,0.08171512 ,0.27903375 ,0.61112439 ,0.20784267 ,0.90652453 ,0.87575255
261
- ,0.26972245 ,0.78780138 ,0.37649185 ,0.08467683]
262
-
263
-
264
- def test_auc_pr_pa(self):
265
- """
266
- Prueba para la función auc_pr_pa.
267
- """
268
- score = round(auc_pr_pa(self.y_true1, self.y_pred1),2)
269
- expected_score = 1.0
270
- self.assertAlmostEqual(score, expected_score, places=4)
271
-
272
- score = round(auc_pr_pa(self.y_true1, self.y_pred2),2)
273
- expected_score = 1.0
274
- self.assertAlmostEqual(score, expected_score, places=4)
275
-
276
- score = round(auc_pr_pa(self.y_true1, self.y_pred3),2)
277
- expected_score = 0.75
278
- self.assertAlmostEqual(score, expected_score, places=4)
279
-
280
-
281
- score = round(auc_pr_pa(self.y_true2, self.y_pred4),2)
282
- expected_score = 0.78
283
- self.assertAlmostEqual(score, expected_score, places=4)
284
-
285
-
286
- def test_auc_pr_pa_consistency(self):
287
- y_true, y_pred = [],[]
288
- try:
289
- for _ in range(100):
290
- y_true = np.random.choice([0, 1], size=(100,))
291
- y_pred = np.random.random( size=(100,))
292
- score = auc_pr_pa(y_true, y_pred)
293
- except Exception as e:
294
- self.fail(f"auc_roc_pr_pa raised an exception {e}")
295
-
296
-
297
-
298
-
299
-
300
- class TestVUSROC(unittest.TestCase):
301
-
302
- def setUp(self):
303
- """
304
- Configuración inicial para las pruebas.
305
- """
306
-
307
- self.y_true1 = np.array([1, 1, 0, 0, 0, 0, 0, 0, 0, 0])
308
- self.y_true2 = np.array([0, 1, 0, 1, 0, 0, 0, 0, 0, 0])
309
-
310
- self.y_pred1 = np.array( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
311
-
312
- self.y_pred2 = np.array([8, 0, 9, 1, 7, 2, 3, 4, 5, 6])
313
-
314
-
315
-
316
-
317
- def test_vus_roc(self):
318
- """
319
- Prueba para la función vus_roc.
320
- """
321
- score = round(vus_roc(self.y_true1, self.y_pred1,window=4),2)
322
- self.assertTrue(score <= 0.1)
323
-
324
- score = round(vus_roc(self.y_true2, self.y_pred2,window=4),2)
325
- self.assertTrue(score > 0.4)
326
-
327
- score = vus_roc(self.y_true2, self.y_pred2,window=0)
328
- self.assertTrue(score < 0.4)
329
-
330
-
331
- def test_vus_roc_consistency(self):
332
- try:
333
- for _ in range(10):
334
- y_true = np.random.choice([0, 1], size=(100,))
335
- y_pred = np.random.random( size=(100,))
336
- score = vus_roc(y_true, y_pred, window=4)
337
- except Exception as e:
338
- self.fail(f"auc_roc raised an exception {e}")
339
-
340
-
341
- class TestVUSPR(unittest.TestCase):
342
-
343
- def setUp(self):
344
- """
345
- Configuración inicial para las pruebas.
346
- """
347
-
348
- self.y_true1 = np.array([1, 1, 0, 0, 0, 0, 0, 0, 0, 0])
349
- self.y_true2 = np.array([0, 1, 0, 1, 0, 0, 0, 0, 0, 0])
350
-
351
- self.y_pred1 = np.array( [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
352
-
353
- self.y_pred2 = np.array([8, 0, 9, 1, 7, 2, 3, 4, 5, 6])
354
-
355
-
356
-
357
-
358
- def test_vus_pr(self):
359
- """
360
- Prueba para la función vus_pr.
361
- """
362
- score = round(vus_pr(self.y_true1, self.y_pred1,window=4),2)
363
- self.assertTrue(score <= 0.2)
364
-
365
- score = round(vus_pr(self.y_true2, self.y_pred2,window=4),2)
366
- self.assertTrue(score > 0.5)
367
-
368
- score = vus_pr(self.y_true2, self.y_pred2,window=0)
369
- self.assertTrue(score < 0.5)
370
-
371
-
372
- def test_vus_pr_consistency(self):
373
- try:
374
- for _ in range(10):
375
- y_true = np.random.choice([0, 1], size=(100,))
376
- y_pred = np.random.random( size=(100,))
377
- score = vus_pr(y_true, y_pred, window=4)
378
- except Exception as e:
379
- self.fail(f"auc_roc raised an exception {e}")
380
-
381
-
382
- class TestNonBinaryPATE(unittest.TestCase):
383
-
384
- def setUp(self):
385
- """
386
- Configuración inicial para las pruebas.
387
- """
388
- self.y_true1 = np.array([0,0,1,1])
389
-
390
-
391
- self.y_pred1 = np.array([1, 3, 2, 4])
392
-
393
- self.y_pred2 = np.array([1, 2, 3, 4])
394
-
395
- self.y_pred3 = np.array([4, 4, 4, 4])
396
-
397
- self.y_true2 = np.array([0,1,1,0,0,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,1,1,0
398
- ,1,1,1,0,0,1,0,0,1,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,1,1,1,1,1,0,1,1
399
- ,1,1,1,1,0,0,1,1,1,1,0,1,0,0,1,1,1,0,0,1,0,0,1,0,1,1])
400
-
401
-
402
- self.y_pred4 = [0.1280475, 0.12059283 ,0.29936968 ,0.85866402 ,0.74071874 ,0.22310849
403
- ,0.11281839 ,0.26133246 ,0.33696106 ,0.01442675 ,0.51962876 ,0.07828833
404
- ,0.45337844 ,0.09444483 ,0.91216588 ,0.18847595 ,0.26828481 ,0.65248919
405
- ,0.46291981 ,0.43730757 ,0.78087553 ,0.45031043 ,0.88661033 ,0.56209352
406
- ,0.45029423 ,0.17638205 ,0.9261279 ,0.58830652 ,0.01602648 ,0.73903379
407
- ,0.61831379 ,0.74779903 ,0.42682106 ,0.82583519 ,0.19709012 ,0.44925962
408
- ,0.62752415 ,0.52458327 ,0.46291768 ,0.33937527 ,0.34868777 ,0.12293847
409
- ,0.84477504 ,0.10225254 ,0.37048167 ,0.04476031 ,0.36680499 ,0.11346155
410
- ,0.10583112 ,0.09493136 ,0.54878736 ,0.68514489 ,0.5940307 ,0.14526962
411
- ,0.69385728 ,0.38888727 ,0.61495304 ,0.06795402 ,0.02894603 ,0.08293609
412
- ,0.22865685 ,0.63531487 ,0.97966126 ,0.31418622 ,0.8943095 ,0.22974177
413
- ,0.94402929 ,0.13140625 ,0.80539267 ,0.40160344 ,0.38151339 ,0.65011626
414
- ,0.71657942 ,0.93297398 ,0.32043329 ,0.54667941 ,0.90645979 ,0.98730183
415
- ,0.82351336 ,0.10404812 ,0.6962921 ,0.72890752 ,0.49700666 ,0.47461103
416
- ,0.59696079 ,0.85876179 ,0.247344 ,0.38187879 ,0.23906861 ,0.5266315
417
- ,0.08171512 ,0.27903375 ,0.61112439 ,0.20784267 ,0.90652453 ,0.87575255
418
- ,0.26972245 ,0.78780138 ,0.37649185 ,0.08467683]
419
-
420
- def test_real_pate(self):
421
- """
422
- Prueba para la función real_pate.
423
- """
424
- score = round(real_pate(self.y_true1, self.y_pred1,early=1, delay=1),2)
425
- expected_score = 0.79
426
- self.assertAlmostEqual(score, expected_score, places=4)
427
-
428
- score = round(real_pate(self.y_true1, self.y_pred2,early=1, delay=1),2)
429
- expected_score = 1.0
430
- self.assertAlmostEqual(score, expected_score, places=4)
431
-
432
- score = round(real_pate(self.y_true1, self.y_pred3,early=1, delay=1),2)
433
- expected_score = 0.75
434
- self.assertAlmostEqual(score, expected_score, places=4)
435
-
436
-
437
- score = round(real_pate(self.y_true2, self.y_pred4,early=5, delay=5),2)
438
- expected_score = 0.67
439
- self.assertAlmostEqual(score, expected_score, places=4)
440
-
441
-
442
- def test_real_pate_consistency(self):
443
- try:
444
- for _ in range(10):
445
- y_true = np.random.choice([0, 1], size=(100,))
446
- y_pred = np.random.random( size=(100,))
447
-
448
- score = real_pate(y_true, y_pred, early=5, delay=5)
449
- except Exception as e:
450
- self.fail(f"real_pate raised an exception {e}")
tests/test_utils.py DELETED
@@ -1,49 +0,0 @@
1
- import unittest
2
- from tsadmetrics import *
3
- import os
4
- import numpy as np
5
- import random
6
-
7
- class TestComputeMetrics(unittest.TestCase):
8
- def setUp(self):
9
- self.y_true = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
10
- self.y_pred_binary = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
11
- self.y_pred_non_binary = np.array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.12, 0.11, 0.21, 0.13, 0.4, 0.3, 0.2, 0.1, 0.32, 0.98, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
12
-
13
-
14
- def test_compute_metrics_binary(self):
15
- metrics = [
16
- ('point_wise_f_score', point_wise_f_score),
17
- ('segment_wise_f_score', segment_wise_f_score),
18
- ]
19
- metrics_params = {}
20
-
21
- results = compute_metrics(self.y_true, self.y_pred_binary, metrics, metrics_params)
22
-
23
- self.assertTrue('point_wise_f_score' in results['metric_name'].values)
24
- self.assertTrue('segment_wise_f_score' in results['metric_name'].values)
25
-
26
- def test_compute_metrics_non_binary(self):
27
- metrics = [
28
- ('vus_roc', vus_roc),
29
- ('vus_pr', vus_pr),
30
- ]
31
- metrics_params = {
32
- 'vus_roc': {'window': 3},
33
- 'vus_pr': {'window': 3}}
34
-
35
- results = compute_metrics(self.y_true, self.y_pred_non_binary, metrics, metrics_params, is_anomaly_score=True)
36
-
37
- self.assertTrue('vus_roc' in results['metric_name'].values)
38
- self.assertTrue('vus_pr' in results['metric_name'].values)
39
-
40
- class TestComputeMetricsFromFile(unittest.TestCase):
41
- def setUp(self):
42
- self.y_true = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1])
43
- self.y_pred_binary = np.array([0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
44
- self.results_file = 'tests/test_data/results.csv'
45
- self.conf_file = 'tests/test_data/config.json'
46
-
47
- def test_compute_metrics_from_file(self):
48
- results_df = compute_metrics_from_file(self.results_file, self.conf_file, output_dir='tests/test_data')
49
- assert os.path.exists('tests/test_data/computed_metrics.csv'), f"Error: The file 'computed_metrics.csv' was not created."
@@ -1,86 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- from ._integral_interval import interval_intersection
4
-
5
- def t_start(j, Js = [(1,2),(3,4),(5,6)], Trange = (1,10)):
6
- """
7
- Helper for `E_gt_func`
8
-
9
- :param j: index from 0 to len(Js) (included) on which to get the start
10
- :param Js: ground truth events, as a list of couples
11
- :param Trange: range of the series where Js is included
12
- :return: generalized start such that the middle of t_start and t_stop
13
- always gives the affiliation zone
14
- """
15
- b = max(Trange)
16
- n = len(Js)
17
- if j == n:
18
- return(2*b - t_stop(n-1, Js, Trange))
19
- else:
20
- return(Js[j][0])
21
-
22
- def t_stop(j, Js = [(1,2),(3,4),(5,6)], Trange = (1,10)):
23
- """
24
- Helper for `E_gt_func`
25
-
26
- :param j: index from 0 to len(Js) (included) on which to get the stop
27
- :param Js: ground truth events, as a list of couples
28
- :param Trange: range of the series where Js is included
29
- :return: generalized stop such that the middle of t_start and t_stop
30
- always gives the affiliation zone
31
- """
32
- if j == -1:
33
- a = min(Trange)
34
- return(2*a - t_start(0, Js, Trange))
35
- else:
36
- return(Js[j][1])
37
-
38
- def E_gt_func(j, Js, Trange):
39
- """
40
- Get the affiliation zone of element j of the ground truth
41
-
42
- :param j: index from 0 to len(Js) (excluded) on which to get the zone
43
- :param Js: ground truth events, as a list of couples
44
- :param Trange: range of the series where Js is included, can
45
- be (-math.inf, math.inf) for distance measures
46
- :return: affiliation zone of element j of the ground truth represented
47
- as a couple
48
- """
49
- range_left = (t_stop(j-1, Js, Trange) + t_start(j, Js, Trange))/2
50
- range_right = (t_stop(j, Js, Trange) + t_start(j+1, Js, Trange))/2
51
- return((range_left, range_right))
52
-
53
- def get_all_E_gt_func(Js, Trange):
54
- """
55
- Get the affiliation partition from the ground truth point of view
56
-
57
- :param Js: ground truth events, as a list of couples
58
- :param Trange: range of the series where Js is included, can
59
- be (-math.inf, math.inf) for distance measures
60
- :return: affiliation partition of the events
61
- """
62
- # E_gt is the limit of affiliation/attraction for each ground truth event
63
- E_gt = [E_gt_func(j, Js, Trange) for j in range(len(Js))]
64
- return(E_gt)
65
-
66
- def affiliation_partition(Is = [(1,1.5),(2,5),(5,6),(8,9)], E_gt = [(1,2.5),(2.5,4.5),(4.5,10)]):
67
- """
68
- Cut the events into the affiliation zones
69
- The presentation given here is from the ground truth point of view,
70
- but it is also used in the reversed direction in the main function.
71
-
72
- :param Is: events as a list of couples
73
- :param E_gt: range of the affiliation zones
74
- :return: a list of list of intervals (each interval represented by either
75
- a couple or None for empty interval). The outer list is indexed by each
76
- affiliation zone of `E_gt`. The inner list is indexed by the events of `Is`.
77
- """
78
- out = [None] * len(E_gt)
79
- for j in range(len(E_gt)):
80
- E_gt_j = E_gt[j]
81
- discarded_idx_before = [I[1] < E_gt_j[0] for I in Is] # end point of predicted I is before the begin of E
82
- discarded_idx_after = [I[0] > E_gt_j[1] for I in Is] # start of predicted I is after the end of E
83
- kept_index = [not(a or b) for a, b in zip(discarded_idx_before, discarded_idx_after)]
84
- Is_j = [x for x, y in zip(Is, kept_index)]
85
- out[j] = [interval_intersection(I, E_gt[j]) for I in Is_j]
86
- return(out)
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- import math
4
- from ._affiliation_zone import (
5
- get_all_E_gt_func,
6
- affiliation_partition)
7
- from ._integral_interval import (
8
- integral_interval_distance,
9
- integral_interval_probaCDF_precision,
10
- integral_interval_probaCDF_recall,
11
- interval_length,
12
- sum_interval_lengths)
13
-
14
- def affiliation_precision_distance(Is = [(1,2),(3,4),(5,6)], J = (2,5.5)):
15
- """
16
- Compute the individual average distance from Is to a single ground truth J
17
-
18
- :param Is: list of predicted events within the affiliation zone of J
19
- :param J: couple representating the start and stop of a ground truth interval
20
- :return: individual average precision directed distance number
21
- """
22
- if all([I is None for I in Is]): # no prediction in the current area
23
- return(math.nan) # undefined
24
- return(sum([integral_interval_distance(I, J) for I in Is]) / sum_interval_lengths(Is))
25
-
26
- def affiliation_precision_proba(Is = [(1,2),(3,4),(5,6)], J = (2,5.5), E = (0,8)):
27
- """
28
- Compute the individual precision probability from Is to a single ground truth J
29
-
30
- :param Is: list of predicted events within the affiliation zone of J
31
- :param J: couple representating the start and stop of a ground truth interval
32
- :param E: couple representing the start and stop of the zone of affiliation of J
33
- :return: individual precision probability in [0, 1], or math.nan if undefined
34
- """
35
- if all([I is None for I in Is]): # no prediction in the current area
36
- return(math.nan) # undefined
37
- return(sum([integral_interval_probaCDF_precision(I, J, E) for I in Is]) / sum_interval_lengths(Is))
38
-
39
- def affiliation_recall_distance(Is = [(1,2),(3,4),(5,6)], J = (2,5.5)):
40
- """
41
- Compute the individual average distance from a single J to the predictions Is
42
-
43
- :param Is: list of predicted events within the affiliation zone of J
44
- :param J: couple representating the start and stop of a ground truth interval
45
- :return: individual average recall directed distance number
46
- """
47
- Is = [I for I in Is if I is not None] # filter possible None in Is
48
- if len(Is) == 0: # there is no prediction in the current area
49
- return(math.inf)
50
- E_gt_recall = get_all_E_gt_func(Is, (-math.inf, math.inf)) # here from the point of view of the predictions
51
- Js = affiliation_partition([J], E_gt_recall) # partition of J depending of proximity with Is
52
- return(sum([integral_interval_distance(J[0], I) for I, J in zip(Is, Js)]) / interval_length(J))
53
-
54
- def affiliation_recall_proba(Is = [(1,2),(3,4),(5,6)], J = (2,5.5), E = (0,8)):
55
- """
56
- Compute the individual recall probability from a single ground truth J to Is
57
-
58
- :param Is: list of predicted events within the affiliation zone of J
59
- :param J: couple representating the start and stop of a ground truth interval
60
- :param E: couple representing the start and stop of the zone of affiliation of J
61
- :return: individual recall probability in [0, 1]
62
- """
63
- Is = [I for I in Is if I is not None] # filter possible None in Is
64
- if len(Is) == 0: # there is no prediction in the current area
65
- return(0)
66
- E_gt_recall = get_all_E_gt_func(Is, E) # here from the point of view of the predictions
67
- Js = affiliation_partition([J], E_gt_recall) # partition of J depending of proximity with Is
68
- return(sum([integral_interval_probaCDF_recall(I, J[0], E) for I, J in zip(Is, Js)]) / interval_length(J))