Skip to content

Commit d6023e3

Browse files
committed
Htmcore detector: remove artificial spatial-anomaly code
which is "fake" and non-biological, not HTM related. Unfortunately, with the current settings the code affected the results the most.
1 parent a51f60d commit d6023e3

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

nab/detectors/htmcore/htmcore_detector.py

+2-29
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434

3535
from nab.detectors.base import AnomalyDetector
3636

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-
4337
parameters_numenta_comparable = {
4438
# there are 2 (3) encoders: "value" (RDSE) & "time" (DateTime weekend, timeOfDay)
4539
'enc': {
@@ -96,7 +90,6 @@ def __init__(self, *args, **kwargs):
9690
# useful for checking the efficacy of AnomalyLikelihood. You will need
9791
# to re-optimize the thresholds when running with this setting.
9892
self.useLikelihood = True
99-
self.useSpatialAnomaly = True
10093
self.verbose = True
10194

10295
## internal members
@@ -138,11 +131,6 @@ def initialize(self):
138131
#parameters = default_parameters
139132
parameters = parameters_numenta_comparable
140133

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
146134

147135
## setup Enc, SP, TM, Likelihood
148136
# Make the Encoders. These will convert input data into binary representations.
@@ -245,22 +233,7 @@ def modelRun(self, ts, val):
245233
#TODO optional: also return an error metric on predictions (RMSE, R2,...)
246234

247235
# 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
264237
# -temporal (raw)
265238
raw = self.tm.anomaly
266239
temporalAnomaly = raw
@@ -271,7 +244,7 @@ def modelRun(self, ts, val):
271244
logScore = self.anomalyLikelihood.computeLogLikelihood(like)
272245
temporalAnomaly = logScore #TODO optional: TM to provide anomaly {none, raw, likelihood}, compare correctness with the py anomaly_likelihood
273246

274-
anomalyScore = max(spatialAnomaly, temporalAnomaly) # this is the "main" anomaly, compared in NAB
247+
anomalyScore = temporalAnomaly # this is the "main" anomaly, compared in NAB
275248

276249
# 5. print stats
277250
if self.verbose and self.iteration_ % 1000 == 0:

0 commit comments

Comments
 (0)