def testBestMatchingCell(self): tm = TemporalMemory( connectedPermanence=0.50, minThreshold=1, seed=42 ) segment1 = tm.layer.columns[0].cells[0].createSegment() segment1.createSynapse(presynapticCell=tm.layer.columns[0].cells[23], permanence=0.6) segment1.createSynapse(presynapticCell=tm.layer.columns[1].cells[5], permanence=0.4) segment1.createSynapse(presynapticCell=tm.layer.columns[14].cells[29], permanence=0.9) segment2 = tm.layer.columns[0].cells[0].createSegment() segment2.createSynapse(presynapticCell=tm.layer.columns[1].cells[17], permanence=0.9) segment2.createSynapse(presynapticCell=tm.layer.columns[0].cells[3], permanence=0.8) segment3 = tm.layer.columns[0].cells[1].createSegment() segment3.createSynapse(presynapticCell=tm.layer.columns[22].cells[29], permanence=0.7) segment4 = tm.layer.columns[3].cells[12].createSegment() segment4.createSynapse(presynapticCell=tm.layer.columns[15].cells[6], permanence=0.9) activeCells = set([tm.layer.columns[0].cells[23], tm.layer.columns[1].cells[5], tm.layer.columns[1].cells[17], tm.layer.columns[22].cells[29]]) self.assertEqual(tm.bestMatchingCell(tm.layer.columns[0].cells, activeCells), (tm.layer.columns[0].cells[0], segment1)) self.assertEqual(tm.bestMatchingCell(tm.layer.columns[3].cells, # column containing cell 108 activeCells), (tm.layer.columns[3].cells[20], None)) # Random cell from column self.assertEqual(tm.bestMatchingCell(tm.layer.columns[999].cells, activeCells), (tm.layer.columns[999].cells[19], None)) # Random cell from column
def testBestMatchingCellFewestSegments(self): tm = TemporalMemory( layer=Layer(columnDimensions=[2], numCellsPerColumn=2), connectedPermanence=0.50, minThreshold=1, seed=42 ) segment1 = tm.layer.columns[0].cells[0].createSegment() segment1.createSynapse(presynapticCell=tm.layer.columns[1].cells[1], permanence=0.3) activeSynapsesForSegment = set([]) for _ in range(100): # Never pick cell 0, always pick cell 1 (cell, _) = tm.bestMatchingCell(tm.layer.columns[0].cells, activeSynapsesForSegment) self.assertEqual(cell, tm.layer.columns[0].cells[1])