def testDestroySegment(self): """ Creates a segment, destroys it, and makes sure it got destroyed along with all of its synapses. """ connections = Connections(1024) connections.createSegment(10) segment2 = connections.createSegment(20) connections.createSegment(30) connections.createSegment(40) connections.createSynapse(segment2, 80, 0.85) connections.createSynapse(segment2, 81, 0.85) connections.createSynapse(segment2, 82, 0.15) self.assertEqual(4, connections.numSegments()) self.assertEqual(3, connections.numSynapses()) connections.destroySegment(segment2) self.assertEqual(3, connections.numSegments()) self.assertEqual(0, connections.numSynapses()) (numActiveConnected, numActivePotential) = connections.computeActivity([80, 81, 82], 0.5) self.assertEqual(0, numActiveConnected[segment2.flatIdx]) self.assertEqual(0, numActivePotential[segment2.flatIdx])
def testComputeActivity(self): """ Creates a sample set of connections, and makes sure that computing the activity for a collection of cells with no activity returns the right activity data. """ connections = Connections(1024) # Cell with 1 segment. # Segment with: # - 1 connected synapse: active # - 2 matching synapses segment1a = connections.createSegment(10) connections.createSynapse(segment1a, 150, .85) connections.createSynapse(segment1a, 151, .15) # Cell with 1 segment. # Segment with: # - 2 connected synapse: 2 active # - 3 matching synapses: 3 active segment2a = connections.createSegment(20) connections.createSynapse(segment2a, 80, .85) connections.createSynapse(segment2a, 81, .85) synapse = connections.createSynapse(segment2a, 82, .85) connections.updateSynapsePermanence(synapse, .15) inputVec = [50, 52, 53, 80, 81, 82, 150, 151] (numActiveConnected, numActivePotential) = connections.computeActivity(inputVec, .5) self.assertEqual(1, numActiveConnected[segment1a.flatIdx]) self.assertEqual(2, numActivePotential[segment1a.flatIdx]) self.assertEqual(2, numActiveConnected[segment2a.flatIdx]) self.assertEqual(3, numActivePotential[segment2a.flatIdx])
def testDestroySynapse(self): """ Creates a segment, creates a number of synapses on it, destroys a synapse, and makes sure it got destroyed. """ connections = Connections(1024) segment = connections.createSegment(20) synapse1 = connections.createSynapse(segment, 80, .85) synapse2 = connections.createSynapse(segment, 81, .85) synapse3 = connections.createSynapse(segment, 82, .15) self.assertEqual(3, connections.numSynapses()) connections.destroySynapse(synapse2) self.assertEqual(2, connections.numSynapses()) self.assertEqual(set([synapse1, synapse3]), connections.synapsesForSegment(segment)) (numActiveConnected, numActivePotential) = connections.computeActivity([80, 81, 82], .5) self.assertEqual(1, numActiveConnected[segment.flatIdx]) self.assertEqual(2, numActivePotential[segment.flatIdx])