Spatial Pooler Implementation for MNIST Dataset

Hello @dmac
I am trying to run the spatial pooler with different boosting (exp boosting, log boosting, and non boosting). For this reason, according to what you said, I went to the following address and tried to run various boosting functions with the following commands.

github/htm.core/src/htm/algorithms/SpatialPooler.cpp

‘if(boost < htm::Epsilon) return;’
output[i] = exp((targetDensity - actualDensity[i]) * boost);
‘output[i] = log(actualDensity[i]) / log(targetDensity);’

Unfortunately, with the change of codes, there is no change in the output.
Even I change the word boost to the boosting-Func in this line, no error occurs.
Another example is, I wrote the following command in this file, but no message was printed in the output.
'out << “------------CPP SpatialPooler Parameters ------------------\n”; ’

I was very confused. I do not understand why this is happening. Would you mind guiding me?

That is strange. It sounds like there is a problem with how you are compiling and running the C++ code.

Are you using the right mode: “debug” vs “release”?
For example: I’ve had issues where I make a change to the code and recompile it, but I recompiled it for release mode and then tested the old stale debug mode build.

Thank you for your answer.Sorry I did not understand what you meant. I downloaded the code file and ran it in Python, but the changes to the SpatialPooler.cpp do not affect the result. What do you think I should do to run log-boosting and exp-boosting?

If you change the c++ code (any file that ends in “.cpp” or “.hpp”) then you need to compile the new source code to make a new library, which will include your changes.

There are build instructions at: https://github.com/htm-community/htm.core#building-from-source

I’m so sorry, but I’m not familiar with these files.I used the following commands to run the code:

python -m pip install -i https :// test.pypi.org /simple/  htm.core

pip install -i Simple index htm.core[examples]

python setup.py install --user --force

And then I ran the MNIST.py code. Would you please tell me exactly what I should do after making changes to the SpatialPooler.cpp?
thanks

hi dear @dmac
I have been trying for about a week to see the effect of exp boosting and log boosting on the spatial pooler output. To do this, after modifying the ‘SpatialPooler.cpp’ file, I ran the following commands:

Simple C ++ build

After cloning/downloading the repository, do the following:
`` `
cd path-to-repository

mkdir -p build / scripts

cd build / scripts

cmake …/ …

make -j8 install
`` `

And then, I ran the code ‘mnist.py’. But no change occurred, and not even the order
out << “------------ log_boosting ------------------ \ n”;

Also, what I wrote in the ‘SpatialPooler.cpp’ file was not printed.
Please tell me where the problem is and how can I change the boosting?
Is there a way to make these changes in Python code?

Edit: You should use David Keeney’s directions in the next post:

So you should delete the entire build folder and then run python setup.py install --user --force .

1 Like

Actually, python setup.py install includes the cmake and the make and it contains slightly different build parameters for the python library. You can confuse the cache if you build for C++ and then try to use that to construct the python library.

So you should delete the entire build folder and then run python setup.py install --user --force.

2 Likes

Many thanks for your response.I was finally able to see the sentences I wrote in the ‘spatial pooler.cpp’ file.

But the strange thing for me was that the output of the spatial pooler was exactly the same in all three modes of exp boosting, log boosting, and no boosting.All three algorithms showed the following output.
‘spatialpooler_output=[174,241,287,291,313,356,367,424,428,434,571,595,609,658,689]’

Is it correct? Do you think I made a mistake in running the code? (I expected the output bits of these three algorithms to be different for a particular input.)

Hello . Please help me and answer my questions

I gave the whole MNIST dataset to the spatial pooler algorithm and compared the following four modes for this data set:

1-learning=true and log2-boosting function

2-learning=true and exp-boosting function

3-learnind=true and none boosting

4-none learning

The classification accuracy for these four modes is as follows:89.61%, 89.4%, 86.91%, 85.72%.

1- My question is whether these experiments can conclude that the spatial pooler algorithm with log2-boosting is better than other methods?

2-I have not done these tests on another database yet. Is it always on any database log2-boosting better than other methods?
3-I want to compare the above four modes in terms of convergence speed. For which mode do you think the convergence is faster?
4- The problem I have with comparing convergences is that every time I change iteratinNum in the file spatialpooler.cpp I have to compile it first and then run it, which takes about 1 hour. So if I want to get the convergence speed in the log-boosting methods for iteratinNum = 0 to iteratinNum = 25, it takes about 26 hours, and comparing the convergence of 4 methods takes 26 x 4 hours. Am I right?
Is there a faster way to compare these four methods in terms of convergence speed?

thanks a lot

1 Like