Skip to content

Commit

Permalink
cleanup SP test
Browse files Browse the repository at this point in the history
  • Loading branch information
breznak committed Jul 4, 2019
1 parent 7ab155b commit ba4b61d
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/test/unit/algorithms/SpatialPoolerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ void setup(SpatialPooler &sp, UInt numInputs, UInt numColumns) {
TEST(SpatialPoolerTest, testUpdateInhibitionRadius) {
SpatialPooler sp;
vector<UInt> colDim, inputDim;
colDim.push_back(57);

//test for global inhibition, this is trivial
{
colDim.push_back(57); //max SP dimension
colDim.push_back(31);
colDim.push_back(2);
inputDim.push_back(1);
Expand All @@ -247,14 +250,18 @@ TEST(SpatialPoolerTest, testUpdateInhibitionRadius) {

sp.initialize(inputDim, colDim);
sp.setGlobalInhibition(true);
ASSERT_TRUE(sp.getInhibitionRadius() == 57);
ASSERT_TRUE(sp.getInhibitionRadius() == 57) << "In global inh radius must match max dimension";
}

//tests for local inhibition
UInt numInputs = 3;
UInt numCols = 12;
{
colDim.clear();
inputDim.clear();
// avgColumnsPerInput = 4
// avgConnectedSpanForColumn = 3
UInt numInputs = 3;
inputDim.push_back(numInputs);
UInt numCols = 12;
colDim.push_back(numCols);
sp.initialize(inputDim, colDim);
sp.setGlobalInhibition(false);
Expand All @@ -264,11 +271,12 @@ TEST(SpatialPoolerTest, testUpdateInhibitionRadius) {
Real permArr[] = {1, 1, 1};
sp.setPermanence(i, permArr);
}
UInt trueInhibitionRadius = 6;
// ((3 * 4) - 1)/2 => round up
sp.updateInhibitionRadius_();
ASSERT_TRUE(trueInhibitionRadius == sp.getInhibitionRadius());
ASSERT_EQ(6u, sp.getInhibitionRadius());
}

{
colDim.clear();
inputDim.clear();
// avgColumnsPerInput = 1.2
Expand All @@ -288,10 +296,11 @@ TEST(SpatialPoolerTest, testUpdateInhibitionRadius) {
}
sp.setPermanence(i, permArr);
}
trueInhibitionRadius = 1;
sp.updateInhibitionRadius_();
ASSERT_TRUE(trueInhibitionRadius == sp.getInhibitionRadius());
ASSERT_EQ(1u, sp.getInhibitionRadius());
}

{
colDim.clear();
inputDim.clear();
// avgColumnsPerInput = 2.4
Expand All @@ -308,10 +317,10 @@ TEST(SpatialPoolerTest, testUpdateInhibitionRadius) {
Real permArr[] = {1, 1, 0, 0, 0};
sp.setPermanence(i, permArr);
}
trueInhibitionRadius = 2;
// ((2.4 * 2) - 1)/2 => round up
sp.updateInhibitionRadius_();
ASSERT_TRUE(trueInhibitionRadius == sp.getInhibitionRadius());
ASSERT_EQ(2u, sp.getInhibitionRadius());
}
}

TEST(SpatialPoolerTest, testUpdateMinDutyCycles) {
Expand Down

0 comments on commit ba4b61d

Please # to comment.