Skip to content

Commit

Permalink
Merge pull request numenta#236 from BoltzmannBrain/nta_params
Browse files Browse the repository at this point in the history
HTM detector use NuPIC params
  • Loading branch information
BoltzmannBrain committed Mar 11, 2016
2 parents a2be152 + 79694b4 commit 0767135
Show file tree
Hide file tree
Showing 66 changed files with 295,256 additions and 295,394 deletions.
12 changes: 6 additions & 6 deletions config/thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
},
"numenta": {
"reward_low_FN_rate": {
"score": 10.305974147007882,
"threshold": 0.5
"score": 9.432068022614288,
"threshold": 0.5126953125
},
"reward_low_FP_rate": {
"score": 9.877035526285063,
"threshold": 0.5
"score": 19.920558339682692,
"threshold": 0.5125976562500002
},
"standard": {
"score": 17.305974147007884,
"threshold": 0.5
"score": 35.432068022614295,
"threshold": 0.5126953125
}
},
"random": {
Expand Down
93 changes: 0 additions & 93 deletions nab/detectors/numenta/modelParams/model_params.json

This file was deleted.

49 changes: 27 additions & 22 deletions nab/detectors/numenta/numenta_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import simplejson as json

from nupic.algorithms import anomaly_likelihood
from nupic.frameworks.opf.common_models.cluster_params import (
getScalarMetricWithTimeOfDayAnomalyParams)
from nupic.frameworks.opf.modelfactory import ModelFactory

from nab.detectors.base import AnomalyDetector
Expand Down Expand Up @@ -66,28 +68,17 @@ def handleRecord(self, inputData):


def initialize(self):
calcRange = abs(self.inputMax - self.inputMin)
calcPad = calcRange * .2

self.inputMin = self.inputMin - calcPad
self.inputMax = self.inputMax + calcPad
# Load the model params JSON

paramsPath = os.path.join(os.path.split(__file__)[0],
"modelParams",
"model_params.json")
with open(paramsPath) as fp:
modelParams = json.load(fp)

self.sensorParams = modelParams["modelParams"]["sensorParams"]\
["encoders"]["value"]

# RDSE - resolution calculation
resolution = max(0.001,
(self.inputMax - self.inputMin) / \
self.sensorParams.pop("numBuckets")
)
self.sensorParams["resolution"] = resolution
# Get config params, setting the RDSE resolution
rangePadding = abs(self.inputMax - self.inputMin) * 0.2
modelParams = getScalarMetricWithTimeOfDayAnomalyParams(
metricData=[0],
minVal=self.inputMin-rangePadding,
maxVal=self.inputMax+rangePadding,
minResolution=0.001
)["modelConfig"]

self._setupEncoderParams(
modelParams["modelParams"]["sensorParams"]["encoders"])

self.model = ModelFactory.create(modelParams)

Expand All @@ -100,3 +91,17 @@ def initialize(self):
estimationSamples=self.probationaryPeriod-numentaLearningPeriod,
reestimationPeriod=100
)


def _setupEncoderParams(self, encoderParams):
# The encoder must expect the NAB-specific datafile headers
encoderParams["timestamp_dayOfWeek"] = encoderParams.pop("c0_dayOfWeek")
encoderParams["timestamp_timeOfDay"] = encoderParams.pop("c0_timeOfDay")
encoderParams["timestamp_timeOfDay"]["fieldname"] = "timestamp"
encoderParams["timestamp_timeOfDay"]["name"] = "timestamp"
encoderParams["timestamp_weekend"] = encoderParams.pop("c0_weekend")
encoderParams["value"] = encoderParams.pop("c1")
encoderParams["value"]["fieldname"] = "value"
encoderParams["value"]["name"] = "value"

self.sensorParams = encoderParams["value"]
10 changes: 5 additions & 5 deletions results/final_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"standard": 0.0
},
"numenta": {
"reward_low_FN_rate": 69.28308927558334,
"reward_low_FP_rate": 56.50002521814655,
"standard": 64.70049598232758
"reward_low_FN_rate": 69.377031040979887,
"reward_low_FP_rate": 58.586447560215518,
"standard": 65.272443113189652
},
"random": {
"reward_low_FN_rate": 25.876351314080456,
Expand All @@ -20,8 +20,8 @@
"standard": 35.687043255862065
},
"twitterADVec": {
"reward_low_FN_rate": 53.501074951005741,
"reward_low_FN_rate": 53.50107495100574,
"reward_low_FP_rate": 33.610051641206894,
"standard": 47.061957254081889
"standard": 47.06195725408189
}
}
Loading

0 comments on commit 0767135

Please sign in to comment.