Newbie question: How to get both anomaly score, anomaly likelihood and predictions


I’m trying to create a simple model for detecting anomalies in metrics data (very similar to the HotGym case) but I want to get both the anomaly score, anomaly likelihood and the actual predictions.

I saw a quite old video about the anomaly likelihood in which the presenter (I don’t remember his name…) said that the anomaly likelihood is an external mechanism that is not included in the NUPIC framework but might be in the future. What is the current status of this? Is there a good document on how to get the anomaly likelihood.

As for the anomaly and the prediction, I use these model parameters:

    'model': "HTMPrediction",
    'version': 1,
    'aggregationInfo': {   'days': 0,
        'fields': [('value', 'sum')],
        'hours': 1,
        'microseconds': 0,
        'milliseconds': 0,
        'minutes': 0,
        'months': 0,
        'seconds': 0,
        'weeks': 0,
        'years': 0},
    'predictAheadTime': None,
    'modelParams': {
        'inferenceType': 'TemporalMultiStep',
        'sensorParams': {
            'verbosity' : 0,
            'encoders': {
                u'value':    {
                    'fieldname': u'value',
                    'resolution': 0.88,
                    'seed': 1,
                    'name': u'value',
                    'type': 'RandomDistributedScalarEncoder',
                'timestamp_timeOfDay': {   'fieldname': u'timestamp',
                                           'name': u'timestamp_timeOfDay',
                                           'timeOfDay': (21, 1),
                                           'type': 'DateEncoder'},
                'timestamp_weekend': {   'fieldname': u'timestamp',
                                         'name': u'timestamp_weekend',
                                         'type': 'DateEncoder',
                                         'weekend': 21}
            'sensorAutoReset': None,
        'spEnable': True,
        'spParams': {
            'spVerbosity': 0,
            'spatialImp': 'cpp',
            'globalInhibition': 1,
            'columnCount': 2048,
            'inputWidth': 0,
            'numActiveColumnsPerInhArea': 40,
            'seed': 1956,
            'potentialPct': 0.85,
            'synPermConnected': 0.1,
            'synPermActiveInc': 0.04,
            'synPermInactiveDec': 0.005,
            'boostStrength': 3.0,
        'tmEnable' : True,
        'tmParams': {
            'verbosity': 0,
            'columnCount': 2048,
            'cellsPerColumn': 32,
            'inputWidth': 2048,
            'seed': 1960,
            'temporalImp': 'cpp',
            'newSynapseCount': 20,
            'maxSynapsesPerSegment': 32,
            'maxSegmentsPerCell': 128,
            'initialPerm': 0.21,
            'permanenceInc': 0.1,
            'permanenceDec': 0.1,
            'globalDecay': 0.0,
            'maxAge': 0,
            'minThreshold': 12,
            'activationThreshold': 16,
            'outputType': 'normal',
            'pamLength': 1,
        'clParams': {
            'regionName': 'SDRClassifierRegion',
            'verbosity': 0,
            'alpha': 0.1,
            'steps': '1,5',
            'implementation': 'cpp',
        'trainSPNetOnlyIfRequested': False,

I tried to change the inferenceType to TemporalAnomaly and then I received the anomaly_score but not the prediction and then I changed it to TemporalMultiStep and received the predictions but not the anomaly_score.
Is it possible to receive both?

Thanks a lot,

1 Like

Anomaly likelihood is part of nupic now, there’s a tutorial with code here:

Also, here’s the docs for anomaly detection:

Essentially they are just helpers that give you an anomaly likelihood based on the anomaly score, configured to parameters of your choice.


Thanks a lot!!! I’ll try that today and I’ll let you know.



1 Like


I know it’s been a while… (-: I have been too busy to continue my work on this…
Anyway, I still cannot find a working example of code+model params for computing both an anomaly score or probability and prediction (on step only). Do you know where I can get such an example code?


@artifex Great question, I can also confirm that it is possible, but I also can’t find any code. :frowning: I found something related in the NuPIC code comments, perhaps you can find a lead here until someone else has something better.

Edit: Also found this thread, in which I see pictures of both prediction/anomaly happening, with code:

1 Like

Thanks a lot for your answer! I still hope to get a code sample… It’s pretty tough for me to find the right way to do it in order to get both a prediction and an anomalyScore. Every piece of code I found so far that demonstrated the usage of AnomalyLikelihood also required having the anomaly score and sending it as an argument…

You mentioned that you can confirm that it is possible. How so? Have you found a way to make it work? If so, can you please share your work?