def testNumConnectedSynapses(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)) presynaptic_input_set = set(presynaptic_input) inputSDR = SDR(1024) inputSDR.sparse = presynaptic_input connections = Connections(NUM_CELLS, 0.2) for i in range(NUM_CELLS): seg = 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) connected_synapses = connections.numConnectedSynapses(segment) self.assertEqual(connected_synapses, len(presynaptic_input), "Missing synapses") presynaptic_input1 = list(range(0, 5)) presynaptic_input_set1 = set(presynaptic_input1) inputSDR.sparse = presynaptic_input1 total_connected = 0 for cell in active_cells: segments = connections.segmentsForCell(cell) segment = segments[0] connections.adaptSegment(segment, inputSDR, 0.0, 0.1, False) connected_synapses = connections.numConnectedSynapses(segment) self.assertEqual(connected_synapses, len(presynaptic_input1), "Missing synapses") total_connected += connected_synapses connected_synapses = connections.numSynapses(segment) self.assertEqual(connected_synapses, len(presynaptic_input), "Missing synapses") self.assertEqual(total_connected, len(presynaptic_input1) * 40, "Missing synapses")
def testDestroySegment(self): co = Connections(NUM_CELLS, 0.51) self.assertEqual(co.numSegments(), 0, "there are zero segments yet") # removing while no segments exist co.destroySegment(1) # successfully remove seg = co.createSegment(1, 20) self.assertEqual(co.numSegments(), 1) n = co.numConnectedSynapses(seg) #uses dataForSegment() co.destroySegment(seg) self.assertEqual(co.numSegments(), 0, "segment should have been removed") with pytest.raises(RuntimeError): n2 = co.numConnectedSynapses(seg)
def testDestroySegment(self): co = Connections(NUM_CELLS, 0.51) self.assertEqual(co.numSegments(), 0, "there are zero segments yet") # successfully remove seg = co.createSegment(1, 20) self.assertEqual(co.numSegments(), 1) n = co.numConnectedSynapses(seg) #uses dataForSegment() co.destroySegment(seg) self.assertEqual(co.numSegments(), 0, "segment should have been removed")