Learning from multiple sequences

I posted a question about a month ago on reddit on specific time-series prediction problem:

Someone contacted me and suggested HTM. I’ve now watched through HTM school videos and reviewed nupic documentation. I don’t see how one can learn from multiple sequences in nupic. In temporal memory video from HTM school, Matt shows that is possible as the two sequences are “boys eat many cakes” and “girls eat meany pies”. Can one run swarming on multiple sequences (either multiple csv files or a column in a csv file representing sequence id), beacuse as far as i see from documentation this is not possible.

EDIT: i only mentioned swarming but i’m really also interested in other functionalities. Can OPF or Algorithm API deal with multiple sequences? If it’s not supported for swarming but is supported for one of these i can still do something like a grid search quite easily.

1 Like

If I understand your Reddit question, you can use HTM/NuPIC on this task simply by inserting a reset signal between each sequence. You can predict distributions - NuPIC will give you probabilities of likely future values. One thing that is more difficult is predict values you’ve never seen.

I would recommend starting without swarming at first, starting with the hotgym parameter set.

1 Like

I see. I’m guessing you mean resetSequenceStates() function. That looks like exactly what i need. Thank you.

One more thing. If i want all sequences to be equally important (i don’t want model to forget), should i set the alpha parameter to 0?

Same question i have.
ResetSequence didnt help in that… at least strange thing anyway happens.
I have learn one sequence and it recognized on test data with learning disabled.
But when i add one more sequence with ResetSequnce and test on same data there is no first sequence that detected before.

So you are trying to teach a model to classify two sequences? When you say “it recognized on test data” how were you determining that?

Yes… i am trying to teach 2 sequences. I send ::datetime, delta(float), signal(CategoryEncoder).
Then in last row on sequence i send signal field value not equal zero (for example 10) and then ResetSequenceStates…
Second sequence doind the same way with signal value 11.

I determine that sequence is recognized when predicted field signal return non zero in my case 10.

Is signal a numeric value? If so, you should not use the CategoryEncoder. That is meant for strings. You would use one of the scalar encoders.

I convert that in string when call run function. That just sequence number that i detect what sequenve is recognized.

I think I could help you if I could see your:

  1. model params
  2. sample line of data (with headers)

Thanks.
Here is one sequence.
I didn`t use swarming and model params configured manually for best result.


'version': 1,
'inferenceArgs': { },
'modelParams': {
    'inferenceType': 'TemporalMultiStep',
    'sensorParams': {
        'verbosity': 0,
        'encoders': {
            'timestamp': {'fieldname': 'timestamp',
                          'name': 'timestamp',
                          'type': 'DateEncoder',
                          'timeOfDay': (39, 0.05),
                         },
            'deltaData': {
                'fieldname': u'deltaData',
                'type': 'RandomDistributedScalarEncoder',
                'resolution': 1,
            },
            'signal':{
                'fieldname': u'signal',
                'classifierOnly': True,
                'type': 'SDRCategoryEncoder',
                'name': '_classifierInput',
                'w': 21,
                'n': 121,
            }
        },
        'sensorAutoReset' : None,
    },

    'spEnable': True,
    'spParams': {'boostStrength': 0.0,
                 'columnCount': 2048,
                 'globalInhibition': 1,
                 'inputWidth': 0,
                 'numActiveColumnsPerInhArea': 40,
                 'potentialPct': 0.8,
                 'seed': 1956,
                 'spVerbosity': 0,
                 'spatialImp': 'cpp',
                 'synPermActiveInc': 0.05,
                 'synPermConnected': 0.1,
                 'synPermInactiveDec': 0.05015},

    'tmEnable': True,
    'tmParams': {'activationThreshold': 14,
                 'cellsPerColumn': 32,
                 'columnCount': 2048,
                 'globalDecay': 0.0,
                 'initialPerm': 20.21,
                 'inputWidth': 2048,
                 'maxAge': 0,
                 'maxSegmentsPerCell': 128,
                 'maxSynapsesPerSegment': 32,
                 'minThreshold': 10,
                 'newSynapseCount': 20,
                 'outputType': 'normal',
                 'pamLength': 5,
                 'permanenceInc': 0.9,
                 'permanenceDec': 0.001,
                 'seed': 1960,
                 'temporalImp': 'cpp',
                 'verbosity': 0},

    'clParams': {
        'implementation': 'cpp',
        'regionName' : 'SDRClassifierRegion',
        'verbosity' : 0,
        'alpha': 0.001,
        'steps': '1',
    },
    'trainSPNetOnlyIfRequested': False,
},

}

---- DATA ----
timestamp,deltaData,signal
datetime,float,string
T,
2017-01-25 12:10:00, 6.0, 0.0
2017-01-25 12:11:00, -14.0, 0.0
2017-01-25 12:12:00, 11.0, 0.0
2017-01-25 12:13:00, -22.0, 0.0
2017-01-25 12:14:00, -11.0, 0.0
2017-01-25 12:15:00, -3.0 0.0
2017-01-25 12:16:00, -5.0, 0.0
2017-01-25 12:17:00, -64.0, 0.0
2017-01-25 12:18:00, 1.0, 0.0
2017-01-25 12:19:00, -21.0, 0.0
2017-01-25 12:20:00, -6.0, 0.0
2017-01-25 12:21:00, -18.0, 0.0
2017-01-25 12:22:00, 17.0, 0.0
2017-01-25 12:23:00, -48.0, 0.0
2017-01-25 12:24:00, 8.0, 0.0
2017-01-25 12:25:00, -12.0, 0.0
2017-01-25 12:26:00, 2.0, 0.0
2017-01-25 12:27:00, 31.0, 0.0
2017-01-25 12:28:00, 4.0, 0.0
2017-01-25 12:29:00, -3.0, 19.0

We have an encoder specifically for delta values: DeltaEncoder. You might try using the actual values with both a DeltaEncoder and another scalar encoder.

Also, so I can better understand the fields, you’re trying to predict the deltaData value some point in the future, right? And the signal is a field you think might contribute to this prediction somehow?

Point is predict to signal field… i.e. when i get predicted signal field with 19 (in current sample) i assume that sequence found on stream data…

Is it right to send category id/name at end of sequence?
It still strange… i have 2 sequences… all time it`s detect last teached.
i.e. i send first sequence and then second… then detecting only second and vice versa.

I’m sorry @RulonOboev but I don’t understand what you are asking. I think perhaps there is a language barrier. Can you try to put your thoughts into different words?

Ok. i guess sample will help.
i have 2 sequences… ABC and BCE.
I teach ABC then send resetSequence and teach BCE and resetSequence.
And then i disableLarning.
And after teaching i put data to nupic… after some rows (depends on modelParams setting ) it detect only BCE…
When i change sequence order in teaching. i.e. first i teach BCE and then ABC.
It`s going detect only ABC and no BCE.

Why is that ?

Thank you.

How many times does it see each pattern? One thing you could do is alternate the patterns when you are training it so one does not override the other.

1 Like

Thank you, Matt.
I have increase teach repeating to 300 and above and it help to detecting/recognize several learned sequences in one HTM.

1 Like

One more question:
There is some strange behavior with negative values.
To be precise, when a positive value follows a negative value and vice versa.

Looks like it reset sequence while training or when processing streaming data.

Do i need to avoid negative values? Or there another way to pass negative values ?

Thanks you.

Can you show me your latest model params?

MODEL_PARAMS = {
    'model': "HTMPrediction",
    'version': 1,
    'inferenceArgs': {
    },
    'modelParams': {
        'inferenceType': 'TemporalMultiStep',
        'sensorParams': {
            'verbosity': 0,
            'encoders': {
                'Delta': {
                    'fieldname': u'Delta',
                    'type': 'RandomDistributedScalarEncoder',
                    'resolution': 0.01,
                    #'w': 81,
                    #'n': 1600,
                },
                'signal':{
                    'fieldname': u'signal',
                    'classifierOnly': True,
                    'type': 'SDRCategoryEncoder',
                    'name': '_classifierInput',
                    #'categoryList':['19.0','-19.0'],
                    'w': 21,
                    'n': 121,
                }
            },
            'sensorAutoReset' : None,
        },

        'spEnable': True,
        'spParams': {'boostStrength': 0.0,
                     'columnCount': 2048,
                     'globalInhibition': 1,
                     'inputWidth': 0,
                     'numActiveColumnsPerInhArea': 40,
                     'potentialPct': 0.8,
                     'seed': 1956,
                     'spVerbosity': 0,
                     'spatialImp': 'cpp',
                     'synPermActiveInc': 0.09,
                     'synPermConnected': 0.01,
                     'synPermInactiveDec': 0.09},

        'tmEnable': True,
        'tmParams': {'activationThreshold': 12,
                     'cellsPerColumn': 32,
                     'columnCount': 2048,
                     'globalDecay': 0.0,
                     'initialPerm': 0.21,
                     'inputWidth': 2048,
                     'maxAge': 0,
                     'maxSegmentsPerCell': 128,
                     'maxSynapsesPerSegment': 32,
                     'minThreshold': 8,
                     'newSynapseCount': 20,
                     'outputType': 'normal',
                     'pamLength': 23,
                     'permanenceInc': 0.05,
                     'permanenceDec': 0.01,
                     'seed': 1960,
                     'temporalImp': 'cpp',
                     'verbosity': 0},

        'clParams': {
            'implementation': 'cpp',
            'regionName' : 'SDRClassifierRegion',
            'verbosity' : 0,
            'alpha': 0.0025,
            'steps': '1',
        },
        'trainSPNetOnlyIfRequested': False,
    },
}