Spatial Pooling Visualization

I have been following the videos from HTM School and specifically, those associated with spatial pooling. I am attempting to reconstruct some of the visualizations. The one that I would like to be able to reconstruct is the mapping from the columns to the encoded input data. I am using the python code. However, it appears that the data members and member functions reside at the lower level .cpp routines which are referenced through a SWIG interface. Granted, I am using an earlier version of nupic but it looks like this area has not changed that much between versions.

Is there a way to access the lower level variables and pointers to objects in the .cpp files but do it within the python code?

For instance, I am working in the python debugger (pdb) and am trying to view the calculateOverlap_ data member of the SpatialPooler.

1 Like

Check out the SP docs here. They should be pretty much the same with older versions of NuPIC.

You can see how I accessed all the SP internal state from HTM School visualizations here:

Just look for self._sp, which is the SP instance.

You can call getOverlaps on the SpatialPooler (even the swigged C++ implementation). This function is defined here:

And you can see some SWIG code to make sure it is wrapped properly for calling from Python here:

Also keep in mind that if you are using the Network API then you have to pull the SP algorithm class out of the region before calling this method.

Thanks, Scott and to everyone else who responded.
I guess my follow-question is more related to the version compatibility. I am running a old version (0.2.7 I believe) which does not have many of these functions that the later versions have.

Can I simply add the code above in the .i file to the existing $NUPIC/binding/algorithms.i and then make an addition to the python wrapper (algorithms_cxx.cpp)?

Probably not. We’ve made breaking changes recently. Why can’t you upgrade?

It looks like 0.2.7 (of nupic.core, not sure if you meant 2.7 of nupic or nupic.core but it should be close enough) has a function for calculating overlaps for a given input:

1 Like

I plan to do just that.

In the interim I was hoping to see if there was something that I could do which was expedient using my existing setup rather than taking the time to upgrade.

But my intentions are to upgrade.

1 Like