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
@@ -138,11 +131,6 @@ def initialize(self):
138
131
#parameters = default_parameters
139
132
parameters = parameters_numenta_comparable
140
133
141
- # setup spatial anomaly
142
- if self .useSpatialAnomaly :
143
- # Keep track of value range for spatial anomaly detection
144
- self .minVal = None
145
- self .maxVal = None
146
134
147
135
## setup Enc, SP, TM, Likelihood
148
136
# Make the Encoders. These will convert input data into binary representations.
@@ -245,22 +233,7 @@ def modelRun(self, ts, val):
245
233
#TODO optional: also return an error metric on predictions (RMSE, R2,...)
246
234
247
235
# 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
-
236
+ # handle contextual (raw, likelihood) anomalies
264
237
# -temporal (raw)
265
238
raw = self .tm .anomaly
266
239
temporalAnomaly = raw
@@ -271,7 +244,7 @@ def modelRun(self, ts, val):
271
244
logScore = self .anomalyLikelihood .computeLogLikelihood (like )
272
245
temporalAnomaly = logScore #TODO optional: TM to provide anomaly {none, raw, likelihood}, compare correctness with the py anomaly_likelihood
273
246
274
- anomalyScore = max ( spatialAnomaly , temporalAnomaly ) # this is the "main" anomaly, compared in NAB
247
+ anomalyScore = temporalAnomaly # this is the "main" anomaly, compared in NAB
275
248
276
249
# 5. print stats
277
250
if self .verbose and self .iteration_ % 1000 == 0 :
0 commit comments