To simplify, here’s the sequence of calls:
init model
model = ModelFactory.create(modelConfig=params[“modelConfig”]) model.enableInference(params[“inferenceArgs”])
train & save model
result = model.run(training_data) (looping over each row)
model.save(save_path)
load in model & disable learning
loaded_model = model.load(save_path)
loaded_model.disableLearning()
feed in test data
result = model.run(test_data) (looping over each row)
anomaly_score = result.inferences[‘anomalyScore’]
TM = model._getTPRegion().getSelf().getAlgorithmInstance()
prediction_density = TM.getPredictedState().sum()
The problem is that the prediction density doesn’t match with the anomaly score.
For example:
or
or even
Where activeColumns comes from:
SP = model._getSPRegion()
if SP is not None:
activeColumns = SP.getOutputData("bottomUpOut").nonzero()[0]
else:
sensor = model._getSensorRegion()
activeColumns = sensor.getOutputData('dataOut').nonzero()[0]
And predCols comes from:
TM_infPredState = TM_obj.getPredictedState()
predColumns = [i for i in range(len(TM_infPredState)) if
0 < sum(TM_Cols_PrevPredStates[i]) ]
Here is my model config:
modelConfig = \
{'aggregationInfo': {'days': 0,
'fields': [],
'hours': 0,
'microseconds': 0,
'milliseconds': 0,
'minutes': 0,
'months': 0,
'seconds': 0,
'weeks': 0,
'years': 0},
'model': 'HTMPrediction',
'modelParams': {'anomalyParams': {u'anomalyCacheRecords': None,
u'autoDetectThreshold': None,
u'autoDetectWaitRecords': None},
'inferenceType': 'TemporalAnomaly',
'sensorParams': {
'encoders': encoder_dict,
'sensorAutoReset': None,
'verbosity': 0},
'spEnable': False,
'spParams': {'columnCount': 2048,
'globalInhibition': 1,
'inputWidth': 0,
'boostStrength': 2.0,
'numActiveColumnsPerInhArea': 40,
'potentialPct': 0.8,
'seed': 1956,
'spVerbosity': 0,
'spatialImp': 'cpp',
'synPermActiveInc': 0.05,
'synPermConnected': 0.1,
'synPermInactiveDec': 0.08568228006654939},
'tmEnable': True,
'tmParams': {'activationThreshold': 12,
'cellsPerColumn': 32,
'columnCount': tm_colcount, ## 2100 (3 encoders, each 700 width)
'computePredictedActiveCellIndices': True,
'globalDecay': 0.0,
'initialPerm': 0.21,
'inputWidth': tm_colcount, ## 2100 (3 encoders, each 700 width)
'maxInfBacktrack': 10,
'maxLrnBacktrack': 5,
'maxAge': 0,
'maxSegmentsPerCell': 128,
'maxSynapsesPerSegment': 32,
'minThreshold': 10,
'newSynapseCount': 20,
'outputType': 'normal',
'pamLength': 1,
'permanenceDec': 0.1,
'permanenceInc': 0.1,
'seed': 1960,
'temporalImp': 'cpp',
'verbosity': 0},
'clEnable': False,
'clParams': None,
'trainSPNetOnlyIfRequested': False},
'predictAheadTime': None,
'version': 1}
Could I maybe bug you @Scott as well?
Sorry about this! I wouldn’t be asking if I hadn’t already dug around for many hours!