From 46e4ca5be3c3bc7f0b3bcf836b78d4119a3dd71f Mon Sep 17 00:00:00 2001 From: Marek Otahal Date: Wed, 3 Jun 2020 13:20:55 +0200 Subject: [PATCH] SP: enable segment pruning for Conn.adaptSegment by setting segmentThreshold param. This should be ON, but there are some issues with platform independent reproducible results --- src/examples/hello/HelloSPTP.cpp | 10 +++++----- src/htm/algorithms/SpatialPooler.cpp | 2 +- src/test/unit/algorithms/SpatialPoolerTest.cpp | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/examples/hello/HelloSPTP.cpp b/src/examples/hello/HelloSPTP.cpp index 018b60479a..dfaf80681a 100644 --- a/src/examples/hello/HelloSPTP.cpp +++ b/src/examples/hello/HelloSPTP.cpp @@ -201,24 +201,24 @@ EPOCHS = 2; // make test faster in Debug SDR goldSP({COLS}); const SDR_sparse_t deterministicSP{ - 62, 72, 73, 82, 85, 102, 263, 277, 287, 303, 306, 308, 309, 322, 337, 339, 340, 352, 370, 493, 1094, 1095, 1114, 1115, 1120, 1463, 1512, 1518, 1647, 1651, 1691, 1694, 1729, 1745, 1746, 1760, 1770, 1774, 1775, 1781, 1797, 1798, 1803, 1804, 1805, 1812, 1827, 1828, 1831, 1832, 1858, 1859, 1860, 1861, 1862, 1875, 1878, 1880, 1881, 1898, 1918, 1923, 1929, 1931,1936, 1950, 1953, 1956, 1958, 1961, 1964, 1965, 1967, 1971, 1973, 1975, 1976, 1979, 1980, 1981, 1982, 1984, 1985, 1986, 1988, 1991, 1994, 1996, 1997, 1998, 1999, 2002, 2006, 2008, 2011, 2012, 2013, 2017, 2019, 2022, 2027, 2030 + 17, 62, 71, 72, 73, 78, 82, 83, 85, 93, 102, 131, 261, 263, 268, 269, 277, 282, 287, 301, 306, 308, 309, 317, 323, 331, 336, 337, 338, 339, 340, 352, 359, 366, 432, 443, 493, 502, 523, 811, 928, 955, 1089, 1095, 1114, 1115, 1120, 1133, 1134, 1428, 1508, 1512, 1651, 1677, 1745, 1760, 1774, 1804, 1805, 1858, 1861, 1925, 1927, 1929, 1936, 1937, 1940, 1950, 1951, 1953, 1956, 1961, 1967, 1969, 1971, 1975, 1978, 1979, 1980, 1981, 1982, 1984, 1985, 1987, 1988, 1990, 1994, 1996, 1997, 1998, 1999, 2000, 2002, 2006, 2008, 2011, 2012, 2013, 2016, 2022, 2027, 2034 }; goldSP.setSparse(deterministicSP); SDR goldSPlocal({COLS}); const SDR_sparse_t deterministicSPlocal{ - 12, 13, 71, 72, 75, 78, 82, 85, 131, 171, 182, 186, 189, 194, 201, 263, 277, 287, 308, 319, 323, 337, 339, 365, 407, 429, 432, 434, 443, 445, 493, 494, 502, 508, 523, 542, 554, 559, 585, 586, 610, 611, 612, 644, 645, 647, 691, 698, 699, 701, 702, 707, 777, 809, 810, 811, 833, 839, 841, 920, 923, 928, 929, 935, 955, 1003, 1005, 1073, 1076, 1094, 1095, 1114, 1115, 1133, 1134, 1184, 1203, 1232, 1233, 1244, 1253, 1268, 1278, 1291, 1294, 1306, 1309, 1331, 1402, 1410, 1427, 1434, 1442, 1463, 1508, 1512, 1514, 1515, 1518, 1561, 1564, 1623, 1626, 1630, 1640, 1647, 1691, 1694, 1729, 1745, 1746, 1760, 1797, 1804, 1805, 1812, 1827, 1831, 1858, 1861, 1862, 1918, 1956, 1961, 1965, 1971, 1975, 1994, 2012 + 13, 62, 71, 72, 73, 78, 80, 134, 140, 167, 169, 179, 189, 194, 261, 263, 268, 269, 308, 323, 328, 337, 339, 365, 407, 423, 425, 432, 434, 443, 493, 494, 508, 512, 514, 520, 585,598, 601, 610, 630, 644, 645, 673, 675, 691, 701, 707, 748, 749, 777, 809, 811, 833, 838, 841, 853, 889, 906, 921, 926, 928, 952, 958, 967, 989, 1005, 1076, 1089, 1095, 1114, 1115, 1120, 1133, 1146, 1181, 1184, 1196, 1203, 1217, 1249, 1252, 1253, 1263, 1282, 1291, 1306, 1309, 1331, 1337, 1401, 1402, 1410, 1434, 1462, 1469, 1487, 1494, 1508, 1512, 1518, 1547, 1563, 1564, 1623, 1624, 1626, 1651, 1672, 1677, 1693, 1694, 1745, 1746, 1750, 1760, 1768, 1802, 1805, 1831, 1858, 1861, 1869, 1880, 1889, 1929, 1950, 1956, 1961, 1994, 2002, 2011, 2012, 2027 }; goldSPlocal.setSparse(deterministicSPlocal); SDR goldTM({COLS}); const SDR_sparse_t deterministicTM{ - 87, 93, 102, 282, 303, 308, 337, 340, 502, 542, 952, 1115, 1502, 1518, 1626, 1691, 1694, 1711, 1727, 1760, 1775, 1781, 1804, 1805, 1827, 1831, 1832, 1844, 1851, 1858, 1859, 1918, 1929, 1931, 1941, 1943, 1945, 1952, 1953, 1955, 1956, 1958, 1960, 1961, 1965, 1973, 1975, 1976, 1979, 1980, 1984, 1985, 1986, 1987, 1994, 1996, 1998, 2002, 2006, 2013, 2042 + 82, 83, 85, 102, 131, 147, 268, 269, 282, 286, 301, 323, 337, 339, 340, 352, 493, 502, 523, 645, 754, 811, 833, 1214, 1263, 1544, 1627, 1738, 1808, 1854, 1858, 1867, 1925, 1927, 1931, 1933, 1943, 1947, 1953, 1955, 1956, 1958, 1959, 1961, 1964, 1965, 1966, 1967, 1969, 1970, 1971, 1975, 1976, 1978, 1980, 1981, 1984, 1987, 1990, 1997, 1998, 2008, 2011, 2013, 2025, 2027, 2034, 2040, 2042, 2044 }; goldTM.setSparse(deterministicTM); - const float goldAn = 0.715686f; //Note: this value is for a (randomly picked) datapoint, it does not have to improve (decrease) with better algorithms - const float goldAnAvg = 0.412719f; // ...the averaged value, on the other hand, should improve/decrease. + const float goldAn = 0.558824f; //Note: this value is for a (randomly picked) datapoint, it does not have to improve (decrease) with better algorithms + const float goldAnAvg = 0.389571f; // ...the averaged value, on the other hand, should improve/decrease. #ifdef _ARCH_DETERMINISTIC if(e+1 == 5000) { diff --git a/src/htm/algorithms/SpatialPooler.cpp b/src/htm/algorithms/SpatialPooler.cpp index acd93b7eae..9398cdbc68 100644 --- a/src/htm/algorithms/SpatialPooler.cpp +++ b/src/htm/algorithms/SpatialPooler.cpp @@ -710,7 +710,7 @@ Real SpatialPooler::avgConnectedSpanForColumnND_(const UInt column) const { void SpatialPooler::adaptSynapses_(const SDR &input, const SDR &active) { for(const auto &column : active.getSparse()) { - connections_.adaptSegment(column, input, synPermActiveInc_, synPermInactiveDec_, true, 0); //! stimulusThreshold_); //FIXME segment pruning not platform-independent! + connections_.adaptSegment(column, input, synPermActiveInc_, synPermInactiveDec_, true, stimulusThreshold_); connections_.raisePermanencesToThreshold( column, stimulusThreshold_ ); } } diff --git a/src/test/unit/algorithms/SpatialPoolerTest.cpp b/src/test/unit/algorithms/SpatialPoolerTest.cpp index 76b2cf0bbd..6b428106be 100644 --- a/src/test/unit/algorithms/SpatialPoolerTest.cpp +++ b/src/test/unit/algorithms/SpatialPoolerTest.cpp @@ -2056,7 +2056,7 @@ TEST(SpatialPoolerTest, ExactOutput) { // Silver is an SDR that is loaded by direct initalization from a vector. SDR silver_sdr({ 200 }); SDR_sparse_t data = { - 4, 64, 74, 78, 85, 113, 125, 126, 127, 153 + 11, 17, 31, 63, 78, 125, 126, 153, 173, 193 }; silver_sdr.setSparse(data); @@ -2064,7 +2064,7 @@ TEST(SpatialPoolerTest, ExactOutput) { // Gold tests initalizing an SDR from a manually created string in JSON format. // hint: you can generate this string using // silver_sdr.save(std::cout, JSON); - string gold = "{\"dimensions\": [200],\"sparse\": [4, 64, 74, 78, 85, 113, 125, 126, 127, 153]}"; + string gold = "{\"dimensions\": [200],\"sparse\": [11, 17, 31, 63, 78, 125, 126, 153, 173, 193]}"; std::stringstream gold_stream( gold ); SDR gold_sdr; gold_sdr.load( gold_stream, JSON );