def testNupicSpatialPoolerSavingToString(self): """Test writing to and reading from NuPIC SpatialPooler.""" # Simple test: make sure that writing/reading works... sp = SP() s = sp.writeToString() sp2 = SP(columnDimensions=[32, 32]) sp2.loadFromString(s) self.assertEqual( sp.getNumColumns(), sp2.getNumColumns(), "NuPIC SpatialPooler write to/read from string failed.")
def testNupicSpatialPoolerSavingToString(self): """Test writing to and reading from NuPIC SpatialPooler.""" inputs = SDR( 100 ).randomize( .05 ) active = SDR( 100 ) sp = SP( inputs.dimensions, active.dimensions, stimulusThreshold = 1 ) for _ in range(10): sp.compute( inputs, True, active ) # Simple test: make sure that writing/reading works... s = sp.writeToString() sp2 = SP(columnDimensions=[32, 32]) sp2.loadFromString(s) self.assertEqual(sp.getNumColumns(), sp2.getNumColumns(), "NuPIC SpatialPooler write to/read from string failed.") self.assertEqual(str(sp), str(sp2), "HTM SpatialPooler write to/read from string failed.")
def testNupicSpatialPoolerPickling(self): """Test pickling / unpickling of NuPIC SpatialPooler.""" # Simple test: make sure that dumping / loading works... sp = SP() pickledSp = pickle.dumps(sp) sp2 = pickle.loads(pickledSp) self.assertEqual(sp.getNumColumns(), sp2.getNumColumns(), "Simple NuPIC SpatialPooler pickle/unpickle failed.")
def _runGetConnectedCounts(self, uint_type): """ Check that getConnectedCounts() returns values. """ inputs = SDR(100).randomize(.05) active = SDR(100) sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1) for _ in range(10): sp.compute(inputs, True, active) # There should be at least one connected none zero connected = np.zeros(sp.getNumColumns(), dtype=uint_type) sp.getConnectedCounts(connected) assert (connected.sum() > 0)