Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

SP: add test for different constructor vs setter behavior #1387

Closed

Conversation

breznak
Copy link
Member

@breznak breznak commented Jan 12, 2018

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

  • different behavior for constructor vs setters
    • fix for different

Fixes #1386

SP behaves differently when constructor vs setters are used to set the
same parameters!
sp.setPotentialPct(0.5);
sp.setGlobalInhibition(false);
sp.setLocalAreaDensity(0.02); //2% active cols
sp.setNumActiveColumnsPerInhArea(0); //mutex with above ^^
Copy link
Member Author

Choose a reason for hiding this comment

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

I suspect an issue in these 2 values, which are mutually exclusive. the Num Active Cols per Inh Area should never be zero

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.

EDIT: fixed the difference

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.

Provided test and fixed the setters, now behaves correctly and all tests pass.

@@ -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?

@@ -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 incompatibility with API documentation

@breznak
Copy link
Member Author

breznak commented Jan 12, 2018

@rhyolight atomic and well tested PR, can we please review and merge asap? other PRs are blocked by this.

@breznak
Copy link
Member Author

breznak commented Jan 19, 2018

Closing for freeze of this repo, moved to htm-community#5

@breznak breznak closed this Jan 19, 2018
@breznak breznak deleted the fix_sp_initialize_vs_constructor branch January 19, 2018 11:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SpatialPooler initialization with constructor vs initialize() results in different SP state
1 participant