# Learning from multiple sequences

**URL:** <https://discourse.numenta.org/t/learning-from-multiple-sequences/2358>\
**Category:** NuPIC\
**Tags:** swarming, question\
**Created:** [May 27, 2017, 9:15am UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358 "2017-05-27T09:15:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![simejanko](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@simejanko](https://discourse.numenta.org/u/simejanko)\
**Post date:** [May 27, 2017, 9:15am UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/1 "2017-05-27T09:15:16Z")

</div>

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

> **[r/MLQuestions - Techniques for predictiong future distributions of some...](https://www.reddit.com/r/MLQuestions/comments/65pjpg/techniques_for_predictiong_future_distributions/)**
>
> 1 vote and 0 comments so far on Reddit

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.

---

<div class="post-metadata">

**Author:** ![subutai](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/subutai/32/106_2.png) [@subutai](https://discourse.numenta.org/u/subutai)\
**Post date:** [May 28, 2017, 2:10am UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/2 "2017-05-28T02:10:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![simejanko](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@simejanko](https://discourse.numenta.org/u/simejanko)\
**Post date:** [May 28, 2017, 6:03am UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/3 "2017-05-28T06:03:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [May 31, 2017, 4:08pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/4 "2017-05-31T16:08:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 31, 2017, 4:12pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/5 "2017-05-31T16:12:38Z")

</div>

> [@RulonOboev](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [May 31, 2017, 4:32pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/6 "2017-05-31T16:32:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 31, 2017, 4:34pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/7 "2017-05-31T16:34:48Z")

</div>

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](http://nupic.docs.numenta.org/0.7.0.dev0/api/algorithms/encoders.html#scalar-encoders).

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [May 31, 2017, 4:44pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/8 "2017-05-31T16:44:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 31, 2017, 7:43pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/9 "2017-05-31T19:43:33Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [May 31, 2017, 8:14pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/10 "2017-05-31T20:14:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [May 31, 2017, 9:16pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/11 "2017-05-31T21:16:29Z")

</div>

We have an encoder specifically for delta values: [`DeltaEncoder`](http://nupic.docs.numenta.org/0.7.0.dev0/api/algorithms/encoders.html#nupic.encoders.delta.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?

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [May 31, 2017, 10:04pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/12 "2017-05-31T22:04:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [June 3, 2017, 12:16pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/13 "2017-06-03T12:16:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [June 4, 2017, 4:05pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/14 "2017-06-04T16:05:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [June 4, 2017, 5:51pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/15 "2017-06-04T17:51:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [June 4, 2017, 5:53pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/16 "2017-06-04T17:53:31Z")

</div>

> [@RulonOboev](#):
>
> I teach ABC then send resetSequence and teach BCE and resetSequence.

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.

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [June 6, 2017, 7:36am UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/17 "2017-06-06T07:36:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [June 6, 2017, 8:51pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/18 "2017-06-06T20:51:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [June 6, 2017, 9:00pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/19 "2017-06-06T21:00:36Z")

</div>

Can you show me your latest model params?

---

<div class="post-metadata">

**Author:** ![RulonOboev](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@RulonOboev](https://discourse.numenta.org/u/RulonOboev)\
**Post date:** [June 6, 2017, 9:04pm UTC](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358/20 "2017-06-06T21:04:59Z")

</div>

```python
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,
    },
}

```

[Next page](https://discourse.numenta.org/t/learning-from-multiple-sequences/2358.md?page=2)
