Trying to implement the Spatial Pooler algorithm without Nupic

Hey guys. I start with the HTM theory a few time ago and I’m trying to implement the Spatial Pooling algorithm without use the Nupic library, to understand better how it works, but I’m facing difficulties. Someone have a idea of some place where I can search some inspiration?

There is a good chapter on SP here: