My own implementation of Temporal Memory

I am implementing a simpler model of Temporal Memory as a protocol, for testing. I am hoping for some feedback.


  • I have not implemented Spatial Pooler. Just temporal memory where each column is assigned (by me) to represent a particular item.
  • It has only 5-6 columns and 20 cells per column.
  • No segments.
  • Threshold is 1, for distal connections. So only one connecting cell needs to be on to put the next cell in predictive state.

Otherwise, there is permanence and weights. A weight is connected if the permanence goes beyond a threshold.

Question 1: Would this work? Do you see a fundamental problem with this simple system?

There is a decision to be made: when the presynaptic neuron fires, and there is no predictive cell, all neurons in the postsynaptic column fire. How to choose the postsynaptic neuron to be potentiated? When there is a segment, the cell with the most active segment is chosen.

I have implemented this as follows:

  1. Choose the cell with the highest weight between pre- and post- synaptic neuron.
  2. If the connection is already established (permanence is above threshold) between pre- and post- cell, then strengthen the permanence further. Else,
  3. If the cell (pre- or post- synaptic) is used in some other connection (weights are already connected), then remove it, and go to the step 1.
  4. If cell is not used, then strengthen connection between pre- and post- cells.

Step 2 is introduced so that one cell is not shared between sequences as far as possible. I can also make this second rule more fuzzy - in step 2, the threshold used is lower than that for connection. For example, if permanence is above x, connection is established. If permanence is 0.9x, then connections are strengthened further, step 3 is not executed.

Question 2: Do you think this follows the principles of original HTM? Any comments?


Disclaimer: I’m probably the least knowledgeable person on HTM theory on this entire message board. In fact, I only began trying to learn it a few days ago. So part of why I’m responding is because I’m not sure myself and I want to know.

That said, I don’t quite understand what you mean by:

Just temporal memory where each column is assigned (by me) to represent a particular item.

In my understanding, I don’t think it makes sense to analogize the HTM sequence memory circuit to a traditional feed-forward neural network with an input layer, hidden layers, and an output layer. It’s tempting to see the column activations as the output layer, but I think they are conceptually something totally different.

But if my understanding is correct, it does raise another question: How would you train an HTM sequence memory circuit to recognize and label sequences?

In some of the HTM School examples, it looked like they were matching pre-defined SDRs to recognize certain system states, so that might be one way.

My intuition says that you could encode the label you want the system to learn as part of the input field, and then wait for it to learn to predict that part of the input. The trouble with that would be that it would quickly learn to rely on that input when identifying parts of the sequence, and also it might learn to stop predicting it when you took it away. There might be a different type of “one-way” connection where a column can flag that its state should never be used as an input to another column’s connections, in order to permit something along these lines. I’m just guessing…

Perhaps I’ve misunderstood what you meant.

Regarding one of your other comments:

How to choose the postsynaptic neuron to be potentiated?

@Rhyolight ’s “HTM School” Episode 12 talks about how to choose the “winner neuron” cell when a column is activated. Temporal Memory Part 2 (Episode 12) - YouTube The explanation starts around the 4:00 mark.

Also, what implementation framework are you using? Are you building on top of NuPIC Core, or just experimenting in your own code from scratch?

Like I said, I’m nowhere near an authority. In fact, I am likely totally wrong so please take what I’m saying with lots of salt. Hopefully a real expert will chime in.

1 Like


I would recommend having many more columns. Try multiplying those numbers by 10 or 20, or at very least write your code in such a way that later you can easily increase the number of columns.

As you’ve mentioned, you need a threshold of 1 BC each item is only represented by 1 column. This is not very robust to any kind of error; a single spurious synapse will cause a problem.

Instead if you had 20 active columns and a threshold of 10, then it would be much more robust in the face of cells which either failed to activate or activated in the wrong context.

No segments

You should be able to demonstrate a basic “sequence memory” without needing segments. However no segments will greatly reduce its capacity to remember things.

Good luck, and happy coding.

1 Like

Thanks. I have a few questions on a particular topic, corresponding to the original HTM implementation:

When there is no predictive cell that is active, then all the cells of the column burst. How to choose the winner cell?

As @LukeTPeterson mentioned, the video shows some info, but I am hoping for more clarity. So here are my questions:

Let us suppose (only for the sake of example and discussion of current topic) there are 10 columns with 10 cells each, so 90 total cells in the system.

  1. Each cell contains several segments. So each segment would be a binary vector of 100 dimensions, 1 denoting an active synapse, and 0 denoting an inactive one, correct?
  2. If no segment is active, I pick the segment with the highest number of active synapses, and the cell corresponding to that segment as the winner cell - is that correct? So suppose column 2 burst, in absence of any predictive neuron. Suppose, col.2 cell 5 contains 6 segments, and segment 1 has 13 active synapses, which is the highest, across all cells in col. 2. Then I pick segment 1, and the corresponding cell 5 in column 2 as the winner cell.
  3. Do I increase the permanence of cell 5 (the winner cell) or should I increase the permanence of all the bursting cells?


Sequence memory is used to predict the next item in the sequence, or detect anomalies. It can’t recognize entire sequences, just the current sequence-so-far. There was work on recognizing whole sequences a while back, but it had capacity problems I think. It’s a hard problem. It requires the same representation for each item in the sequence and listing multiple possible sequences. Sequences can branch.