Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNIST baseline model: no SP, directly raw images to classifier, 90.5% #555

Merged
merged 3 commits into from Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/examples/mnist/MNIST_SP.cpp
Expand Up @@ -56,6 +56,9 @@ class MNIST {
* Score: 95.35% (465 / 10000 wrong) : 28x28x16 : 2 : 125 : : smaller boosting (2.0)
* -- this will be my working model, reasonable performance/speed ratio
*
* Baseline:
* Score: 90.52% (948 / 10000 wrong). : SP disabled : 1 : 0.489 : 01a6c90297 : baseline with only classifier on raw images, on SP
*
*/

private:
Expand All @@ -67,7 +70,7 @@ class MNIST {

public:
UInt verbosity = 1;
const UInt train_dataset_iterations = 2u; //epochs somewhat help, at linear time
const UInt train_dataset_iterations = 1u; //epochs somewhat help, at linear time


void setup() {
Expand Down Expand Up @@ -104,7 +107,13 @@ void setup() {
mnist::binarize_dataset(dataset);
}

void train() {

/**
* train the SP on the training set.
* @param skipSP bool (default false) if set, output directly the input to the classifier.
* This is used for a baseline benchmark (Classifier directly learns on input images)
*/
void train(const bool skipSP=false) {
// Train

if(verbosity)
Expand Down Expand Up @@ -133,8 +142,9 @@ void train() {

// Compute & Train
input.setDense( image );
sp.compute(input, true, columns);
clsr.learn( columns, {label} );
if(not skipSP)
sp.compute(input, true, columns);
clsr.learn( skipSP ? input : columns, {label} );
if( verbosity && (++i % 1000 == 0) ) cout << "." << flush;
}
if( verbosity ) cout << endl;
Expand All @@ -154,7 +164,7 @@ void train() {
dump.close();
}

void test() {
void test(const bool skipSP=false) {
// Test
Real score = 0;
UInt n_samples = 0;
Expand All @@ -167,9 +177,11 @@ void test() {

// Compute
input.setDense( image );
sp.compute(input, false, columns);
if(not skipSP)
sp.compute(input, false, columns);

// Check results
if( argmax( clsr.infer( columns ) ) == label)
if( argmax( clsr.infer( skipSP ? input : columns ) ) == label)
score += 1;
n_samples += 1;
if( verbosity && i % 1000 == 0 ) cout << "." << flush;
Expand All @@ -185,6 +197,11 @@ void test() {
int main(int argc, char **argv) {
MNIST m;
m.setup();
cout << "===========BASELINE: no SP====================" << endl;
m.train(true); //skip SP learning
m.test(true);
cout << "===========Spatial Pooler=====================" << endl;
m.setup();
m.train();
m.test();

Expand Down
2 changes: 1 addition & 1 deletion src/htm/algorithms/SpatialPooler.cpp
Expand Up @@ -425,7 +425,7 @@ void SpatialPooler::initialize(
spVerbosity_ = spVerbosity;
wrapAround_ = wrapAround;
updatePeriod_ = 50u;
initConnectedPct_ = 0.5f;
initConnectedPct_ = 0.5f; //FIXME make SP's param, and much lower 0.01 https://discourse.numenta.org/t/spatial-pooler-implementation-for-mnist-dataset/2317/25?u=breznak
iterationNum_ = 0u;
iterationLearnNum_ = 0u;

Expand Down