本文整理汇总了Python中nupic.research.TP.TP.compute方法的典型用法代码示例。如果您正苦于以下问题:Python TP.compute方法的具体用法?Python TP.compute怎么用?Python TP.compute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.research.TP.TP
的用法示例。
在下文中一共展示了TP.compute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCheckpointMiddleOfSequence
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [as 别名]
def testCheckpointMiddleOfSequence(self):
# Create a model and give it some inputs to learn.
tp1 = TP(numberOfCols=100, cellsPerColumn=12, verbosity=VERBOSITY)
sequences = [self.generateSequence() for _ in xrange(5)]
train = list(itertools.chain.from_iterable(sequences[:3] +
[sequences[3][:5]]))
for bottomUpInput in train:
if bottomUpInput is None:
tp1.reset()
else:
tp1.compute(bottomUpInput, True, True)
# Serialize and deserialized the TP.
checkpointPath = os.path.join(self._tmpDir, 'a')
tp1.saveToFile(checkpointPath)
tp2 = pickle.loads(pickle.dumps(tp1))
tp2.loadFromFile(checkpointPath)
# Check that the TPs are the same.
self.assertTPsEqual(tp1, tp2)
# Feed some data into the models.
test = list(itertools.chain.from_iterable([sequences[3][5:]] +
sequences[3:]))
for bottomUpInput in test:
if bottomUpInput is None:
tp1.reset()
tp2.reset()
else:
result1 = tp1.compute(bottomUpInput, True, True)
result2 = tp2.compute(bottomUpInput, True, True)
self.assertTPsEqual(tp1, tp2)
self.assertTrue(numpy.array_equal(result1, result2))
示例2: testCheckpointMiddleOfSequence2
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [as 别名]
def testCheckpointMiddleOfSequence2(self):
"""More complex test of checkpointing in the middle of a sequence."""
tp1 = TP(2048, 32, 0.21, 0.5, 11, 20, 0.1, 0.1, 1.0, 0.0, 14, False, 5, 2,
False, 1960, 0, False, '', 3, 10, 5, 0, 32, 128, 32, 'normal')
tp2 = TP(2048, 32, 0.21, 0.5, 11, 20, 0.1, 0.1, 1.0, 0.0, 14, False, 5, 2,
False, 1960, 0, False, '', 3, 10, 5, 0, 32, 128, 32, 'normal')
with resource_stream(__name__, 'data/tp_input.csv') as fin:
reader = csv.reader(fin)
records = []
for bottomUpInStr in fin:
bottomUpIn = numpy.array(eval('[' + bottomUpInStr.strip() + ']'),
dtype='int32')
records.append(bottomUpIn)
i = 1
for r in records[:250]:
print i
i += 1
output1 = tp1.compute(r, True, True)
output2 = tp2.compute(r, True, True)
self.assertTrue(numpy.array_equal(output1, output2))
print 'Serializing and deserializing models.'
savePath1 = os.path.join(self._tmpDir, 'tp1.bin')
tp1.saveToFile(savePath1)
tp3 = pickle.loads(pickle.dumps(tp1))
tp3.loadFromFile(savePath1)
savePath2 = os.path.join(self._tmpDir, 'tp2.bin')
tp2.saveToFile(savePath2)
tp4 = pickle.loads(pickle.dumps(tp2))
tp4.loadFromFile(savePath2)
self.assertTPsEqual(tp1, tp3)
self.assertTPsEqual(tp2, tp4)
for r in records[250:]:
print i
i += 1
out1 = tp1.compute(r, True, True)
out2 = tp2.compute(r, True, True)
out3 = tp3.compute(r, True, True)
out4 = tp4.compute(r, True, True)
self.assertTrue(numpy.array_equal(out1, out2))
self.assertTrue(numpy.array_equal(out1, out3))
self.assertTrue(numpy.array_equal(out1, out4))
self.assertTPsEqual(tp1, tp2)
self.assertTPsEqual(tp1, tp3)
self.assertTPsEqual(tp2, tp4)
示例3: main
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [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)
示例4: testCheckpointMiddleOfSequence2
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [as 别名]
def testCheckpointMiddleOfSequence2(self):
"""More complex test of checkpointing in the middle of a sequence."""
tp1 = TP(
2048,
32,
0.21,
0.5,
11,
20,
0.1,
0.1,
1.0,
0.0,
14,
False,
5,
2,
False,
1960,
0,
False,
"",
3,
10,
5,
0,
32,
128,
32,
"normal",
)
tp2 = TP(
2048,
32,
0.21,
0.5,
11,
20,
0.1,
0.1,
1.0,
0.0,
14,
False,
5,
2,
False,
1960,
0,
False,
"",
3,
10,
5,
0,
32,
128,
32,
"normal",
)
with resource_stream(__name__, "data/tp_input.csv") as fin:
reader = csv.reader(fin)
records = []
for bottomUpInStr in fin:
bottomUpIn = numpy.array(eval("[" + bottomUpInStr.strip() + "]"), dtype="int32")
records.append(bottomUpIn)
for r in records[:250]:
output1 = tp1.compute(r, True, True)
output2 = tp2.compute(r, True, True)
self.assertTrue(numpy.array_equal(output1, output2))
tp3 = pickle.loads(pickle.dumps(tp1))
tp4 = pickle.loads(pickle.dumps(tp2))
i = 0
for r in records[250:]:
print i
i += 1
out1 = tp1.compute(r, True, True)
out2 = tp2.compute(r, True, True)
out3 = tp3.compute(r, True, True)
out4 = tp4.compute(r, True, True)
self.assertTPsEqual(tp1, tp2)
self.assertTrue(numpy.array_equal(out1, out2))
self.assertTrue(numpy.array_equal(out1, out3))
self.assertTrue(numpy.array_equal(out1, out4))
示例5: int
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [as 别名]
stream.start_stream()
data = stream.read(1024*5)
stream.stop_stream()
# Turn our sample into a decibel measurement.
rms = audioop.rms(data,2)
decibel = int(20 * math.log10(rms))
# Turn our decibel number into a sparse distributed representation.
encoded = enc.encode(decibel)
# Add our encoded representation to the temporal pooler.
tp.compute(encoded, enableLearn = True, computeInfOutput = True)
# For the curious:
#tp.printCells()
#tp.printStates(printPrevious=False, printLearnState=False)
predictedCells = tp.getPredictedState()
decval = 0
if predictedCells.any():
decval = predictedCells.max(axis=1).nonzero()[0][-1]
# This is more correct, but seems wonky...
#decval = int(enc.decode(predictedCells.max(axis=1).
#nonzero()[0])[0]["[0:100]"][0][0][1])
示例6: TP
# 需要导入模块: from nupic.research.TP import TP [as 别名]
# 或者: from nupic.research.TP.TP import compute [as 别名]
tp = TP(numberOfCols=50, cellsPerColumn=2,
initialPerm=0.5, connectedPerm=0.5,
minThreshold=10, newSynapseCount=10,
permanenceInc=0.1, permanenceDec=0.0,
activationThreshold=8,
globalDecay=0, burnIn=1,
checkSynapseConsistency=False,
pamLength=10)
# In[22]:
for i in range(1):
for note in encoded_list:
tp.compute(note, enableLearn = True, computeInfOutput = False)
# This function prints the segments associated with every cell.$$$$
# If you really want to understand the TP, uncomment this line. By following
# every step you can get an excellent understanding for exactly how the TP
# learns.
# tp.printCells()
tp.reset()
print 'FINISHED TEMPORAL POOLING'
# In[ ]:
def formatRow(x):
s = ''
for c in range(len(x)):