本文整理汇总了Python中nupic.encoders.MultiEncoder.decode方法的典型用法代码示例。如果您正苦于以下问题:Python MultiEncoder.decode方法的具体用法?Python MultiEncoder.decode怎么用?Python MultiEncoder.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.MultiEncoder
的用法示例。
在下文中一共展示了MultiEncoder.decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Sensor
# 需要导入模块: from nupic.encoders import MultiEncoder [as 别名]
# 或者: from nupic.encoders.MultiEncoder import decode [as 别名]
#.........这里部分代码省略.........
# Update sensor bits
for i in range(len(outputArray)):
if outputArray[i] > 0.:
self.bits[i].isActive.setForCurrStep(True)
else:
self.bits[i].isActive.setForCurrStep(False)
# Mark falsely predicted bits
for bit in self.bits:
if bit.isPredicted.atPreviousStep() and not bit.isActive.atCurrStep():
bit.isFalselyPredicted.setForCurrStep(True)
self._output = outputArray
def getPredictions(self):
"""
Get the predictions after an iteration.
"""
if self.predictionsMethod == PredictionsMethod.reconstruction:
# Prepare list with predictions to be classified
# This list contains the indexes of all bits that are predicted
output = []
for i in range(len(self.bits)):
if self.bits[i].isPredicted.atCurrStep():
output.append(1)
else:
output.append(0)
output = numpy.array(output)
# Decode output and create predictions list
fieldsDict, fieldsOrder = self.encoder.decode(output)
for encoding in self.encodings:
if encoding.enableInference:
predictions = []
encoding.predictedValues.setForCurrStep(dict())
# If encoder field name was returned by decode(), assign the the predictions to it
if encoding.encoderFieldName in fieldsOrder:
predictedLabels = fieldsDict[encoding.encoderFieldName][1].split(', ')
predictedValues = fieldsDict[encoding.encoderFieldName][0]
for i in range(len(predictedLabels)):
predictions.append([predictedValues[i], predictedLabels[i]])
encoding.predictedValues.atCurrStep()[1] = predictions
# Get the predicted value with the biggest probability to happen
if len(predictions) > 0:
bestPredictionRange = predictions[0][0]
min = bestPredictionRange[0]
max = bestPredictionRange[1]
bestPredictedValue = (min + max) / 2.0
encoding.bestPredictedValue.setForCurrStep(bestPredictedValue)
elif self.predictionsMethod == PredictionsMethod.classification:
# A classification involves estimate which are the likely values to occurs in the next time step.
offset = 0
for encoding in self.encodings:
encoderWidth = encoding.encoder.getWidth()
if encoding.enableInference:
# Prepare list with predictions to be classified
# This list contains the indexes of all bits that are predicted