Nupic-master vs htm-core

Are the two algorithms ‘nupic-master’ and ‘htm-core’ different in terms of implementation and performance? Which of them works better?
I have a few questions about these two algorithms. I was very confused and the results I get from the run of these codes contradicts what I have read before.Please help me understand the answers to these questions:
1)I give a specific input to the Spatial pooler algorithm from nupic-master and during several runs the output of the algorithm is always the same( the SDR is fixed).But when I give a specific input to the Spatial pooler algorithm from htm-core and run the algorithm several times the SDR output is different each time. What is the problem?

2)In htm-core I defined the parameters as follows:
default_parameters = {
'numActiveColumnsPerInhArea ’ :15.0,
‘potentialRadius’: 16,
‘boostStrength’: 0.0,
‘columnDimensions’: (28, 28),
‘dutyCyclePeriod’: 1000,
‘localAreaDensity’: 0.1,
‘minPctOverlapDutyCycle’: 0.2,
‘potentialPct’: 0.1,
‘stimulusThreshold’: 10,
‘synPermActiveInc’: 0.01,
‘synPermConnected’: 0.5,
‘synPermInactiveDec’: 0.008
But the SDR_output has 41 bits (instead of 15 bits) As shown below. Why? How do I set it up?

sp_out.nonzero() (array([ 76, 100, 123, 127, 146, 160, 216, 230, 267, 280, 294, 304,
310,325, 329, 343, 347, 350, 351, 352, 373, 381, 382, 401, 414,
416,428, 456, 497, 552, 554, 570, 576, 592, 593, 619, 652, 692,
695, 728, 748]),)

3)In the ‘nupic-master’ algorithm in both cases “sp.compute(inputArray,True, activeArray)” and “sp.compute(inputArray,False, activeArray)” the output of a particular input is the same and as follows. Shouldn’t the outputs of these two modes be different from each other?

(‘inputArray.nonzero()’, (array([157, 184, 185, 186, 212, 213, 214, 239, 240, 241, 267, 268, 269,
294, 295, 296, 297, 322, 323, 324, 350, 351, 352, 378, 379, 380,
405, 406, 407, 433, 434, 435, 461, 462, 463, 488, 489, 490, 516,
517, 518, 544, 545, 546, 572, 573, 599, 600, 601, 627, 628, 629,
655, 656, 657, 684]),))

(‘activeArray.nonzero()’, (array([ 12, 13, 71, 99, 149, 159, 176, 219, 270, 335, 504, 525, 653, 677, 713]),))

1 Like

I would recommend using htm-core.
Full disclosure, I wrote parts of htm-core.

Did you remember to set the random seed? If the random seed is zero (the default case) then it uses the current time as the random seed. All of the htm-core algorithms which use random numbers should also accept a keyword argument “seed”.

I think that your Spatial Pooler is configured to have multiple inhibition areas.
Try replacing the potentialRadius parameter with globalInhibition=True.
Also you should probably only specify one of numActiveColumnsPerInhArea and localAreaDensity since they do the same thing and one of them overrides the other.

I hope this helps

1 Like

Thanks for your good tips; it was solved. Now I have some new questions. Would you please guide me as always?
First, I set the parameters of the two codes ‘nupic-master’ and ‘htm.core’ in spatial pooler mode, the same and set the parameter ‘localAreaDensity=0.02’ and ‘numActiveColumnsPerInhArea=15’. Then I gave one of the MNIST dataset images as input to these two codes and noticed that when ‘globalInhibition=True’ , the output of Spatial pooler in both cases has 15 bits but is different (shown below)

Htm.core _output =[209,214,219,230,231,346,349,432,468,556,581,595,597,609,627]

Nupic-master _output =[12,13,71,99,149,159,176,219,270,335,504,525,653, 677, 713]

And when ‘globalInhibition=False’ , both the number of active bits and their locations are different.

I did the same for other images from the MNIST database, and the same thing happened again (shown below).

Htm.core _output = [158,174,241,287,291,313,356,367,428,434,571,609,658,689]

Nupic-master _output =[4,10,13,99,149,176,219,270,335,504,525,546,549,653,677]

  1. Why are the active bits in the two algorithms’ nupic-master’ and ‘htm.core’ different?

  2. Is it possible to distinguish which of these two algorithms is better and has a better answer?

  3. What is the reason for the difference in the number of active bits in the ‘globalInhibition=False’ mode?

  4. Are these ‘nupic-master’ and ‘htm.core’ different in algorithm logic, or is their implementation different?

  5. Algorithm’ htm. core’ with variable ‘globalInhibition=False’ always has less active bits. Does this indicate the superiority of the algorithm in sparsing data over other methods?

  6. How can these two algorithms be compared?

  7. I did the same tests for the mHTM algorithm related to the article “A Mathematical Formalization of Hierarchical Temporal Memory’s Spatial Pooler for use in Machine Learning”. The active output bits were different from the above two methods. Do you have information about this algorithm and why it differs?

Please ask these questions of the supervisors where you study or work.

Unfortunately, my supervisor is not very familiar with the HTM algorithm. If anyone knows the answers to my questions, please help me understand. The answers to these questions are probably very simple for those who wrote these codes. I would like to know more about this algorithm and why it happened. Thank you all

1 The Spatial Pooler algorithm starts with random synapses.
Both implementations use a random seed, so the indexes of the active bits won’t change every time you run it (unless you forget to set the seed or set it to a random number).
However, different implementations use different random number generators so the results will never be identical, even if you use the same random seed.

4 There might be some slight differences, but on the whole they should perform the same algorithm.

5 I can not speak about globalInhibition=False because I’m not very familiar with that part of the code.

6 There are two ways to compare the algorithms:

Speed: how fast does it run?
htm-core runs faster than nupic.

Quality of results: does it do what a spatial pooler is supposed to do?
Both implementations should be about equal on this point.
The properties which SP are supposed to have are described in this paper:


First thing I’d do is swap out MNIST for the old reliable Hotgym dataset, since it’s so well studied.

You’re using images right, a much less common data type for HTM, so the deviations could maybe stem from different image encoding processes.

I’d be curious if the deviations remain with Hotgym data.

1 Like

That was interesting. Until now, I thought the two algorithms were different. Is there an article on how these two algorithms work?

Thanks a lot, dear @dmac

One of my goals is to be able to compare the output of different spatial pooler algorithms and analyze the results.Based on the explanation you gave, I realized that the two algorithms Nupic-master and htm.core are the same. But I’m still looking for different results and finding the difference in the output of the algorithms that implement HTM.

I reviewed the article you introduced. It is referenced in this article "Mnatzaganian, J., Fokoué, E., and Kudithipudi, D. (2017). A mathematical formalization of hierarchical temporal memory’s spatial pooler "which is the mHTM code I wrote about before.

  1. Would you mind telling me the differences and similarities between this code and Nupic-master regarding the algorithm?

Another algorithm called Etaler has been written to implement HTM.

2)Do you expect the spatial pooler output of this code to look like a nupic-master or not?

3)Can you explain the differences and similarities between Etaler and Nupic Master?

4)Is there another algorithm that implements HTM, and its logic is different from Nupic-master so that I can check the difference between its output and Nupic-master?

Thanks for your suggestion

The htm .core code uses the Hotgym dataset, but I did not see the Hotgym dataset as input in the nupic -master algorithm. Do you have this code?

Yep, its well documented here:

thanks a lot @sheiser1

1 Like

As another developer of htm.core, all of the modules implement the same HTM algorithms and we started with the code from nupic.master. Some of the modules were ported from Python to C++, others we used the existing C++ code and re-implemented parts of it to improve the speed and replaced some of the third party dependencies for ones that are more robust or easier to use and maintain. We also replaced many of the flat arrays with the SDR object.

I would not expect htm.core to produce exactly the same bit patterns in the resulting SDR as Nupic, partly due to the randomization that @dmac mentioned and partly do to minor compromises we made to improve speed. There were also some minor differences in the parameters used and the actual bit patterns in the SDR’s is very sensitive to the parameters. However, the job they are performing should be exactly the same.

1 Like

Thanks for your good explanation @David_Keeney