Skip to content

Commit

Permalink
SP: enable segment pruning for Conn.adaptSegment
Browse files Browse the repository at this point in the history
by setting segmentThreshold param. This should be ON, but there
are some issues with platform independent reproducible results
  • Loading branch information
breznak committed Jun 3, 2020
1 parent b91144d commit 46e4ca5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/examples/hello/HelloSPTP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/htm/algorithms/SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/algorithms/SpatialPoolerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,15 +2056,15 @@ 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);


// 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 );
Expand Down

0 comments on commit 46e4ca5

Please sign in to comment.