def testBestMatchingCell(self): tm = TemporalMemory(connectedPermanence=0.50, minThreshold=1, seed=42) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 23, 0.6) connections.createSynapse(0, 37, 0.4) connections.createSynapse(0, 477, 0.9) connections.createSegment(0) connections.createSynapse(1, 49, 0.9) connections.createSynapse(1, 3, 0.8) connections.createSegment(1) connections.createSynapse(2, 733, 0.7) connections.createSegment(108) connections.createSynapse(3, 486, 0.9) activeCells = set([23, 37, 49, 733]) self.assertEqual( tm.bestMatchingCell(tm.cellsForColumn(0), activeCells), (0, 0)) self.assertEqual( tm.bestMatchingCell( tm.cellsForColumn(3), # column containing cell 108 activeCells), (103, None)) # Random cell from column self.assertEqual( tm.bestMatchingCell(tm.cellsForColumn(999), activeCells), (31979, None)) # Random cell from column
def testCellsForColumnInvalidColumn(self): tm = TemporalMemory(columnDimensions=[64, 64], cellsPerColumn=4) try: tm.cellsForColumn(4095) except IndexError: self.fail("IndexError raised unexpectedly") args = [4096] self.assertRaises(IndexError, tm.cellsForColumn, *args) args = [-1] self.assertRaises(IndexError, tm.cellsForColumn, *args)
def testCellsForColumnInvalidColumn(self): tm = TemporalMemory( columnDimensions=[64, 64], cellsPerColumn=4 ) try: tm.cellsForColumn(4095) except IndexError: self.fail("IndexError raised unexpectedly") args = [4096] self.assertRaises(IndexError, tm.cellsForColumn, *args) args = [-1] self.assertRaises(IndexError, tm.cellsForColumn, *args)
def testCellsForColumn2D(self): tm = TemporalMemory( columnDimensions=[64, 64], cellsPerColumn=4 ) expectedCells = set([256, 257, 258, 259]) self.assertEqual(tm.cellsForColumn(64), expectedCells)
def testCellsForColumn1D(self): tm = TemporalMemory( columnDimensions=[2048], cellsPerColumn=5 ) expectedCells = set([5, 6, 7, 8, 9]) self.assertEqual(tm.cellsForColumn(1), expectedCells)
def testLeastUsedCell(self): tm = TemporalMemory(columnDimensions=[2], cellsPerColumn=2, seed=42) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 3, 0.3) for _ in range(100): # Never pick cell 0, always pick cell 1 self.assertEqual(tm.leastUsedCell(tm.cellsForColumn(0)), 1)
def testBestMatchingCell(self): tm = TemporalMemory( connectedPermanence=0.50, minThreshold=1, seed=42 ) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 23, 0.6) connections.createSynapse(0, 37, 0.4) connections.createSynapse(0, 477, 0.9) connections.createSegment(0) connections.createSynapse(1, 49, 0.9) connections.createSynapse(1, 3, 0.8) connections.createSegment(1) connections.createSynapse(2, 733, 0.7) connections.createSegment(108) connections.createSynapse(3, 486, 0.9) activeCells = set([23, 37, 49, 733]) self.assertEqual(tm.bestMatchingCell(tm.cellsForColumn(0), activeCells, connections), (0, 0)) self.assertEqual(tm.bestMatchingCell(tm.cellsForColumn(3), # column containing cell 108 activeCells, connections), (96, None)) # Random cell from column self.assertEqual(tm.bestMatchingCell(tm.cellsForColumn(999), activeCells, connections), (31972, None)) # Random cell from column
def testLeastUsedCell(self): tm = TemporalMemory( columnDimensions=[2], cellsPerColumn=2, seed=42 ) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 3, 0.3) for _ in range(100): # Never pick cell 0, always pick cell 1 self.assertEqual(tm.leastUsedCell(tm.cellsForColumn(0)), 1)
def testBestMatchingCellFewestSegments(self): tm = TemporalMemory(columnDimensions=[2], cellsPerColumn=2, connectedPermanence=0.50, minThreshold=1, seed=42) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 3, 0.3) activeSynapsesForSegment = set([]) for _ in range(100): # Never pick cell 0, always pick cell 1 (cell, _) = tm.bestMatchingCell(tm.cellsForColumn(0), activeSynapsesForSegment) self.assertEqual(cell, 1)
def testBestMatchingCellFewestSegments(self): tm = TemporalMemory( columnDimensions=[2], cellsPerColumn=2, connectedPermanence=0.50, minThreshold=1, seed=42 ) connections = tm.connections connections.createSegment(0) connections.createSynapse(0, 3, 0.3) activeSynapsesForSegment = set([]) for _ in range(100): # Never pick cell 0, always pick cell 1 (cell, _) = tm.bestMatchingCell(tm.cellsForColumn(0), activeSynapsesForSegment) self.assertEqual(cell, 1)