Exemple #1
0
    def testNumSynapses(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

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

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

            connections.adaptSegment(segment, inputSDR, 0.1, 0.0, False)

            num_synapses = connections.numSynapses(segment)
            self.assertEqual(num_synapses, len(presynaptic_input),
                             "Missing synapses")

        self.assertEqual(connections.numSynapses(),
                         len(presynaptic_input) * 40, "Missing synapses")
    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")