From ba4b61d9def21587c35e69a25a8d835169504d81 Mon Sep 17 00:00:00 2001 From: Marek Otahal Date: Thu, 4 Jul 2019 12:13:04 +0200 Subject: [PATCH] cleanup SP test --- .../unit/algorithms/SpatialPoolerTest.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/test/unit/algorithms/SpatialPoolerTest.cpp b/src/test/unit/algorithms/SpatialPoolerTest.cpp index 28fe20a133..ad720bd315 100644 --- a/src/test/unit/algorithms/SpatialPoolerTest.cpp +++ b/src/test/unit/algorithms/SpatialPoolerTest.cpp @@ -238,7 +238,10 @@ void setup(SpatialPooler &sp, UInt numInputs, UInt numColumns) { TEST(SpatialPoolerTest, testUpdateInhibitionRadius) { SpatialPooler sp; vector 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); @@ -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); @@ -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 @@ -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 @@ -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) {