-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TM, SP: fix possible underflow in seed. Default random (0) seed. #799
base: master
Are you sure you want to change the base?
Changes from 2 commits
e8217a9
7faf388
e159de9
a4a4283
d66c1e9
3995e40
26a5d0f
b0c2909
c029f61
a7420a5
e0fdb49
fa46037
bd84c41
ce72ea7
ea7b88d
be4c661
9dc9954
284dc2e
8b6c6a3
c1a1b3d
d034207
d5d4b69
bd6c275
3ce080e
6247c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,9 +173,9 @@ Argument boostStrength A number greater or equal than 0, used to | |
too much boosting may also lead to instability of SP outputs. | ||
|
||
|
||
Argument seed Seed for our random number generator. If seed is < 0 | ||
Argument seed Seed for our random number generator. If seed is 0 | ||
a randomly generated seed is used. The behavior of the spatial | ||
pooler is deterministic once the seed is set. | ||
pooler is deterministic once the seed is set > 0. | ||
|
||
Argument spVerbosity spVerbosity level: 0, 1, 2, or 3 | ||
|
||
|
@@ -197,7 +197,7 @@ Argument wrapAround boolean value that determines whether or not inputs | |
, py::arg("minPctOverlapDutyCycle") = 0.001 | ||
, py::arg("dutyCyclePeriod") = 1000 | ||
, py::arg("boostStrength") = 0.0 | ||
, py::arg("seed") = 1 | ||
, py::arg("seed") = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the defaults to "random" (0) in cpp, py, NetworkAPI |
||
, py::arg("spVerbosity") = 0 | ||
, py::arg("wrapAround") = true | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,7 @@ EPOCHS = 2; // make test faster in Debug | |
SpatialPooler spLocal(enc.dimensions, vector<UInt>{COLS}); // Spatial pooler with local inh | ||
spGlobal.setGlobalInhibition(true); | ||
spLocal.setGlobalInhibition(false); | ||
Random rnd(42); //uses fixed seed for deterministic output checks | ||
|
||
|
||
TemporalMemory tm(vector<UInt>{COLS}, CELLS); | ||
|
||
AnomalyLikelihood anLikelihood; | ||
|
@@ -94,6 +93,12 @@ EPOCHS = 2; // make test faster in Debug | |
Metrics statsSPglobal(outSPglobal, 1000); | ||
Metrics statsTM(outTM, 1000); | ||
|
||
//uses fixed seed for deterministic output checks: | ||
Random rnd(42); | ||
spGlobal.setSeed(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a strange thing is happening here, I set the |
||
spLocal.setSeed(1); | ||
tm.setSeed(42); | ||
|
||
/* | ||
* For example: fn = sin(x) -> periodic >= 2Pi ~ 6.3 && x+=0.01 -> 630 steps to 1st period -> window >= 630 | ||
*/ | ||
|
@@ -201,7 +206,7 @@ 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 | ||
66, 70, 72, 75, 76, 82, 83, 85, 99, 297, 300, 301, 303, 305, 306, 308, 309, 311, 316, 320, 321, 323, 324, 325, 327, 329, 330, 343, 345, 347, 363, 508, 1084, 1110, 1112, 1115, 1120, 1131, 1522, 1532, 1535, 1634, 1684, 1697, 1732, 1769, 1777, 1778, 1800, 1801, 1803, 1817, 1818, 1823, 1830, 1834, 1836, 1844, 1847, 1851, 1855, 1859, 1860, 1862, 1866, 1882, 1886, 1897,1906, 1918, 1921, 1922, 1931, 1936, 1954, 1961, 1964, 1965, 1966, 1967, 1968, 1970, 1971, 1972, 1973, 1975, 1977, 1978, 1980, 1981, 1987, 1989, 1990, 2001, 2006, 2007, 2009, 2015, 2016, 2018, 2020, 2042 | ||
}; | ||
goldSP.setSparse(deterministicSP); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1944,27 +1944,24 @@ TEST(SpatialPoolerTest, testSerialization_ar) { | |
|
||
SpatialPooler sp1; | ||
sp1.initialize(inputDims, colDims); | ||
sp1.setSeed(1); | ||
|
||
SDR input(inputDims); | ||
SDR output(colDims); | ||
|
||
//burn-in the SP | ||
for (UInt i = 0; i < 100; ++i) { | ||
input.randomize(0.05f, random); //5% random ON | ||
sp1.compute(input, true, output); | ||
} | ||
|
||
// Now we reuse the last input to test after serialization | ||
|
||
auto activeColumnsBefore = output.getSparse(); | ||
|
||
// Save initial trained model | ||
stringstream ss; | ||
ss.precision(std::numeric_limits<double>::digits10 + 1); | ||
ss.precision(std::numeric_limits<float>::digits10 + 1); | ||
sp1.save(ss); | ||
|
||
SpatialPooler sp2; | ||
|
||
htm::Timer testTimer; | ||
|
||
for (UInt i = 0; i < 6; ++i) { | ||
|
@@ -1975,26 +1972,26 @@ TEST(SpatialPoolerTest, testSerialization_ar) { | |
SDR outputBaseline(output); | ||
sp1.compute(input, true, outputBaseline); | ||
|
||
// C - Next do old version | ||
// C - Next, verify the same results come from the de/serialized version | ||
{ | ||
SpatialPooler spTemp; | ||
testTimer.start(); | ||
|
||
// Deserialize | ||
ss.seekg(0); | ||
spTemp.load(ss); | ||
EXPECT_NO_THROW(spTemp.load(ss)); | ||
|
||
// Feed new record through | ||
SDR outputC({numColumns}); | ||
spTemp.compute(input, true, outputC); | ||
|
||
// Serialize | ||
ss.clear(); | ||
spTemp.save(ss); | ||
EXPECT_NO_THROW(spTemp.save(ss)); | ||
|
||
testTimer.stop(); | ||
|
||
EXPECT_EQ(outputBaseline, outputC); | ||
EXPECT_EQ(outputBaseline, outputC); //FIXME this test randomly fails. (De/serialization of rng_ is correct?) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is another test that is inconsistent! Sometimes it passes, sometimes crashes on different outputs. I can't see why would that be, the test is relatively simple and seems correct. |
||
} | ||
} | ||
ss.clear(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected the doc strings