def basicComputeLoop(self, imp, params, inputSize, columnDimensions, seed = None): """ Feed in some vectors and retrieve outputs. Ensure the right number of columns win, that we always get binary outputs, and that nothing crashes. """ sp = CreateSP(imp,params) # Create a set of input vectors as well as various numpy vectors we will # need to retrieve data from the SP numRecords = 100 randomState = getNumpyRandomGenerator(seed) inputMatrix = ( randomState.rand(numRecords,inputSize) > 0.8).astype(uintType) y = cupy.zeros(columnDimensions, dtype = uintType) dutyCycles = cupy.zeros(columnDimensions, dtype = uintType) # With learning on we should get the requested number of winners for v in inputMatrix: y.fill(0) sp.compute(v, True, y) self.assertEqual(sp.getNumActiveColumnsPerInhArea(),y.sum()) self.assertEqual(0,y.min()) self.assertEqual(1,y.max()) # With learning off and some prior training we should get the requested # number of winners for v in inputMatrix: y.fill(0) sp.compute(v, False, y) self.assertEqual(sp.getNumActiveColumnsPerInhArea(),y.sum()) self.assertEqual(0,y.min()) self.assertEqual(1,y.max())
def basicComputeLoop(self, imp, params, inputSize, columnDimensions, seed = None): """ Feed in some vectors and retrieve outputs. Ensure the right number of columns win, that we always get binary outputs, and that nothing crashes. """ sp = CreateSP(imp,params) # Create a set of input vectors as well as various numpy vectors we will # need to retrieve data from the SP numRecords = 100 randomState = getNumpyRandomGenerator(seed) inputMatrix = ( randomState.rand(numRecords,inputSize) > 0.8).astype(uintType) y = numpy.zeros(columnDimensions, dtype = uintType) dutyCycles = numpy.zeros(columnDimensions, dtype = uintType) # With learning on we should get the requested number of winners for v in inputMatrix: y.fill(0) sp.compute(v, True, y) self.assertEqual(sp.getNumActiveColumnsPerInhArea(),y.sum()) self.assertEqual(0,y.min()) self.assertEqual(1,y.max()) # With learning off and some prior training we should get the requested # number of winners for v in inputMatrix: y.fill(0) sp.compute(v, False, y) self.assertEqual(sp.getNumActiveColumnsPerInhArea(),y.sum()) self.assertEqual(0,y.min()) self.assertEqual(1,y.max())