|
29 | 29 | #include "htm/types/Sdr.hpp"
|
30 | 30 | #include "htm/utils/Random.hpp"
|
31 | 31 | #include "htm/utils/MovingAverage.hpp"
|
| 32 | +#include "htm/utils/SdrMetrics.hpp" |
32 | 33 |
|
33 | 34 | namespace examples {
|
34 | 35 |
|
@@ -79,6 +80,13 @@ Real64 BenchmarkHotgym::run(UInt EPOCHS, bool useSPlocal, bool useSPglobal, bool
|
79 | 80 | SDR outTM(spGlobal.getColumnDimensions());
|
80 | 81 | Real an = 0.0f, anLikely = 0.0f; //for anomaly:
|
81 | 82 | MovingAverage avgAnom10(1000); //chose the window large enough so there's (some) periodicity in the patter, so TM can learn something
|
| 83 | + |
| 84 | + //metrics |
| 85 | + Metrics statsInput(input, 1000); |
| 86 | + Metrics statsSPlocal(outSPlocal, 1000); |
| 87 | + Metrics statsSPglobal(outSPglobal, 1000); |
| 88 | + Metrics statsTM(outTM, 1000); |
| 89 | + |
82 | 90 | /*
|
83 | 91 | * For example: fn = sin(x) -> periodic >= 2Pi ~ 6.3 && x+=0.01 -> 630 steps to 1st period -> window >= 630
|
84 | 92 | */
|
@@ -147,13 +155,26 @@ Real64 BenchmarkHotgym::run(UInt EPOCHS, bool useSPlocal, bool useSPglobal, bool
|
147 | 155 | if (e == EPOCHS - 1) {
|
148 | 156 | tAll.stop();
|
149 | 157 |
|
| 158 | + //print connections stats |
| 159 | + cout << "\nInput :\n" << statsInput |
| 160 | + << "\nSP(local) " << spLocal.connections |
| 161 | + << "\nSP(local) " << statsSPlocal |
| 162 | + << "\nSP(global) " << spGlobal.connections |
| 163 | + << "\nSP(global) " << statsSPglobal |
| 164 | + << "\nTM " << tm.connections |
| 165 | + << "\nTM " << statsTM |
| 166 | + << "\n"; |
| 167 | + |
| 168 | + // output values |
150 | 169 | cout << "Epoch = " << e << endl;
|
151 | 170 | cout << "Anomaly = " << an << endl;
|
152 | 171 | cout << "Anomaly (avg) = " << avgAnom10.getCurrentAvg() << endl;
|
153 | 172 | cout << "Anomaly (Likelihood) = " << anLikely << endl;
|
154 | 173 | cout << "SP (g)= " << outSP << endl;
|
155 | 174 | cout << "SP (l)= " << outSPlocal <<endl;
|
156 | 175 | cout << "TM= " << outTM << endl;
|
| 176 | + |
| 177 | + //timers |
157 | 178 | cout << "==============TIMERS============" << endl;
|
158 | 179 | cout << "Init:\t" << tInit.getElapsed() << endl;
|
159 | 180 | cout << "Random:\t" << tRng.getElapsed() << endl;
|
@@ -184,12 +205,12 @@ Real64 BenchmarkHotgym::run(UInt EPOCHS, bool useSPlocal, bool useSPglobal, bool
|
184 | 205 |
|
185 | 206 | SDR goldTM({COLS});
|
186 | 207 | const SDR_sparse_t deterministicTM{
|
187 |
| - 51, 62, 72, 77, 102, 155, 287, 306, 337, 340, 370, 493, 542, 952, 1089, 1110, 1115, 1193, 1463, 1488, 1507, 1518, 1547, 1626, 1668, 1694, 1781, 1803, 1805, 1827, 1841, 1858,1859, 1860, 1861, 1862, 1878, 1881, 1915, 1918, 1923, 1929, 1933, 1939, 1941, 1953, 1955, 1956, 1958, 1961, 1965, 1968, 1975, 1976, 1980, 1981, 1985, 1986, 1987, 1991, 1992, 1994, 1997, 2002, 2006, 2008, 2012, 2013, 2040, 2042 |
| 208 | + 62, 77, 85, 322, 340, 432, 952, 1120, 1488, 1502, 1512, 1518, 1547, 1627, 1633, 1668, 1727, 1729, 1797, 1803, 1805, 1812, 1858, 1859, 1896, 1918, 1923, 1925, 1929, 1931, 1939, 1941, 1942, 1944, 1950, 1953, 1955, 1956, 1965, 1966, 1967, 1968, 1974, 1980, 1987, 1996, 2006, 2008, 2011, 2027, 2030, 2042, 2046 |
188 | 209 | };
|
189 | 210 | goldTM.setSparse(deterministicTM);
|
190 | 211 |
|
191 |
| - const float goldAn = 0.745098f; |
192 |
| - const float goldAnAvg = 0.408286f; |
| 212 | + const float goldAn = 0.627451f; |
| 213 | + const float goldAnAvg = 0.407265f; |
193 | 214 |
|
194 | 215 | if(EPOCHS == 5000) { //these hand-written values are only valid for EPOCHS = 5000 (default), but not for debug and custom runs.
|
195 | 216 | NTA_CHECK(input == goldEnc) << "Deterministic output of Encoder failed!\n" << input << "should be:\n" << goldEnc;
|
|
0 commit comments