本文整理汇总了Python中nupic.research.connections.Connections.dataForSynapse方法的典型用法代码示例。如果您正苦于以下问题:Python Connections.dataForSynapse方法的具体用法?Python Connections.dataForSynapse怎么用?Python Connections.dataForSynapse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.connections.Connections
的用法示例。
在下文中一共展示了Connections.dataForSynapse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPathsNotInvalidatedByOtherDestroys
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import dataForSynapse [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, connections.dataForSynapse(synapse3).presynapticCell)
connections.destroySynapse(synapse1)
self.assertEqual(203, connections.dataForSynapse(synapse3).presynapticCell)
connections.destroySynapse(synapse5)
self.assertEqual(203, connections.dataForSynapse(synapse3).presynapticCell)
connections.destroySegment(segment1)
self.assertEqual(connections.synapsesForSegment(segment3),
[synapse2, synapse3, synapse4])
connections.destroySegment(segment5)
self.assertEqual(connections.synapsesForSegment(segment3),
[synapse2, synapse3, synapse4])
self.assertEqual(203, connections.dataForSynapse(synapse3).presynapticCell)
示例2: testUpdateSynapsePermanence
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import dataForSynapse [as 别名]
def testUpdateSynapsePermanence(self):
""" Creates a synapse and updates its permanence, and makes sure that its
data was correctly updated.
"""
connections = Connections(1024)
segment = connections.createSegment(10)
synapse = connections.createSynapse(segment, 50, .34)
connections.updateSynapsePermanence(synapse, .21)
synapseData = connections.dataForSynapse(synapse)
self.assertAlmostEqual(synapseData.permanence, .21)
示例3: TemporalMemory
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import dataForSynapse [as 别名]
#.........这里部分代码省略.........
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()
if numSegments == minNumSegments: