本文整理汇总了Python中nupic.research.connections.Connections.synapsesForSegment方法的典型用法代码示例。如果您正苦于以下问题:Python Connections.synapsesForSegment方法的具体用法?Python Connections.synapsesForSegment怎么用?Python Connections.synapsesForSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.connections.Connections
的用法示例。
在下文中一共展示了Connections.synapsesForSegment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPathsNotInvalidatedByOtherDestroys
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
def testPathsNotInvalidatedByOtherDestroys(self):
""" Creates segments and synapses, then destroys segments and synapses on
either side of them and verifies that existing Segment and Synapse
instances still point to the same segment / synapse as before.
"""
connections = Connections(1024)
segment1 = connections.createSegment(11)
connections.createSegment(12)
segment3 = connections.createSegment(13)
connections.createSegment(14)
segment5 = connections.createSegment(15)
synapse1 = connections.createSynapse(segment3, 201, .85)
synapse2 = connections.createSynapse(segment3, 202, .85)
synapse3 = connections.createSynapse(segment3, 203, .85)
synapse4 = connections.createSynapse(segment3, 204, .85)
synapse5 = connections.createSynapse(segment3, 205, .85)
self.assertEqual(203, synapse3.presynapticCell)
connections.destroySynapse(synapse1)
self.assertEqual(203, synapse3.presynapticCell)
connections.destroySynapse(synapse5)
self.assertEqual(203, synapse3.presynapticCell)
connections.destroySegment(segment1)
self.assertEqual(set([synapse2, synapse3, synapse4]),
connections.synapsesForSegment(segment3))
connections.destroySegment(segment5)
self.assertEqual(set([synapse2, synapse3, synapse4]),
connections.synapsesForSegment(segment3))
self.assertEqual(203, synapse3.presynapticCell)
示例2: testCreateSegmentReuse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
def testCreateSegmentReuse(self):
connections = Connections(1024, 2)
segment1 = connections.createSegment(42)
connections.createSynapse(segment1, 1, .5)
connections.createSynapse(segment1, 2, .5)
# Let some time pass.
connections.startNewIteration();
connections.startNewIteration();
connections.startNewIteration();
# Create a segment with 3 synapse.
segment2 = connections.createSegment(42)
connections.createSynapse(segment2, 1, .5)
connections.createSynapse(segment2, 2, .5)
connections.createSynapse(segment2, 3, .5)
connections.startNewIteration();
# Give the first segment some activity.
connections.recordSegmentActivity(segment1)
# Create a new segment with 1 synapse.
segment3 = connections.createSegment(42);
connections.createSynapse(segment3, 1, .5)
segments = connections.segmentsForCell(42)
self.assertEqual(2, len(segments))
# Verify first segment is still there with the same synapses.
self.assertEqual(set([1, 2]),
set(synapse.presynapticCell for synapse in
connections.synapsesForSegment(segments[0])))
# Verify second segment has been replaced.
self.assertEqual(set([1]),
set(synapse.presynapticCell for synapse in
connections.synapsesForSegment(segments[1])))
# Verify the flatIdxs were properly reused.
self.assertLess(segment1.flatIdx, 2)
self.assertLess(segment3.flatIdx, 2)
self.assertTrue(segment1 is connections.segmentForFlatIdx(segment1.flatIdx))
self.assertTrue(segment3 is connections.segmentForFlatIdx(segment3.flatIdx))
示例3: testSynapseReuse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
def testSynapseReuse(self):
""" Creates a synapse over the synapses per segment limit, and verifies
that the lowest permanence synapse is removed to make room for the new
synapse.
"""
connections = Connections(1024, 1024, 2)
segment = connections.createSegment(10)
synapse1 = connections.createSynapse(segment, 50, .34)
synapse2 = connections.createSynapse(segment, 51, .34)
synapses = connections.synapsesForSegment(segment)
self.assertEqual(synapses, [synapse1, synapse2])
#Add an additional synapse to force it over the limit of num synapses
#per segment.
synapse3 = connections.createSynapse(segment, 52, .52)
self.assertEqual(0, synapse3.idx)
#ensure lower permanence synapse was removed
synapses = connections.synapsesForSegment(segment)
self.assertEqual(synapses, [synapse3, synapse2])
示例4: testSynapseReuse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
def testSynapseReuse(self):
""" Creates a synapse over the synapses per segment limit, and verifies
that the lowest permanence synapse is removed to make room for the new
synapse.
"""
connections = Connections(1024, 1024, 2)
segment = connections.createSegment(10)
synapse1 = connections.createSynapse(segment, 50, .34)
synapse2 = connections.createSynapse(segment, 51, .48)
synapses = connections.synapsesForSegment(segment)
self.assertEqual(set([synapse1, synapse2]), synapses)
# Add an additional synapse to force it over the limit of num synapses
# per segment.
connections.createSynapse(segment, 52, .52)
# Ensure lower permanence synapse was removed.
self.assertEqual(set([51, 52]),
set(synapse.presynapticCell
for synapse in
connections.synapsesForSegment(segment)))
示例5: testReuseSegmentWithDestroyedSynapses
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
def testReuseSegmentWithDestroyedSynapses(self):
""" Destroy a segment that has a destroyed synapse and a non-destroyed
synapse. Create a new segment in the same place. Make sure its synapse
count is correct.
"""
connections = Connections(1024)
segment = connections.createSegment(11)
synapse1 = connections.createSynapse(segment, 201, .85)
connections.createSynapse(segment, 202, .85)
connections.destroySynapse(synapse1)
self.assertEqual(1, connections.numSynapses(segment))
connections.destroySegment(segment)
reincarnated = connections.createSegment(11)
self.assertEqual(0, connections.numSynapses(reincarnated))
self.assertEqual(0, len(connections.synapsesForSegment(reincarnated)))
示例6: testDestroySynapse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
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(connections.synapsesForSegment(segment), [synapse1,
synapse3])
active, matching = connections.computeActivity([80, 81, 82], .5, 2, 0.0, 1)
self.assertEqual(0, len(active))
self.assertEqual(1, len(matching))
self.assertEqual(2, matching[0].overlap)
示例7: testDestroySynapse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
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])
示例8: TemporalMemory
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import synapsesForSegment [as 别名]
#.........这里部分代码省略.........
for cell in cells:
segment, numActiveSynapses = self.bestMatchingSegment(cell, activeCells)
if segment is not None and numActiveSynapses > maxSynapses:
maxSynapses = numActiveSynapses
bestCell = cell
bestSegment = segment
if bestCell is None:
bestCell = self.leastUsedCell(cells)
return bestCell, bestSegment
def bestMatchingSegment(self, cell, activeCells):
"""
Gets the segment on a cell with the largest number of activate synapses,
including all synapses with non-zero permanences.
@param cell (int) Cell index
@param activeCells (set) Indices of active cells
@return (tuple) Contains:
`segment` (int),
`connectedActiveSynapses` (set)
"""
maxSynapses = self.minThreshold
bestSegment = None
bestNumActiveSynapses = None
for segment in self.connections.segmentsForCell(cell):
numActiveSynapses = 0
for synapse in self.connections.synapsesForSegment(segment):
synapseData = self.connections.dataForSynapse(synapse)
if ( (synapseData.presynapticCell in activeCells) and
synapseData.permanence > 0):
numActiveSynapses += 1
if numActiveSynapses >= maxSynapses:
maxSynapses = numActiveSynapses
bestSegment = segment
bestNumActiveSynapses = numActiveSynapses
return bestSegment, bestNumActiveSynapses
def leastUsedCell(self, cells):
"""
Gets the cell with the smallest number of segments.
Break ties randomly.
@param cells (set) Indices of cells
@return (int) Cell index
"""
leastUsedCells = set()
minNumSegments = float("inf")
for cell in cells:
numSegments = len(self.connections.segmentsForCell(cell))
if numSegments < minNumSegments:
minNumSegments = numSegments
leastUsedCells = set()