def testAdaptShouldRemoveSegments(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.51) for i in range(NUM_CELLS): seg = connections.createSegment(i, 1) for cell in active_cells: segments = connections.segmentsForCell(cell) self.assertEqual(len(segments), 1, "Segments were prematurely destroyed.") segment = segments[0] connections.adaptSegment(segment, inputSDR, 0.1, 0.001, True) segments = connections.segmentsForCell(cell) self.assertEqual(len(segments), 0, "Segments were not destroyed.")
def testAdaptShouldRemoveSegments(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.51) for i in range(NUM_CELLS): seg = connections.createSegment(i, 2) seg = connections.createSegment(i, 2) #create 2 segments on each cell for cell in active_cells: segments = connections.segmentsForCell(cell) self.assertEqual(len(segments), 2, "Segments were prematurely destroyed.") segment = segments[0] numSynapsesOnSegment = len(segments) connections.adaptSegment(segment, inputSDR, 0.1, 0.001, pruneZeroSynapses=True, segmentThreshold=1) #set to =1 so that segments get always deleted in this test segments = connections.segmentsForCell(cell) self.assertEqual(len(segments), 1, "Segments were not destroyed.")
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 testAdaptShouldDecrementSynapses(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.51) 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) presynamptic_cells = self._getPresynapticCells( connections, segment, 0.2) self.assertEqual(presynamptic_cells, presynaptic_input_set, "Missing synapses") presynaptic_input1 = list(range(0, 5)) presynaptic_input_set1 = set(presynaptic_input1) inputSDR.sparse = presynaptic_input1 for cell in active_cells: segments = connections.segmentsForCell(cell) segment = segments[0] connections.adaptSegment(segment, inputSDR, 0.0, 0.1, False) presynamptic_cells = self._getPresynapticCells( connections, segment, 0.2) self.assertEqual(presynamptic_cells, presynaptic_input_set1, "Too many synapses") presynamptic_cells = self._getPresynapticCells( connections, segment, 0.1) self.assertEqual(presynamptic_cells, presynaptic_input_set, "Missing synapses")
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)) presynaptic_input_set = set(presynaptic_input) inputSDR = SDR(1024) inputSDR.sparse = presynaptic_input l = len(presynaptic_input) connections = Connections(NUM_CELLS, 0.51, False) for i in range(NUM_CELLS): seg = 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")