Last time I used spatial poolers with vision, I remember they took a while to initialize the random connections, so I thought this would be useful:
It generates 20 MB of uniform random connections in under 10 seconds, and 200MB in about 36 seconds.
I set it to 2x the given sparsity so I could have the number of connected synapses be about equal to the given sparsity, and I might handle the disconnected synapses by ‘drifting’ them, or changing their indexes to other nearby ones. I think I’d be less likely to crash my computer again like that.
Hopefully this helps someone. Also, if anyone can think of ways to improve this code, I’m all ears. (To test/run: clone, open project&file in PyCharm, right click >>> in init_random, and click run.)
Edit: changed 5MB to 20MB. I’m using int32s, not int8s.