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

Fix SP initialize vs constructor differences #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

breznak
Copy link
Member

@breznak breznak commented Jan 19, 2018

SP behaves differently when constructor vs setters are used to set the
same parameters!

different behavior for constructor vs setters
    fix for different

SP behaves differently when constructor vs setters are used to set the
same parameters!
this sets the num active columns,
but also has to disable mutex localAreaDensity,
according to the API it's done by = -1;
but the setter wrongly used =0;
fixed
this fixes the issue with different SP states when constructor/setter is used.
Copy link
Member Author

@breznak breznak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR with SP constructor fix + tests.
1 additional question to resolve, please see below.

@@ -186,7 +186,7 @@ UInt SpatialPooler::getPotentialRadius() const

void SpatialPooler::setPotentialRadius(UInt potentialRadius)
{
potentialRadius_ = potentialRadius;
potentialRadius_ = std::min(potentialRadius, numInputs_); //crop to numInputs (input size)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this caused the difference, because constructor does implicitly crop to bounds, while setter didn't.
TODO: do implicitly, or throw NTA_ASSERT?

@@ -196,6 +196,7 @@ Real SpatialPooler::getPotentialPct() const

void SpatialPooler::setPotentialPct(Real potentialPct)
{
NTA_ASSERT(potentialPct > 0 && potentialPct <= 1); //bounds check
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turn assert to always check?
We should check the public API and if it's public, always check. Other hand, performance impact.

@@ -219,7 +220,7 @@ void SpatialPooler::setNumActiveColumnsPerInhArea(
{
NTA_ASSERT(numActiveColumnsPerInhArea > 0);
numActiveColumnsPerInhArea_ = numActiveColumnsPerInhArea;
localAreaDensity_ = 0;
localAreaDensity_ = -1; //disabling
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes the incompatibility with API documentation

@breznak breznak added ready bug Something isn't working SP labels Jan 19, 2018
@breznak breznak added this to the Community fixes milestone Jan 23, 2018
@breznak breznak self-assigned this Jan 23, 2018
@breznak breznak closed this Jan 25, 2018
@breznak breznak reopened this Jan 25, 2018
@breznak breznak removed this from the Community fixes milestone Aug 1, 2018
@breznak breznak added code code enhancement, optimization, cleanup..programmer stuff and removed feature new feature, extending API labels Aug 9, 2018
@breznak breznak requested a review from dkeeney August 30, 2018 09:00
@breznak
Copy link
Member Author

breznak commented Aug 30, 2018

@dkeeney please have a look, small PR, fixes a discrepancy in the API. Pls give your thoughts on the question: crop vs assert.

@breznak
Copy link
Member Author

breznak commented Aug 30, 2018

Test configs need to be updated!
https://travis-ci.org/htm-community/nupic.cpp/builds/422453282#L6740

dkeeney
dkeeney previously approved these changes Sep 3, 2018
@breznak breznak closed this Nov 7, 2018
@breznak breznak reopened this Nov 7, 2018
@breznak breznak removed the ready label Nov 7, 2018
breznak pushed a commit that referenced this pull request Dec 17, 2018
Connections fix bindings py change
@breznak breznak mentioned this pull request Feb 26, 2019
@Zbysekz Zbysekz closed this Jun 26, 2020
@Zbysekz Zbysekz deleted the fix_sp_initialize_vs_constructor branch June 26, 2020 06:58
@breznak breznak restored the fix_sp_initialize_vs_constructor branch June 26, 2020 07:13
@breznak breznak reopened this Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working code code enhancement, optimization, cleanup..programmer stuff SP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SpatialPooler initialization with constructor vs initialize() results in different SP state
3 participants