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): 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 testAdaptShouldIncrementSynapses(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): 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.001, True) presynamptic_cells = self._getPresynapticCells( connections, segment, 0.2) self.assertEqual(presynamptic_cells, presynaptic_input_set, "Missing synapses") presynamptic_cells = self._getPresynapticCells( connections, segment, 0.3) self.assertEqual(presynamptic_cells, set(), "Too many synapses")
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 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")