def testCalculateOverlap(self): sp = SpatialPooler(inputDimensions=[10], columnDimensions=[5]) permanences = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]] inputVectors = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] expectedOverlaps = [[0, 0, 0, 0, 0], [10, 8, 6, 4, 2], [5, 4, 3, 2, 1], [5, 3, 1, 0, 0], [1, 1, 1, 1, 1]] for column, permanence in enumerate(permanences): sp.setPermanence(column, np.array(permanence, dtype=realDType)) for inputVector, expectedOverlap in zip(inputVectors, expectedOverlaps): inputVector = np.array(inputVector, dtype=uintDType) overlap = set(sp._calculateOverlap(inputVector)) expected = set(expectedOverlap) self.assertSetEqual( overlap, expected, "Input: {0}\tExpected: {1}\tActual: {2}".format( inputVector, expected, overlap))
def testCalculateOverlap(self): sp = SpatialPooler(inputDimensions = [10], columnDimensions = [5]) permanences = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 1, 1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1] ] inputVectors = [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], [1, 1, 1, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1] ] expectedOverlaps = [ [0, 0, 0, 0, 0], [10, 8, 6, 4, 2], [5, 4, 3, 2, 1], [5, 3, 1, 0, 0], [1, 1, 1, 1, 1] ] for column, permanence in enumerate(permanences): sp.setPermanence(column, np.array(permanence, dtype=realDType)) for inputVector, expectedOverlap in zip(inputVectors, expectedOverlaps): inputVector = np.array(inputVector, dtype=uintDType) overlap = set(sp._calculateOverlap(inputVector)) expected = set(expectedOverlap) self.assertSetEqual(overlap, expected, "Input: {0}\tExpected: {1}\tActual: {2}".format( inputVector, expected, overlap))