本文整理汇总了Python中nupic.algorithms.temporal_memory.TemporalMemory.getWinnerCells方法的典型用法代码示例。如果您正苦于以下问题:Python TemporalMemory.getWinnerCells方法的具体用法?Python TemporalMemory.getWinnerCells怎么用?Python TemporalMemory.getWinnerCells使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.algorithms.temporal_memory.TemporalMemory
的用法示例。
在下文中一共展示了TemporalMemory.getWinnerCells方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNewSegmentAddSynapsesToSubsetOfWinnerCells
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testNewSegmentAddSynapsesToSubsetOfWinnerCells(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.50,
minThreshold=2,
maxNewSynapseCount=2,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.0,
seed=42)
previousActiveColumns = [0, 1, 2]
activeColumns = [4]
tm.compute(previousActiveColumns, True)
prevWinnerCells = tm.getWinnerCells() #[0, 8, 7]
self.assertEqual(3, len(prevWinnerCells))
tm.compute(activeColumns, True)
winnerCells = tm.getWinnerCells() #[18]
self.assertEqual(1, len(winnerCells))
segments = list(tm.connections.segmentsForCell(winnerCells[0]))
self.assertEqual(1, len(segments))
synapses = list(tm.connections.synapsesForSegment(segments[0]))
self.assertEqual(2, len(synapses))
for synapse in synapses:
synapseData = tm.connections.dataForSynapse(synapse)
self.assertAlmostEqual(.21, synapseData.permanence)
self.assertTrue(synapseData.presynapticCell in prevWinnerCells)
示例2: testZeroActiveColumns
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testZeroActiveColumns(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.5,
minThreshold=2,
maxNewSynapseCount=3,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.0,
seed=42)
previousActiveColumns = [0]
previousActiveCells = [0, 1, 2, 3]
expectedActiveCells = [4]
segment = tm.createSegment(expectedActiveCells[0])
tm.connections.createSynapse(segment, previousActiveCells[0], .5)
tm.connections.createSynapse(segment, previousActiveCells[1], .5)
tm.connections.createSynapse(segment, previousActiveCells[2], .5)
tm.connections.createSynapse(segment, previousActiveCells[3], .5)
tm.compute(previousActiveColumns, True)
self.assertFalse(len(tm.getActiveCells()) == 0)
self.assertFalse(len(tm.getWinnerCells()) == 0)
self.assertFalse(len(tm.getPredictiveCells()) == 0)
zeroColumns = []
tm.compute(zeroColumns, True)
self.assertTrue(len(tm.getActiveCells()) == 0)
self.assertTrue(len(tm.getWinnerCells()) == 0)
self.assertTrue(len(tm.getPredictiveCells()) == 0)
示例3: testMatchingSegmentAddSynapsesToAllWinnerCells
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testMatchingSegmentAddSynapsesToAllWinnerCells(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=1,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.50,
minThreshold=1,
maxNewSynapseCount=3,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.0,
seed=42)
previousActiveColumns = [0, 1]
prevWinnerCells = [0, 1]
activeColumns = [4]
matchingSegment = tm.createSegment(4)
tm.connections.createSynapse(matchingSegment, 0, .5)
tm.compute(previousActiveColumns, True)
self.assertEqual(prevWinnerCells, tm.getWinnerCells())
tm.compute(activeColumns)
synapses = tm.connections.synapsesForSegment(matchingSegment)
self.assertEqual(2, len(synapses))
for synapse in synapses:
synapseData = tm.connections.dataForSynapse(synapse)
if synapseData.presynapticCell != 0:
self.assertAlmostEqual(.21, synapseData.permanence)
self.assertEqual(prevWinnerCells[1], synapseData.presynapticCell)
示例4: testPredictedActiveCellsAreAlwaysWinners
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testPredictedActiveCellsAreAlwaysWinners(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.5,
minThreshold=2,
maxNewSynapseCount=3,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.0,
seed=42)
previousActiveColumns = [0]
activeColumns = [1]
previousActiveCells = [0, 1, 2, 3]
expectedWinnerCells = [4, 6]
activeSegment1 = tm.createSegment(expectedWinnerCells[0])
tm.connections.createSynapse(activeSegment1, previousActiveCells[0], .5)
tm.connections.createSynapse(activeSegment1, previousActiveCells[1], .5)
tm.connections.createSynapse(activeSegment1, previousActiveCells[2], .5)
activeSegment2 = tm.createSegment(expectedWinnerCells[1])
tm.connections.createSynapse(activeSegment2, previousActiveCells[0], .5)
tm.connections.createSynapse(activeSegment2, previousActiveCells[1], .5)
tm.connections.createSynapse(activeSegment2, previousActiveCells[2], .5)
tm.compute(previousActiveColumns, False)
tm.compute(activeColumns, False)
self.assertEqual(expectedWinnerCells, tm.getWinnerCells())
示例5: testRecycleWeakestSynapseToMakeRoomForNewSynapse
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testRecycleWeakestSynapseToMakeRoomForNewSynapse(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=1,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.50,
minThreshold=1,
maxNewSynapseCount=3,
permanenceIncrement=.02,
permanenceDecrement=.02,
predictedSegmentDecrement=0.0,
seed=42,
maxSynapsesPerSegment=3)
prevActiveColumns = [0, 1, 2]
prevWinnerCells = [0, 1, 2]
activeColumns = [4]
matchingSegment = tm.connections.createSegment(4)
tm.connections.createSynapse(matchingSegment, 81, .6)
weakestSynapse = tm.connections.createSynapse(matchingSegment, 0, .11)
tm.compute(prevActiveColumns)
self.assertEqual(prevWinnerCells, tm.getWinnerCells())
tm.compute(activeColumns)
synapses = tm.connections.synapsesForSegment(matchingSegment)
self.assertEqual(3, len(synapses))
presynapticCells = set(synapse.presynapticCell for synapse in synapses)
self.assertFalse(0 in presynapticCells)
示例6: testRecycleWeakestSynapseToMakeRoomForNewSynapse
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testRecycleWeakestSynapseToMakeRoomForNewSynapse(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=1,
activationThreshold=3,
initialPermanence=.21,
connectedPermanence=.50,
minThreshold=1,
maxNewSynapseCount=3,
permanenceIncrement=.02,
permanenceDecrement=.02,
predictedSegmentDecrement=0.0,
seed=42,
maxSynapsesPerSegment=4)
prevActiveColumns = [1, 2, 3]
prevWinnerCells = [1, 2, 3]
activeColumns = [4]
matchingSegment = tm.createSegment(4)
tm.connections.createSynapse(matchingSegment, 81, .6)
# Create a weak synapse. Make sure it's not so weak that permanenceIncrement
# destroys it.
tm.connections.createSynapse(matchingSegment, 0, .11)
# Create a synapse that will match.
tm.connections.createSynapse(matchingSegment, 1, .20)
# Create a synapse with a high permanence
tm.connections.createSynapse(matchingSegment, 31, .60)
tm.compute(prevActiveColumns)
self.assertEqual(prevWinnerCells, tm.getWinnerCells())
tm.compute(activeColumns)
synapses = tm.connections.synapsesForSegment(matchingSegment)
self.assertEqual(4, len(synapses))
presynapticCells = set(synapse.presynapticCell for synapse in synapses)
self.assertEqual(set([1, 2, 3, 31]), presynapticCells)
示例7: testActiveSegmentGrowSynapsesAccordingToPotentialOverlap
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
def testActiveSegmentGrowSynapsesAccordingToPotentialOverlap(self):
"""
When a segment becomes active, grow synapses to previous winner cells.
The number of grown synapses is calculated from the "matching segment"
overlap, not the "active segment" overlap.
"""
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=1,
activationThreshold=2,
initialPermanence=.21,
connectedPermanence=.50,
minThreshold=1,
maxNewSynapseCount=4,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.0,
seed=42)
# Use 1 cell per column so that we have easy control over the winner cells.
previousActiveColumns = [0, 1, 2, 3, 4]
prevWinnerCells = [0, 1, 2, 3, 4]
activeColumns = [5]
activeSegment = tm.createSegment(5)
tm.connections.createSynapse(activeSegment, 0, .5)
tm.connections.createSynapse(activeSegment, 1, .5)
tm.connections.createSynapse(activeSegment, 2, .2)
tm.compute(previousActiveColumns, True)
self.assertEqual(prevWinnerCells, tm.getWinnerCells())
tm.compute(activeColumns, True)
presynapticCells = set(synapse.presynapticCell for synapse in
tm.connections.synapsesForSegment(activeSegment))
self.assertTrue(presynapticCells == set([0, 1, 2, 3]) or
presynapticCells == set([0, 1, 2, 4]))
示例8: range
# 需要导入模块: from nupic.algorithms.temporal_memory import TemporalMemory [as 别名]
# 或者: from nupic.algorithms.temporal_memory.TemporalMemory import getWinnerCells [as 别名]
for i in range(10):
# Send each letter in the sequence in order
for j in range(5):
activeColumns = set([i for i, j in zip(count(), x[j]) if j == 1])
# The compute method performs one step of learning and/or inference. Note:
# here we just perform learning but you can perform prediction/inference and
# learning in the same step if you want (online learning).
tm.compute(activeColumns, learn = True)
# The following print statements can be ignored.
# Useful for tracing internal states
print("active cells " + str(tm.getActiveCells()))
print("predictive cells " + str(tm.getPredictiveCells()))
print("winner cells " + str(tm.getWinnerCells()))
print("# of active segments " + str(tm.connections.numSegments()))
# The reset command tells the TM that a sequence just ended and essentially
# zeros out all the states. It is not strictly necessary but it's a bit
# messier without resets, and the TM learns quicker with resets.
tm.reset()
#######################################################################
#
# Step 3: send the same sequence of vectors and look at predictions made by
# temporal memory
for j in range(5):
print "\n\n--------","ABCDE"[j],"-----------"
print "Raw input vector : " + formatRow(x[j])