本文整理汇总了Python中nupic.research.connections.Connections.computeActivity方法的典型用法代码示例。如果您正苦于以下问题:Python Connections.computeActivity方法的具体用法?Python Connections.computeActivity怎么用?Python Connections.computeActivity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.connections.Connections
的用法示例。
在下文中一共展示了Connections.computeActivity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testComputeActivity
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [as 别名]
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])
示例2: testDestroySegment
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [as 别名]
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])
示例3: testDestroySegment
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [as 别名]
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())
args = [segment2]
self.assertRaises(ValueError, connections.synapsesForSegment, *args)
active, matching = connections.computeActivity([80, 81, 82], .5, 2, .1, 1)
self.assertEqual(len(active), 0)
self.assertEqual(len(matching), 0)
示例4: testCreateSegmentReuse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [as 别名]
def testCreateSegmentReuse(self):
connections = Connections(1024, 2)
segment1 = connections.createSegment(42)
connections.createSynapse(segment1, 1, .5)
connections.createSynapse(segment1, 2, .5)
connections.computeActivity([], .5, 2, .1, 1)
connections.computeActivity([], .5, 2, .1, 1)
connections.computeActivity([], .5, 2, .1, 1)
segment2 = connections.createSegment(42)
activeSegs, _ = connections.computeActivity([1, 2], .5, 2, .1, 1)
self.assertEqual(1, len(activeSegs))
self.assertEqual(segment1, activeSegs[0].segment)
segment3 = connections.createSegment(42)
self.assertEqual(segment2.idx, segment3.idx)
示例5: testComputeActivity
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [as 别名]
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 2 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)
# Segment with:
# - 2 connected synapses: 1 active, 1 inactive
# - 3 matching synapses: 2 active, 1 inactive
# - 1 non-matching synapse: 1 active
segment2b = connections.createSegment(20)
connections.createSynapse(segment2b, 50, .85)
connections.createSynapse(segment2b, 51, .85)
connections.createSynapse(segment2b, 52, .15)
connections.createSynapse(segment2b, 53, .05)
# Cell with one segment.
# Segment with:
# - 1 non-matching synapse: 1 active
segment3a = connections.createSegment(30)
connections.createSynapse(segment3a, 53, .05)
inputVec = [50, 52, 53, 80, 81, 82, 150, 151]
active, matching = connections.computeActivity(inputVec, .5, 2, .1, 1)
self.assertEqual(1, len(active))
self.assertEqual(segment2a, active[0].segment)
self.assertEqual(2, active[0].overlap)
self.assertEqual(3, len(matching))
self.assertEqual(segment1a, matching[0].segment)
self.assertEqual(2, matching[0].overlap)
self.assertEqual(segment2a, matching[1].segment)
self.assertEqual(3, matching[1].overlap)
self.assertEqual(segment2b, matching[2].segment)
self.assertEqual(2, matching[2].overlap)
示例6: testDestroySynapse
# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import computeActivity [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 computeActivity [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 computeActivity [as 别名]
#.........这里部分代码省略.........
self.connections,
learn,
self.permanenceDecrement,
self.permanenceIncrement,
prevActiveCells)
self.activeCells += cellsToAdd
self.winnerCells += cellsToAdd
else:
(cellsToAdd,
winnerCell) = TemporalMemory.burstColumn(self.cellsPerColumn,
column,
self.connections,
self.initialPermanence,
learn,
matchingSegmentsOnCol,
self.maxNewSynapseCount,
self.permanenceDecrement,
self.permanenceIncrement,
prevActiveCells,
prevWinnerCells,
self._random)
self.activeCells += cellsToAdd
self.winnerCells.append(winnerCell)
else:
if learn:
TemporalMemory.punishPredictedColumn(self.connections,
matchingSegmentsOnCol,
self.predictedSegmentDecrement,
prevActiveCells)
(activeSegments,
matchingSegments) = self.connections.computeActivity(
self.activeCells,
self.connectedPermanence,
self.activationThreshold,
0.0,
self.minThreshold,
learn)
self.activeSegments = activeSegments
self.matchingSegments = matchingSegments
def reset(self):
""" Indicates the start of a new sequence and resets the sequence
state of the TM. """
self.activeCells = []
self.winnerCells = []
self.activeSegments = []
self.matchingSegments = []
@staticmethod
def activatePredictedColumn(activeSegments, connections, learn,
permanenceDecrement, permanenceIncrement,
prevActiveCells):
""" Determines which cells in a predicted column should be added to
winner cells list and calls adaptSegment on the segments that correctly
predicted this column.
@param activeSegments (iter) A iterable of SegmentOverlap objects for the
column compute is operating on that are
active
@param connections (Object) Connections instance for the tm