本文整理汇总了Python中nupic.algorithms.temporal_memory.TemporalMemory类的典型用法代码示例。如果您正苦于以下问题:Python TemporalMemory类的具体用法?Python TemporalMemory怎么用?Python TemporalMemory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TemporalMemory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWriteRead
def testWriteRead(self):
tm1 = TemporalMemory(
columnDimensions=(32,),
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=0.21,
connectedPermanence=0.50,
minThreshold=2,
maxNewSynapseCount=3,
permanenceIncrement=0.1,
permanenceDecrement=0.1,
predictedSegmentDecrement=0.0,
seed=42
)
self.serializationTestPrepare(tm1)
proto1 = TemporalMemoryProto_capnp.TemporalMemoryProto.new_message()
tm1.write(proto1)
# Write the proto to a temp file and read it back into a new proto
with tempfile.TemporaryFile() as f:
proto1.write(f)
f.seek(0)
proto2 = TemporalMemoryProto_capnp.TemporalMemoryProto.read(f)
# Load the deserialized proto
tm2 = TemporalMemory.read(proto2)
self.assertEqual(tm1, tm2)
self.serializationTestVerify(tm2)
示例2: testMaxSegmentsPerCellGetter
def testMaxSegmentsPerCellGetter(self):
tm = TemporalMemory(
columnDimensions=[64,64],
cellsPerColumn=32,
maxSegmentsPerCell=200
)
self.assertEqual(tm.getMaxSegmentsPerCell(), 200)
示例3: testMaxSynapsesPerSegmentGetter
def testMaxSynapsesPerSegmentGetter(self):
tm = TemporalMemory(
columnDimensions=[32,32],
cellsPerColumn=16,
maxSynapsesPerSegment=150
)
self.assertEqual(tm.getMaxSynapsesPerSegment(), 150)
示例4: testCellsForColumn1D
def testCellsForColumn1D(self):
tm = TemporalMemory(
columnDimensions=[2048],
cellsPerColumn=5
)
expectedCells = [5, 6, 7, 8, 9]
self.assertEqual(tm.cellsForColumn(1), expectedCells)
示例5: testCellsForColumn2D
def testCellsForColumn2D(self):
tm = TemporalMemory(
columnDimensions=[64, 64],
cellsPerColumn=4
)
expectedCells = [256, 257, 258, 259]
self.assertEqual(tm.cellsForColumn(64), expectedCells)
示例6: testDestroySegmentsWithTooFewSynapsesToBeMatching
def testDestroySegmentsWithTooFewSynapsesToBeMatching(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.2,
connectedPermanence=.50,
minThreshold=2,
maxNewSynapseCount=4,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.02,
seed=42)
prevActiveColumns = [0]
prevActiveCells = [0, 1, 2, 3]
activeColumns = [2]
expectedActiveCell = 5
matchingSegment = tm.connections.createSegment(expectedActiveCell)
tm.connections.createSynapse(matchingSegment, prevActiveCells[0], .015)
tm.connections.createSynapse(matchingSegment, prevActiveCells[1], .015)
tm.connections.createSynapse(matchingSegment, prevActiveCells[2], .015)
tm.connections.createSynapse(matchingSegment, prevActiveCells[3], .015)
tm.compute(prevActiveColumns, True)
tm.compute(activeColumns, True)
self.assertEqual(0, tm.connections.numSegments(expectedActiveCell))
示例7: testDestroyWeakSynapseOnActiveReinforce
def testDestroyWeakSynapseOnActiveReinforce(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.2,
connectedPermanence=.50,
minThreshold=2,
maxNewSynapseCount=4,
permanenceIncrement=.10,
permanenceDecrement=.10,
predictedSegmentDecrement=0.02,
seed=42)
previousActiveColumns = [0]
previousActiveCells = [0, 1, 2, 3]
activeColumns = [2]
activeCell = 5
activeSegment = tm.connections.createSegment(activeCell)
tm.connections.createSynapse(activeSegment, previousActiveCells[0], .5)
tm.connections.createSynapse(activeSegment, previousActiveCells[1], .5)
tm.connections.createSynapse(activeSegment, previousActiveCells[2], .5)
# Weak inactive synapse.
tm.connections.createSynapse(activeSegment, previousActiveCells[3], .009)
tm.compute(previousActiveColumns, True)
tm.compute(activeColumns, True)
self.assertEqual(3, tm.connections.numSynapses(activeSegment))
示例8: testReinforceCorrectlyActiveSegments
def testReinforceCorrectlyActiveSegments(self):
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=4,
activationThreshold=3,
initialPermanence=.2,
connectedPermanence=.50,
minThreshold=2,
maxNewSynapseCount=4,
permanenceIncrement=.10,
permanenceDecrement=.08,
predictedSegmentDecrement=0.02,
seed=42)
prevActiveColumns = [0]
prevActiveCells = [0,1,2,3]
activeColumns = [1]
activeCell = 5
activeSegment = tm.connections.createSegment(activeCell)
as1 = tm.connections.createSynapse(activeSegment, prevActiveCells[0], .5)
as2 = tm.connections.createSynapse(activeSegment, prevActiveCells[1], .5)
as3 = tm.connections.createSynapse(activeSegment, prevActiveCells[2], .5)
is1 = tm.connections.createSynapse(activeSegment, 81, .5) #inactive synapse
tm.compute(prevActiveColumns, True)
tm.compute(activeColumns, True)
self.assertAlmostEqual(.6, tm.connections.dataForSynapse(as1).permanence)
self.assertAlmostEqual(.6, tm.connections.dataForSynapse(as2).permanence)
self.assertAlmostEqual(.6, tm.connections.dataForSynapse(as3).permanence)
self.assertAlmostEqual(.42, tm.connections.dataForSynapse(is1).permanence)
示例9: testMapCellsToColumns
def testMapCellsToColumns(self):
tm = TemporalMemory(
columnDimensions=[100],
cellsPerColumn=4
)
columnsForCells = tm.mapCellsToColumns(set([0, 1, 2, 5, 399]))
self.assertEqual(columnsForCells[0], set([0, 1, 2]))
self.assertEqual(columnsForCells[1], set([5]))
self.assertEqual(columnsForCells[99], set([399]))
示例10: testColumnForCell1D
def testColumnForCell1D(self):
tm = TemporalMemory(
columnDimensions=[2048],
cellsPerColumn=5
)
self.assertEqual(tm.columnForCell(0), 0)
self.assertEqual(tm.columnForCell(4), 0)
self.assertEqual(tm.columnForCell(5), 1)
self.assertEqual(tm.columnForCell(10239), 2047)
示例11: testColumnForCell2D
def testColumnForCell2D(self):
tm = TemporalMemory(
columnDimensions=[64, 64],
cellsPerColumn=4
)
self.assertEqual(tm.columnForCell(0), 0)
self.assertEqual(tm.columnForCell(3), 0)
self.assertEqual(tm.columnForCell(4), 1)
self.assertEqual(tm.columnForCell(16383), 4095)
示例12: testReachSegmentLimitMultipleTimes
def testReachSegmentLimitMultipleTimes(self):
""" Hit the maxSegmentsPerCell threshold multiple times. Make sure it
works more than once.
"""
tm = TemporalMemory(
columnDimensions=[32],
cellsPerColumn=1,
activationThreshold=3,
initialPermanence=.50,
connectedPermanence=.50,
minThreshold=2,
maxNewSynapseCount=3,
permanenceIncrement=.02,
permanenceDecrement=.02,
predictedSegmentDecrement=0.0,
seed=42,
maxSegmentsPerCell=2)
tm.createSegment(10)
self.assertEqual(1, tm.connections.numSegments())
tm.createSegment(10)
self.assertEqual(2, tm.connections.numSegments())
tm.createSegment(10)
self.assertEqual(2, tm.connections.numSegments())
tm.createSegment(10)
self.assertEqual(2, tm.connections.numSegments())
示例13: testActivateCorrectlyPredictiveCells
def testActivateCorrectlyPredictiveCells(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]
expectedActiveCells = [4]
activeSegment = tm.createSegment(expectedActiveCells[0])
tm.connections.createSynapse(activeSegment, previousActiveCells[0], .5)
tm.connections.createSynapse(activeSegment, previousActiveCells[1], .5)
tm.connections.createSynapse(activeSegment, previousActiveCells[2], .5)
tm.connections.createSynapse(activeSegment, previousActiveCells[3], .5)
tm.compute(previousActiveColumns, True)
self.assertEqual(expectedActiveCells, tm.getPredictiveCells())
tm.compute(activeColumns, True)
self.assertEqual(expectedActiveCells, tm.getActiveCells())
示例14: testCellsForColumnInvalidColumn
def testCellsForColumnInvalidColumn(self):
tm = TemporalMemory(
columnDimensions=[64, 64],
cellsPerColumn=4
)
try:
tm.cellsForColumn(4095)
except IndexError:
self.fail("IndexError raised unexpectedly")
args = [4096]
self.assertRaises(IndexError, tm.cellsForColumn, *args)
args = [-1]
self.assertRaises(IndexError, tm.cellsForColumn, *args)
示例15: testColumnForCellInvalidCell
def testColumnForCellInvalidCell(self):
tm = TemporalMemory(
columnDimensions=[64, 64],
cellsPerColumn=4
)
try:
tm.columnForCell(16383)
except IndexError:
self.fail("IndexError raised unexpectedly")
args = [16384]
self.assertRaises(IndexError, tm.columnForCell, *args)
args = [-1]
self.assertRaises(IndexError, tm.columnForCell, *args)