本文整理汇总了Python中nupic.research.TP.TP.learn方法的典型用法代码示例。如果您正苦于以下问题:Python TP.learn方法的具体用法?Python TP.learn怎么用?Python TP.learn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.TP.TP
的用法示例。
在下文中一共展示了TP.learn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: basicTest2
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import learn [as 别名]
def basicTest2(self, tp, numPatterns=100, numRepetitions=3, activity=15,
testTrimming=False, testRebuild=False):
"""Basic test (basic run of learning and inference)"""
# Create PY TP object that mirrors the one sent in.
tpPy = TP(numberOfCols=tp.numberOfCols, cellsPerColumn=tp.cellsPerColumn,
initialPerm=tp.initialPerm, connectedPerm=tp.connectedPerm,
minThreshold=tp.minThreshold, newSynapseCount=tp.newSynapseCount,
permanenceInc=tp.permanenceInc, permanenceDec=tp.permanenceDec,
permanenceMax=tp.permanenceMax, globalDecay=tp.globalDecay,
activationThreshold=tp.activationThreshold,
doPooling=tp.doPooling,
segUpdateValidDuration=tp.segUpdateValidDuration,
pamLength=tp.pamLength, maxAge=tp.maxAge,
maxSeqLength=tp.maxSeqLength,
maxSegmentsPerCell=tp.maxSegmentsPerCell,
maxSynapsesPerSegment=tp.maxSynapsesPerSegment,
seed=tp.seed, verbosity=tp.verbosity)
# Ensure we are copying over learning states for TPDiff
tp.retrieveLearningStates = True
verbosity = VERBOSITY
# Learn
# Build up sequences
sequence = fdrutils.generateCoincMatrix(nCoinc=numPatterns,
length=tp.numberOfCols,
activity=activity)
for r in xrange(numRepetitions):
for i in xrange(sequence.nRows()):
#if i > 11:
# setVerbosity(6, tp, tpPy)
if i % 10 == 0:
tp.reset()
tpPy.reset()
if verbosity >= 2:
print "\n\n ===================================\nPattern:",
print i, "Round:", r, "input:", sequence.getRow(i)
y1 = tp.learn(sequence.getRow(i))
y2 = tpPy.learn(sequence.getRow(i))
# Ensure everything continues to work well even if we continuously
# rebuild outSynapses structure
if testRebuild:
tp.cells4.rebuildOutSynapses()
if testTrimming:
tp.trimSegments()
tpPy.trimSegments()
if verbosity > 2:
print "\n ------ CPP states ------ ",
tp.printStates()
print "\n ------ PY states ------ ",
tpPy.printStates()
if verbosity > 6:
print "C++ cells: "
tp.printCells()
print "PY cells: "
tpPy.printCells()
if verbosity >= 3:
print "Num segments in PY and C++", tpPy.getNumSegments(), \
tp.getNumSegments()
# Check if the two TP's are identical or not. This check is slow so
# we do it every other iteration. Make it every iteration for debugging
# as needed.
self.assertTrue(fdrutils.tpDiff2(tp, tpPy, verbosity, False))
# Check that outputs are identical
self.assertLess(abs((y1 - y2).sum()), 3)
print "Learning completed"
self.assertTrue(fdrutils.tpDiff2(tp, tpPy, verbosity))
# TODO: Need to check - currently failing this
#checkCell0(tpPy)
# Remove unconnected synapses and check TP's again
# Test rebuild out synapses
print "Rebuilding outSynapses"
tp.cells4.rebuildOutSynapses()
self.assertTrue(fdrutils.tpDiff2(tp, tpPy, VERBOSITY))
print "Trimming segments"
tp.trimSegments()
tpPy.trimSegments()
self.assertTrue(fdrutils.tpDiff2(tp, tpPy, VERBOSITY))
# Save and reload after learning
print "Pickling and unpickling"
tp.makeCells4Ephemeral = False
#.........这里部分代码省略.........