Beispiel #1
0
    def testCellsForColumnInvalidColumn(self):
        tm = ExtendedTemporalMemory(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)
Beispiel #2
0
    def testCellsForColumnInvalidColumn(self):
        tm = ExtendedTemporalMemory(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)
Beispiel #3
0
    def testLeastUsedCell(self):
        tm = ExtendedTemporalMemory(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), connections), 1)
Beispiel #4
0
    def testBestMatchingCell(self):
        tm = ExtendedTemporalMemory(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])
        activeApicalCells = set()

        self.assertEqual(
            tm.bestMatchingCell(
                tm.cellsForColumn(0), activeCells, activeApicalCells, connections, tm.apicalConnections
            ),
            (0, 0, None),
        )

        self.assertEqual(
            tm.bestMatchingCell(
                tm.cellsForColumn(3), activeCells, activeApicalCells, connections, tm.apicalConnections
            ),
            (103, None, None),
        )  # Random cell from column

        self.assertEqual(
            tm.bestMatchingCell(
                tm.cellsForColumn(999), activeCells, activeApicalCells, connections, tm.apicalConnections
            ),
            (31979, None, None),
        )  # Random cell from column
Beispiel #5
0
    def testBestMatchingCell(self):
        tm = ExtendedTemporalMemory(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])
        activeApicalCells = set()

        self.assertEqual(
            tm.bestMatchingCell(tm.cellsForColumn(0), activeCells,
                                activeApicalCells, connections,
                                tm.apicalConnections), (0, 0, None))

        self.assertEqual(
            tm.bestMatchingCell(tm.cellsForColumn(3), activeCells,
                                activeApicalCells, connections,
                                tm.apicalConnections),
            (103, None, None))  # Random cell from column

        self.assertEqual(
            tm.bestMatchingCell(tm.cellsForColumn(999), activeCells,
                                activeApicalCells, connections,
                                tm.apicalConnections),
            (31979, None, None))  # Random cell from column
Beispiel #6
0
    def testLeastUsedCell(self):
        tm = ExtendedTemporalMemory(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), connections), 1)
Beispiel #7
0
    def testBestMatchingCellFewestSegments(self):
        tm = ExtendedTemporalMemory(
            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([])
        activeApicalCells = set()

        for _ in range(100):
            # Never pick cell 0, always pick cell 1
            (cell, _, _) = tm.bestMatchingCell(
                tm.cellsForColumn(0), activeSynapsesForSegment, activeApicalCells, connections, tm.apicalConnections
            )
            self.assertEqual(cell, 1)
Beispiel #8
0
    def testBestMatchingCellFewestSegments(self):
        tm = ExtendedTemporalMemory(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([])
        activeApicalCells = set()

        for _ in range(100):
            # Never pick cell 0, always pick cell 1
            (cell, _, _) = tm.bestMatchingCell(tm.cellsForColumn(0),
                                               activeSynapsesForSegment,
                                               activeApicalCells, connections,
                                               tm.apicalConnections)
            self.assertEqual(cell, 1)
Beispiel #9
0
 def testCellsForColumn2D(self):
     tm = ExtendedTemporalMemory(columnDimensions=[64, 64], cellsPerColumn=4)
     expectedCells = set([256, 257, 258, 259])
     self.assertEqual(tm.cellsForColumn(64), expectedCells)
Beispiel #10
0
 def testCellsForColumn1D(self):
     tm = ExtendedTemporalMemory(columnDimensions=[2048], cellsPerColumn=5)
     expectedCells = set([5, 6, 7, 8, 9])
     self.assertEqual(tm.cellsForColumn(1), expectedCells)
Beispiel #11
0
 def testCellsForColumn2D(self):
     tm = ExtendedTemporalMemory(columnDimensions=[64, 64],
                                 cellsPerColumn=4)
     expectedCells = set([256, 257, 258, 259])
     self.assertEqual(tm.cellsForColumn(64), expectedCells)
Beispiel #12
0
 def testCellsForColumn1D(self):
     tm = ExtendedTemporalMemory(columnDimensions=[2048], cellsPerColumn=5)
     expectedCells = set([5, 6, 7, 8, 9])
     self.assertEqual(tm.cellsForColumn(1), expectedCells)