Question on Behavior of resetSequenceStates()

Hi, all.
Recently I’m confused with the role of resetSequenceStates().

My data file contains multiple sequences, each of which is separated by reset flag. (like below)
Reset flag indicates the beginning of each sequence.

Datetime Reset Value1
timestamp int float
T R
2017-05-30 10:39 1 0
2017-05-30 10:40 0 -0.8
2017-05-30 10:41 0 -1.6
… … …
2017-05-30 12:37 0 -6.7
2017-05-30 12:38 0 -6.8
2017-05-30 12:39 1 0
2017-05-30 12:40 0 -1
2017-05-30 12:41 0 -1.5
2017-05-30 12:42 0 -2.1
2017-05-30 12:43 0 -2.3

By reading each row, I call model.resetSequenceStates() whenever I encounter any row having reset flag is ‘1’. By doing so, I wanted to prevent HTM to learn the transition from the end of previous sequence to the beginning of next sequence (from -6.8 to 0 in the example above).

However, I found that the HTM learns unwanted transition and predict 0 with appearance of -6.8 like the figure below (around the position with 216).

So I’m wondering if the behavior of resetSequenceStates() is different from what I have expected.
Is there any way to avoid this and to properly deal with the multiple sequences separated by reset flags? Any help will be appreciated.

That should not be happening. Are you processing this input file manually? Can I see the code?

I notice one different in the field types (row 2) between your code @oreore and this example here:
http://nupic.docs.numenta.org/prerelease/quick-start/example-data.html

In your code you have the reset (‘R’) value as an int:

Datetime Reset Value1
timestamp int float
T R
2017-05-30 10:39 1 0

while in the example it is a bool:

reset,timestamp,value
bool,datetime,float
R,T,
1,2010-07-02 00:00:00,5.4
0,2010-07-02 00:00:15,3.6
0,2010-07-02 00:00:30,2.4
1,2010-09-08 10:00:00,12.7
0,2010-09-08 10:01:15,12.8
0,2010-09-08 10:01:30,13.1

I’m not sure if this is enough to make a difference, though maybe worth trying

1 Like

I attached few lines only here.
The code is referring one of the “Gym” OPF example codes.
What do you mean by “manual”…?
Is there any other way for the model recognizes reset automatically inside in OPF?

Thank you.

with open(_INPUT_FILE_PATH, "rb") as fin:
    reader = unicodecsv.reader(fin, encoding='utf-8')

    headers = reader.next()
    typeDef = np.array(reader.next())
    headerInfo = dict(zip(headers, typeDef))
    reader.next()

    for i, record in enumerate(reader, start=1):
      modelInput = dict(zip(headers, record))
      ....

      # Timestamp
      modelInput[u'Modified_Time'] = datetime.datetime.strptime(modelInput[u'Modified_Time'], "%Y-%m-%d %H:%M")

      actualValue = modelInput[_PREDFIELD]
      timestamp = modelInput[u'Modified_Time']

      # Here I did like below..!
      if modelInput[u'Reset'] == 1:
         model.resetSequenceStates()

      result = model.run(modelInput)
      result = shifter.shift(result)
    
      .....

Yes, there is an experiment runner framework, but I’ve never used it. You need a CSV input file to run swarms over datasets because it does use the experiment runner framework.

Regarding your code… have you tried moving the reset call to the end of the loop after running the model?

Thank you for your reply.

I have tried using bool but I found that it actually does not matter as long as I manually (by additional codes like attached) call the resetSequenceStates().

Is there any mechanism that the model itself recognizes the reset flags on data coming into OPF?

Thank you.

I’ll try calling the resetSequenceStates() after running the model, too.
I knew that the reset flags are recognized well in the swarming process.
But I don’t get the meaning of experiment runner framework. Could you provide relevant example codes or documents?

Thank you very much.

I just checked that moving the code for calling model.resetSequenceStates() to the place below model.run did not change the result.

No there should not be. You have to manually reset. This doesn’t make sense to me.

Can you tell me what version of nupic you are using?

My version is:
nupic==0.6.0 and nupic.bindings==0.6.0

Do you mind uninstalling and reinstalling nupic at the latest version?

pip install nupic==1.0.0 [--user]

I would like to try it if you suggest so.
I will be back after exploring the newest nupic.

Thank you!

Hi,
I just updated nupic to version 1.0.0.
(With the uninstalling -> installing procedure)

With the code attached above, it still shows the same result.

  1. Put reset flag in the beginning of each new sequence
  2. Manually call model.resetSequenceStates() function when encountered reset flag
  • Calling this function before/after running model.run() doesn’t change the result

0.6.0 -> 1.0.0 didn’t help.

Could someone provide some guide more please?

Thank you.