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

Commit

Permalink
NUP-2491: Validate global inhibition parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lscheinkman committed Feb 8, 2018
1 parent 4a9c8a2 commit dabd7f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nupic/algorithms/SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,9 @@ void SpatialPooler::inhibitColumnsGlobal_(
{
activeColumns.clear();
const UInt numDesired = (UInt) (density * numColumns_);
NTA_CHECK(numDesired > 0)
<< "Not enough columns (" << numColumns_ << ") "
<< "for desired density (" << density << ").";
vector<pair<UInt, Real> > winners;
for (UInt i = 0; i < numColumns_; i++)
{
Expand Down
12 changes: 12 additions & 0 deletions src/test/unit/algorithms/SpatialPoolerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,18 @@ namespace {
ASSERT_TRUE(check_vector_eq(trueActive,active));
}

TEST(SpatialPoolerTest, testValidateGlobalInhibitionParameters) {
// With 10 columns the minimum sparsity for global inhibition is 10%
// Setting sparsity to 2% should throw an exception
SpatialPooler sp;
setup(sp, 10, 10);
sp.setGlobalInhibition(true);
sp.setLocalAreaDensity(0.02);
vector<UInt> input(sp.getNumInputs(), 1);
vector<UInt> out1(sp.getNumColumns(), 0);
EXPECT_THROW(sp.compute(input.data(), false, out1.data()), nupic::LoggingException);
}

TEST(SpatialPoolerTest, testInhibitColumnsLocal)
{
// wrapAround = false
Expand Down

0 comments on commit dabd7f8

Please sign in to comment.