![](/img/trans.png)
[英]Using MultiEncoder, I have an array encoders[] and I want to be able to tell, what data-type does the encoder accept. How is that possible?
[英]Trouble setting up the SimpleVector encoder
將breznak的提交用於編碼器 (我無法通過GitHub找出“ git checkout ...”,因此我只是仔細復制了三個文件-base.py,multi.py和multi_test.py) 。
我運行multi_test.py沒有任何問題。
然后,我調整了模型參數(MODEL_PARAMS),以使'sensorParams'的編碼器部分如下所示:
'encoders': {
'frequency': {
'fieldname': u'frequency',
'type': 'SimpleVector',
'length': 5,
'minVal': 0,
'maxVal': 210
}
},
我還調整了代碼的modelInput部分,因此如下所示:
model = ModelFactory.create(model_params.MODEL_PARAMS)
model.enableInference({'predictedField': 'frequency'})
y = [1,2,3,4,5]
modelInput = {"frequency": y}
result = model.run(modelInput)
但是無論我將“ y”實例化為列表還是numpy.ndarray,我都會遇到最終錯誤。
File "nta/eng/lib/python2.7/site-packages/nupic/encoders/base.py", line 183, in _getInputValue
return getattr(obj, fieldname)
AttributeError: 'list' object has no attribute 'idx0'
我還嘗試使用modelInput內聯初始化SimpleVector編碼器,直接對數組進行編碼,然后將其傳遞給modelInput。 因為我現在是雙重編碼,所以這違反了我的SimpleVector的輸入參數。 因此,我刪除了模型參數字典中的編碼器部分。 因為我模型的某些部分正在尋找字典的那部分,所以這引起了口吐聲。
關於下一步我應該做什么?
編輯:這是我與OPF一起使用的文件。
sendAnArray.py
import numpy
from nupic.frameworks.opf.modelfactory import ModelFactory
import model_params
class sendAnArray():
def __init__(self):
self.model = ModelFactory.create(model_params.MODEL_PARAMS)
self.model.enableInference({'predictedField': 'frequency'})
for i in range(100):
self.run()
def run(self):
y = [1,2,3,4,5]
modelInput = {"frequency": y}
result = self.model.run(modelInput)
anomalyScore = result.inferences['anomalyScore']
print y, anomalyScore
sAA = sendAnArray()
model_params.py
MODEL_PARAMS = {
'model': "CLA",
'version': 1,
'predictAheadTime': None,
'modelParams': {
'inferenceType': 'TemporalAnomaly',
'sensorParams': {
'verbosity' : 0,
'encoders': {
'frequency': {
'fieldname': u'frequency',
'type': 'SimpleVector',
'length': 5,
'minVal': 0,
'maxVal': 210
}
},
'sensorAutoReset' : None,
},
'spEnable': True,
'spParams': {
'spVerbosity' : 0,
'globalInhibition': 1,
'columnCount': 2048,
'inputWidth': 5,
'numActivePerInhArea': 60,
'seed': 1956,
'coincInputPoolPct': 0.5,
'synPermConnected': 0.1,
'synPermActiveInc': 0.1,
'synPermInactiveDec': 0.01,
},
'tpEnable' : True,
'tpParams': {
'verbosity': 0,
'columnCount': 2048,
'cellsPerColumn': 32,
'inputWidth': 2048,
'seed': 1960,
'temporalImp': 'cpp',
'newSynapseCount': 20,
'maxSynapsesPerSegment': 32,
'maxSegmentsPerCell': 128,
'initialPerm': 0.21,
'permanenceInc': 0.1,
'permanenceDec' : 0.1,
'globalDecay': 0.0,
'maxAge': 0,
'minThreshold': 12,
'activationThreshold': 16,
'outputType': 'normal',
'pamLength': 1,
},
'clParams': {
'regionName' : 'CLAClassifierRegion',
'clVerbosity' : 0,
'alpha': 0.0001,
'steps': '5',
},
'anomalyParams': {
u'anomalyCacheRecords': None,
u'autoDetectThreshold': None,
u'autoDetectWaitRecords': 2184
},
'trainSPNetOnlyIfRequested': False,
},
}
問題似乎是SimpleVector類正在接受數組而不是字典作為輸入,然后在內部將其重建為{'list': {'idx0': 1, 'idx1': 2, ...}}
(即好像該字典是輸入內容)。 如果始終如一,這樣做很好,但是您的錯誤表明它已在某處損壞。 與@breznak談一談。
通過OPF很難。 我想將一個索引數組輸入到時間池中,所以我選擇直接與算法接口(我非常依賴hello_tp.py )。 我一起忽略了SimpleVector,而是通過BitmapArray編碼器工作。
Subutai 在nupic-discuss listserve上有一封有用的電子郵件 ,其中他細分了NuPIC API的三個主要方面:算法,網絡/區域和OPF。 這有助於我更好地了解自己的選擇。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.