當前位置: 首頁>>代碼示例>>Python>>正文


Python TP.compute方法代碼示例

本文整理匯總了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))
開發者ID:AndreCAndersen,項目名稱:nupic,代碼行數:36,代碼來源:tp_test.py

示例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)
開發者ID:AndreCAndersen,項目名稱:nupic,代碼行數:55,代碼來源:tp_test.py

示例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)
開發者ID:,項目名稱:,代碼行數:56,代碼來源:

示例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))
開發者ID:plexzhang,項目名稱:nupic-1,代碼行數:92,代碼來源:tp_test.py

示例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])
開發者ID:jeffk,項目名稱:pytexas-nupic,代碼行數:32,代碼來源:volume.py

示例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)):
開發者ID:cchio,項目名稱:nupic-fall2014-music-composer-fingerprinting,代碼行數:32,代碼來源:composer_finder_temp.py


注:本文中的nupic.research.TP.TP.compute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。