Basic / Specific Questions about coding HTM

I’m currently trying to code my own version of an HTM in c++, as i have different goals and ideas than the community one, plus I like to understand the whole process intricately. I’m going to post my stupid/very specific questions to here rather than make each one its own topic as I go along.

Question 1: for the pseudoCode in the book, There’s this function (segmentsForColumn(column, segments) : Given a set of segments, return the segments that are on a cell in this column.) - When this says “on a cell”, like the segment is coming FROM this column (and spreading its synapses elsewhere), or a SYNAPSE of another dendrite is touching a cell IN this column?

Question 2: for the pseudoCode numActivePotentialSynapses: A “potential synapse” is a synapse with any permanence - Does this include permanence of 0? I’m wondering how the number of PotentialSynapses would decrease

1 Like

Hi @Jossos, not stupid at all, I just got through the same process myself.


Correct, that count would include permenance of 0.

In this beginner version of your Temporal Memory, I don’t think the number of PotentialSynapses will ever decrease. Pruning out older unused connections is a more advanced feature, you may have to look into the NuPIC source for that.


1 Like

tyvm for the answer! that helps a lot.

Question 3: I’m wondering how some of the numbers are decided, and what some of the numbers are. like, why 2048 minicolumns? im not sure how many minicolumns are in an actual cortical column, but i think i read it was about 10x10? and each column had about 100 neurons? I’m guessing that 2048 minicolumns is meant to simulation a large amount of actual columns, since columns tend to be very interconnected?

Question 4: What are good values for the number of Distal Segments per cell? just 1? 100? what would effectively happen if i increased/decreased this number, and why would I want it higher/lower? Also how many synapses do/should segments have each? and how many synapses should I want to have as active threshold to activate a segment? I think i read in the book that it may be good to have 1 distal segment, with 80 synapses, and a threshold of 15 to activate to give it about 4 possible different uses for that neuron. why not have 4 distal segments with 20 synapses each?

Question 5: What’s the deal with layers? is the idea to have a 2048 minicolumn layer of like 4 neurons each, and then have like 4 of these? since each “layer” would output an sdr, would that just get fed in as the proximal/input to the next layer? I thought a 10x10x100 cortical column had the 4 layers in that single column?

1 Like

In actual cortex the number of mini-columns is vastly greater. The reach of an individual mini-column is about 8 mini-columns, for a diameter of about 15 mini-columns. This works out to a neighborhood of about 220 mini-columns in the cortex.

Each mini-column has something like 100 to 150 cells working together, distributed between layers L2/3, L4, L5, & L6. Each cell has something like 6 dendrites, each festooned with synapses.

Each dendrite is the part that forms the SDR, with the possibility that a single dendrite can form more than one SDR memory.

The HTM model is a simplification that allows the computational power of the cortex to be modeled by the hardware available to the average experimenter. The usual features are:

  • The number of cell bodies is reduced to 16 in most HTM simulations. This is assumed to model one layer, the best fit to the biology being L4.
  • The reach of the HTM dendrite is assumed to reach all cell bodies although there is an option called “topology” that is somewhat more realistic.
  • The number of possible synapse connections is all mini-columns but with sparse connections, the actual number of connections is usually somewhere around 40.
  • The macro-columns formed are a rough approximation of the topography of cortex but they capture the essential voting nature of cortical columns.

“In actual cortex the number of mini-columns is vastly greater.” - I googled this, and wikipedia says " There are about 100,000,000 cortical minicolumns in the neo-cortex with up to 110 neurons each, giving 1,000,000–2,000,000 cortical columns."

which with simple math gives you 100 mini columns per cortical column. am i reading this wrong? or are cortical columns not really separate entities?

also with distal segments, i thought these were supposed to stretch throughout the entire brain, but you’re saying they only have a connection radius of about 8 minicolumns?

Also Im a bit confused how you would create a program with multiple cortical columns to form a hierarchy. I was thinking 2 cortical columns active cells create 2 sdr’s for the input/proximal connections of a “higher up” cortical column, or does this hierarchy have a different way of working? i imagine you could manually create a hierarchy of cortical columns, with the lower “layer” being the input cortical columns, and then creating a vector of bits of the entire layer maybe (or squash them all into an sdr with the spatial pooler?), and using this as input for columns higher in the hierarchy?

1 Like

I have a post with the particulars of mini-column and dendrite geometry here:

Some of the confusion is that since HTM models such a small part of the cortex it was easier to just connect to to the entire array with every dendrite. Real cortex has the limits I described above.

The brain is divided into a collection of small regions about the size of a postage stamp. Current thinking is that there are about 100 of these regions.

Hierarchy comes from the interconnections between these regions.
This post goes into much more detail on this topic:

Estimates vary between 100 and 150 cells per column. There is the further complication that the cells are distributed between layers 2/3, 4, 5, and 6. Layers 2/3 & 4 are thought to form the feed-forward direction of processing and layers 5 & 6 are thought to form the feedback pathway.

You can see the actual mini-columns with a microscope. To the best of my knowledge nobody has been able to demonstrate actual macro-columns although the way that lateral connections work are very suggestive and there are important theoretical reasons why they should exist.

I have my own theory that I have been boring everyone here with for a long time - that the local macro-grouping is a hexagonal grid structure. I have a post that outlines why I think this makes sense:

1 Like

My understanding is that these variables relate to the “ability to detect coincidence”.

A cell with a single segment can only detect a single coincidence amongst it’s synapses (like the Spatial Pooler). Add more segments, and a cell can respond to several different coincidences. In our case, this means opening additional temporal contexts for our input sequences, and making sure cells aren’t being wasted with empty capacity.

Increasing the # of synapses on a segment is like widening the field of view on a single coincidence detector. Having few synapses is like a coincidence spotlight, while having many synapses is more like a coincidence floodlight.

As usual, the ideal numbers will differ depending on your data, and what you’re trying to do. I’m not sure on NuPIC’s settings yet, but that’s the best place to start. Biologically, I recall each cell having between 12 and 24 segments, and each segment having hundreds of synapses.

Yeah, I think you’ve got the basics. One Region could be 2048 minicolumns wide, and 4 neurons tall. And then, you could stack several of those Regions into a Hierarchical network, the output of one being the input to the next.

I’ve lost you on that last line about “10x10x100”, though, sorry.


I’ve got a question reading the book. This part of the psuedo code doesnt make sense to me

“function burstColumn(column)”

if there’s no “matching” segment, it grows a new one? this seems like it could get out of hand. there’s no psuedocode for growNewSegment, so idk if it’s just appending or replacing old ones

1 Like

There is a TM parameter called maxSegmentsPerCell you can find in the model params example in the quick start.

It will grow a new segment if there is no matching, yes. I believe the relevant piece of code is here ( :

    mark all cells as active
    if there are any matching distal dendrite segments
      find the most active matching segment
      mark its cell as a winner cell
        grow and reinforce synapses to previous winner cells
      find the cell with the least segments, mark it as a winner cell
        (optimization) if there are prev winner cells
          add a segment to this winner cell
          grow synapses to previous winner cells
if columnMatchingSegments is not None:
  numActive = lambda s: numActivePotentialSynapsesForSegment[s.flatIdx]
  bestMatchingSegment = max(columnMatchingSegments, key=numActive)
  winnerCell = bestMatchingSegment.cell

  if learn:
    cls._adaptSegment(connections, bestMatchingSegment, prevActiveCells,
                      permanenceIncrement, permanenceDecrement)

    nGrowDesired = maxNewSynapseCount - numActive(bestMatchingSegment)

    if nGrowDesired > 0:
      cls._growSynapses(connections, random, bestMatchingSegment,
                        nGrowDesired, prevWinnerCells, initialPermanence,
  winnerCell = cls._leastUsedCell(random, cellsForColumn, connections)
  if learn:
    nGrowExact = min(maxNewSynapseCount, len(prevWinnerCells))
    if nGrowExact > 0:
      segment = cls._createSegment(connections,
                                   lastUsedIterationForSegment, winnerCell,
                                   iteration, maxSegmentsPerCell)
      cls._growSynapses(connections, random, segment, nGrowExact,
                        prevWinnerCells, initialPermanence,

There is no ‘growNewSegment’ function, though there are ‘_createSegment’ and ‘_growSynapses’.