34
34
35
35
from nab .detectors .base import AnomalyDetector
36
36
37
- # Fraction outside of the range of values seen so far that will be considered
38
- # a spatial anomaly regardless of the anomaly likelihood calculation. This
39
- # accounts for the human labelling bias for spatial values larger than what
40
- # has been seen so far.
41
- SPATIAL_TOLERANCE = 0.05
42
-
43
37
parameters_numenta_comparable = {
44
38
# there are 2 (3) encoders: "value" (RDSE) & "time" (DateTime weekend, timeOfDay)
45
39
'enc' : {
@@ -96,7 +90,6 @@ def __init__(self, *args, **kwargs):
96
90
# useful for checking the efficacy of AnomalyLikelihood. You will need
97
91
# to re-optimize the thresholds when running with this setting.
98
92
self .useLikelihood = True
99
- self .useSpatialAnomaly = True
100
93
self .verbose = True
101
94
102
95
## internal members
@@ -245,22 +238,7 @@ def modelRun(self, ts, val):
245
238
#TODO optional: also return an error metric on predictions (RMSE, R2,...)
246
239
247
240
# 4.2 Anomaly
248
- # handle spatial, contextual (raw, likelihood) anomalies
249
- # -Spatial
250
- spatialAnomaly = 0.0 #TODO optional: make this computed in SP (and later improve)
251
- if self .useSpatialAnomaly :
252
- # Update min/max values and check if there is a spatial anomaly
253
- if self .minVal != self .maxVal :
254
- tolerance = (self .maxVal - self .minVal ) * SPATIAL_TOLERANCE
255
- maxExpected = self .maxVal + tolerance
256
- minExpected = self .minVal - tolerance
257
- if val > maxExpected or val < minExpected :
258
- spatialAnomaly = 1.0
259
- if self .maxVal is None or val > self .maxVal :
260
- self .maxVal = val
261
- if self .minVal is None or val < self .minVal :
262
- self .minVal = val
263
-
241
+ # handle contextual (raw, likelihood) anomalies
264
242
# -temporal (raw)
265
243
raw = self .tm .anomaly
266
244
temporalAnomaly = raw
@@ -271,7 +249,7 @@ def modelRun(self, ts, val):
271
249
logScore = self .anomalyLikelihood .computeLogLikelihood (like )
272
250
temporalAnomaly = logScore #TODO optional: TM to provide anomaly {none, raw, likelihood}, compare correctness with the py anomaly_likelihood
273
251
274
- anomalyScore = max ( spatialAnomaly , temporalAnomaly ) # this is the "main" anomaly, compared in NAB
252
+ anomalyScore = temporalAnomaly # this is the "main" anomaly, compared in NAB
275
253
276
254
# 5. print stats
277
255
if self .verbose and self .iteration_ % 1000 == 0 :
0 commit comments