本文整理汇总了Python中nupic.research.TP.TP.printStates方法的典型用法代码示例。如果您正苦于以下问题:Python TP.printStates方法的具体用法?Python TP.printStates怎么用?Python TP.printStates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.TP.TP
的用法示例。
在下文中一共展示了TP.printStates方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import printStates [as 别名]
def main(SEED, VERBOSITY):
# TP 作成
tp = TP(
numberOfCols = 100,
cellsPerColumn = 1,
initialPerm = 0.3,
connectedPerm = 0.5,
minThreshold = 4,
newSynapseCount = 7,
permanenceInc = 0.1,
permanenceDec = 0.05,
activationThreshold = 5,
globalDecay = 0,
burnIn = 1,
seed = SEED,
verbosity = VERBOSITY,
checkSynapseConsistency = True,
pamLength = 1000
)
print
trainingSet = _getSimplePatterns(10, 10)
for seq in trainingSet[0:5]:
_printOneTrainingVector(seq)
# TP学習
print
print 'Learning 1 ... A->A->A'
for _ in range(2):
for seq in trainingSet[0:5]:
for _ in range(10):
#tp.learn(seq)
tp.compute(seq, enableLearn = True, computeInfOutput=False)
tp.reset()
print
print 'Learning 2 ... A->B->C'
for _ in range(10):
for seq in trainingSet[0:5]:
tp.compute(seq, enableLearn = True, computeInfOutput=False)
tp.reset()
# TP 予測
# Learning 1のみだと, A->Aを出力するのみだが,
# その後, Learning 2もやると, A->A,Bを出力するようになる.
print
print 'Running inference'
for seq in trainingSet[0:5]:
# tp.reset()
# tp.resetStats()
tp.compute(seq, enableLearn = False, computeInfOutput = True)
tp.printStates(False, False)
示例2: basicTest2
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import printStates [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
#.........这里部分代码省略.........
示例3: formatRow
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import printStates [as 别名]
for note in encoded_list:
print "Raw input vector\n", formatRow(note)
# Send each vector to the TP, with learning turned off
tp.compute(note, enableLearn=False, computeInfOutput=True)
# This method prints out the active state of each cell followed by the
# predicted state of each cell. For convenience the cells are grouped
# 10 at a time. When there are multiple cells per column the printout
# is arranged so the cells in a column are stacked together
#
# What you should notice is that the columns where active state is 1
# represent the SDR for the current input pattern and the columns where
# predicted state is 1 represent the SDR for the next expected pattern
print "\nAll the active and predicted cells:"
tp.printStates(printPrevious=False, printLearnState=False)
# tp.getPredictedState() gets the predicted cells.
# predictedCells[c][i] represents the state of the i'th cell in the c'th
# column. To see if a column is predicted, we can simply take the OR
# across all the cells in that column. In numpy we can do this by taking
# the max along axis 1.
print "\n\nThe following columns are predicted by the temporal pooler. This"
print "should correspond to columns in the *next* item in the sequence."
predictedCells = tp.getPredictedState()
print formatRow(predictedCells.max(axis=1).nonzero())
# In[ ]: