예제 #1
0
    def testComputeActivity(self):
        """
        Test that connections are generated on predefined segments.
        """
        random = Random(1981)
        active_cells = np.array(random.sample(
            np.arange(0, NUM_CELLS, 1, dtype="uint32"), 40),
                                dtype="uint32")
        active_cells.sort()

        presynaptic_input = list(range(0, 10))
        inputSDR = SDR(1024)
        inputSDR.sparse = presynaptic_input
        l = len(presynaptic_input)

        connections = Connections(NUM_CELLS, 0.51, False)
        for i in range(NUM_CELLS):
            connections.createSegment(i, 1)

        numActiveConnectedSynapsesForSegment = connections.computeActivity(
            inputSDR, False)
        for count in numActiveConnectedSynapsesForSegment:
            self.assertEqual(count, 0, "Segment should not be active")

        for cell in active_cells:
            segments = connections.segmentsForCell(cell)
            segment = segments[0]
            for c in presynaptic_input:
                connections.createSynapse(segment, c, 0.1)

        numActiveConnectedSynapsesForSegment = connections.computeActivity(
            inputSDR, False)
        for count in numActiveConnectedSynapsesForSegment:
            self.assertEqual(count, 0, "Segment should not be active")

        for cell in active_cells:
            segments = connections.segmentsForCell(cell)
            segment = segments[0]
            connections.adaptSegment(segment, inputSDR, 0.5, 0.0, False)

        active_cells_set = set(active_cells)
        numActiveConnectedSynapsesForSegment = connections.computeActivity(
            inputSDR, False)
        for cell, count in enumerate(numActiveConnectedSynapsesForSegment):
            if cell in active_cells_set:
                self.assertEqual(count, l, "Segment should be active")
            else:
                self.assertEqual(count, 0, "Segment should not be active")
예제 #2
0
    def testComputeActivityUnion(self):
        """
        Test that connections are generated on predefined segments.
        """
        random = Random(1981)
        active_cells = np.array(random.sample(
            np.arange(0, NUM_CELLS, 1, dtype="uint32"), 40),
                                dtype="uint32")
        active_cells.sort()

        presynaptic_input1 = list(range(0, 10))
        presynaptic_input2 = list(range(10, 20))

        connections = Connections(NUM_CELLS, 0.51, False)
        for i in range(NUM_CELLS):
            connections.createSegment(i, 1)

        self._learn(connections, active_cells, presynaptic_input1)
        self._learn(connections, active_cells, presynaptic_input2)

        numSynapses = connections.numSynapses()
        self.assertNotEqual(
            numSynapses, 40,
            "There should be a synapse for each presynaptic cell")

        active_cells_set = set(active_cells)
        inputSDR = SDR(1024)
        inputSDR.sparse = presynaptic_input1

        numActiveConnectedSynapsesForSegment = connections.computeActivity(
            inputSDR, False)
        for cell, count in enumerate(numActiveConnectedSynapsesForSegment):
            if cell in active_cells_set:
                self.assertNotEqual(count, 0, "Segment should be active")

        inputSDR.sparse = presynaptic_input2
        numActiveConnectedSynapsesForSegment = connections.computeActivity(
            inputSDR, False)
        for cell, count in enumerate(numActiveConnectedSynapsesForSegment):
            if cell in active_cells_set:
                self.assertNotEqual(count, 0, "Segment should be active")