@@ -38,8 +38,8 @@ def percentile_threshold(y_score: np.ndarray, percentile: int) -> float:
38
38
def sigma_threshold (y_score : np .ndarray , factor : float = 2 ) -> float :
39
39
r"""Calculate a threshold based on the standard deviation of the anomaly scores.
40
40
41
- Computes a threshold :math:`\theta` based on the anomaly scoring's mean
42
- :math:`\mu_s` and the standard deviation :math:`\sigma_s`, ignoring NaNs:
41
+ Computes a threshold :math:`` \theta` ` based on the anomaly scoring's mean
42
+ :math:`` \mu_s`` and the standard deviation :math:`` \sigma_s` `, ignoring NaNs:
43
43
44
44
.. math::
45
45
\theta = \mu_{s} + x \cdot \sigma_{s}
@@ -49,7 +49,7 @@ def sigma_threshold(y_score: np.ndarray, factor: float = 2) -> float:
49
49
y_score : np.ndarray
50
50
Anomaly scores for each point of the time series of shape (n_instances,).
51
51
factor : float
52
- Number of standard deviations to use as threshold (:math:`x `).
52
+ Number of standard deviations to use as threshold (:math:``x` `).
53
53
54
54
Returns
55
55
-------
@@ -62,14 +62,15 @@ def sigma_threshold(y_score: np.ndarray, factor: float = 2) -> float:
62
62
def top_k_points_threshold (
63
63
y_true : np .ndarray , y_score : np .ndarray , k : int | None = None
64
64
) -> float :
65
- """Calculate a threshold such that at least `k ` anomalous points are found.
65
+ """Calculate a threshold such that at least ``k` ` anomalous points are found.
66
66
67
67
The anomalies are single-point anomalies.
68
68
69
69
Computes a threshold based on the number of expected anomalies (number of
70
70
anomalies). This method iterates over all possible thresholds from high to low to
71
- find the first threshold that yields `k` or more anomalous points. If `k` is `None`,
72
- the ground truth data is used to calculate the real number of anomalies.
71
+ find the first threshold that yields ``k`` or more anomalous points. If ``k``
72
+ is ``None``,the ground truth data is used to calculate the real number of
73
+ anomalies.
73
74
74
75
Parameters
75
76
----------
@@ -78,13 +79,13 @@ def top_k_points_threshold(
78
79
y_score : np.ndarray
79
80
Anomaly scores for each point of the time series of shape (n_instances,).
80
81
k : optional int
81
- Number of expected anomalies. If `k` is `None`, the ground truth data is used
82
- to calculate the real number of anomalies.
82
+ Number of expected anomalies. If ``k`` is `` None`` , the ground truth data
83
+ is used to calculate the real number of anomalies.
83
84
84
85
Returns
85
86
-------
86
87
float
87
- Threshold such that there are at least `k ` anomalous points.
88
+ Threshold such that there are at least ``k` ` anomalous points.
88
89
"""
89
90
if k is None :
90
91
return np .nanpercentile (y_score , (1 - y_true .sum () / y_true .shape [0 ]) * 100 )
@@ -95,15 +96,15 @@ def top_k_points_threshold(
95
96
def top_k_ranges_threshold (
96
97
y_true : np .ndarray , y_score : np .ndarray , k : int | None = None
97
98
) -> float :
98
- """Calculate a threshold such that at least `k ` anomalies are found.
99
+ """Calculate a threshold such that at least ``k` ` anomalies are found.
99
100
100
101
The anomalies are either single-points anomalies or continuous anomalous ranges.
101
102
102
103
Computes a threshold based on the number of expected anomalous subsequences /
103
104
ranges (number of anomalies). This method iterates over all possible thresholds
104
105
from high to low to find the first threshold that yields `k` or more continuous
105
- anomalous ranges. If `k` is `None`, the ground truth data is used to calculate the
106
- real number of anomalies (anomalous ranges).
106
+ anomalous ranges. If ``k`` is `` None`` , the ground truth data is used to
107
+ calculate the real number of anomalies (anomalous ranges).
107
108
108
109
Parameters
109
110
----------
@@ -112,13 +113,13 @@ def top_k_ranges_threshold(
112
113
y_score : np.ndarray
113
114
Anomaly scores for each point of the time series of shape (n_instances,).
114
115
k : optional int
115
- Number of expected anomalies. If `k` is `None`, the ground truth data is used
116
- to calculate the real number of anomalies.
116
+ Number of expected anomalies. If ``k`` is `` None`` , the ground truth data
117
+ is used to calculate the real number of anomalies.
117
118
118
119
Returns
119
120
-------
120
121
float
121
- Threshold such that there are at least `k ` anomalous ranges.
122
+ Threshold such that there are at least ``k` ` anomalous ranges.
122
123
"""
123
124
if k is None :
124
125
k = _count_anomaly_ranges (y_true )
0 commit comments