本文整理汇总了Python中nupic.encoders.scalar.ScalarEncoder.getBucketValues方法的典型用法代码示例。如果您正苦于以下问题:Python ScalarEncoder.getBucketValues方法的具体用法?Python ScalarEncoder.getBucketValues怎么用?Python ScalarEncoder.getBucketValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.scalar.ScalarEncoder
的用法示例。
在下文中一共展示了ScalarEncoder.getBucketValues方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CategoryEncoder
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import getBucketValues [as 别名]
#.........这里部分代码省略.........
if len(desc) > 0:
desc += ", "
desc += self.indexToCategory[minV]
minV += 1
# Return result
if parentFieldName != '':
fieldName = "%s.%s" % (parentFieldName, self.name)
else:
fieldName = self.name
return ({fieldName: (outRanges, desc)}, [fieldName])
def closenessScores(self, expValues, actValues, fractional=True,):
""" See the function description in base.py
kwargs will have the keyword "fractional", which is ignored by this encoder
"""
expValue = expValues[0]
actValue = actValues[0]
if expValue == actValue:
closeness = 1.0
else:
closeness = 0.0
if not fractional:
closeness = 1.0 - closeness
return numpy.array([closeness])
def getBucketValues(self):
""" See the function description in base.py """
if self._bucketValues is None:
numBuckets = len(self.encoder.getBucketValues())
self._bucketValues = []
for bucketIndex in range(numBuckets):
self._bucketValues.append(self.getBucketInfo([bucketIndex])[0].value)
return self._bucketValues
def getBucketInfo(self, buckets):
""" See the function description in base.py
"""
# For the category encoder, the bucket index is the category index
bucketInfo = self.encoder.getBucketInfo(buckets)[0]
categoryIndex = int(round(bucketInfo.value))
category = self.indexToCategory[categoryIndex]
return [EncoderResult(value=category, scalar=categoryIndex,
encoding=bucketInfo.encoding)]
def topDownCompute(self, encoded):
""" See the function description in base.py
"""
encoderResult = self.encoder.topDownCompute(encoded)[0]
value = encoderResult.value
categoryIndex = int(round(value))
示例2: initializeLSTMnet
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import getBucketValues [as 别名]
net = initializeLSTMnet(nDimInput=len(ds.getSample()[0]), nDimOutput=len(ds.getSample()[1]), nLSTMcells=20)
trainer = RPropMinusTrainer(net, dataset=ds, verbose=True)
error = []
for rpt in xrange(rptNum):
err = trainer.train()
error.append(err)
print "test LSTM"
net.reset()
targetInput = np.zeros((len(sequence),))
trueData = np.zeros((len(sequence),))
predictedInput = np.zeros((len(sequence),))
bucketValues = encoderOutput.getBucketValues()
if encoderOutput is not None:
predictedDistribution = np.zeros((len(sequence), encoderOutput.n))
targetDistribution = np.zeros((len(sequence), encoderOutput.n))
for i in xrange(len(sequence)-predictionStep):
sample = getSingleSample(i, sequence, useTimeOfDay, useDayOfWeek)
netActivation = net.activate(sample)
if encoderOutput is None:
predictedInput[i] = netActivation
else:
predictedInput[i] = bucketValues[np.where(netActivation == max(netActivation))[0][0]]
predictedDistribution[i, :] = netActivation/sum(netActivation)
targetDistribution[i, :] = encoderOutput.encode(sequence['data'][i+predictionStep])
示例3: CategoryEncoder
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import getBucketValues [as 别名]
#.........这里部分代码省略.........
"""
# Return result
if parentFieldName != '':
fieldName = "%s.%s" % (parentFieldName, self.name)
else:
fieldName = self.name
return ({fieldName: (outRanges, desc)}, [fieldName])
############################################################################
def closenessScores(self, expValues, actValues, fractional=True,):
""" See the function description in base.py
kwargs will have the keyword "fractional", which is ignored by this encoder
"""
expValue = expValues[0]
actValue = actValues[0]
if expValue == actValue:
closeness = 1.0
else:
closeness = 0.0
if not fractional:
closeness = 1.0 - closeness
return numpy.array([closeness])
############################################################################
def getBucketValues(self):
""" See the function description in base.py """
if self._bucketValues is None:
numBuckets = len(self.encoder.getBucketValues())
self._bucketValues = []
for bucketIndex in range(numBuckets):
self._bucketValues.append(self.getBucketInfo([bucketIndex])[0].value) # to_note: list of category corresponding to bucket indices
# each bucket is a number that is spaced (radius/w) each other
return self._bucketValues
############################################################################
def getBucketInfo(self, buckets):
""" See the function description in base.py
"""
# For the category encoder, the bucket index is the category index
bucketInfo = self.encoder.getBucketInfo(buckets)[0]
categoryIndex = int(round(bucketInfo.value))
category = self.indexToCategory[categoryIndex] # to_note: map the bucket index to category
return [EncoderResult(value=category, scalar=categoryIndex,
encoding=bucketInfo.encoding)]
############################################################################
def topDownCompute(self, encoded):
""" See the function description in base.py
"""
encoderResult = self.encoder.topDownCompute(encoded)[0] # to_note: return EncoderResult, which includes the value (depend on ScalarEncoder)
示例4: LogEncoder
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import getBucketValues [as 别名]
#.........这里部分代码省略.........
# Get the scalar values from the underlying scalar encoder
(fieldsDict, fieldNames) = self.encoder.decode(encoded)
if len(fieldsDict) == 0:
return (fieldsDict, fieldNames)
# Expect only 1 field
assert len(fieldsDict) == 1
# Convert each range into normal space
(inRanges, inDesc) = fieldsDict.values()[0]
outRanges = []
for (minV, maxV) in inRanges:
outRanges.append((math.pow(10, minV), math.pow(10, maxV)))
# Generate a text description of the ranges
desc = ""
numRanges = len(outRanges)
for i in xrange(numRanges):
if outRanges[i][0] != outRanges[i][1]:
desc += "%.2f-%.2f" % (outRanges[i][0], outRanges[i][1])
else:
desc += "%.2f" % (outRanges[i][0])
if i < numRanges - 1:
desc += ", "
# Return result
if parentFieldName != "":
fieldName = "%s.%s" % (parentFieldName, self.name)
else:
fieldName = self.name
return ({fieldName: (outRanges, desc)}, [fieldName])
############################################################################
def getBucketValues(self):
"""
See the function description in base.py
"""
# Need to re-create?
if self._bucketValues is None:
scaledValues = self.encoder.getBucketValues()
self._bucketValues = []
for scaledValue in scaledValues:
value = math.pow(10, scaledValue)
self._bucketValues.append(value)
return self._bucketValues
############################################################################
def getBucketInfo(self, buckets):
"""
See the function description in base.py
"""
scaledResult = self.encoder.getBucketInfo(buckets)[0]
scaledValue = scaledResult.value
value = math.pow(10, scaledValue)
return [EncoderResult(value=value, scalar=value, encoding=scaledResult.encoding)]
############################################################################
def topDownCompute(self, encoded):
"""
See the function description in base.py
"""
示例5: LogEncoder
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import getBucketValues [as 别名]
#.........这里部分代码省略.........
(fieldsDict, fieldNames) = self.encoder.decode(encoded)
if len(fieldsDict) == 0:
return (fieldsDict, fieldNames)
# Expect only 1 field
assert(len(fieldsDict) == 1)
# Convert each range into normal space
(inRanges, inDesc) = fieldsDict.values()[0]
outRanges = []
for (minV, maxV) in inRanges:
outRanges.append((math.pow(10, minV),
math.pow(10, maxV)))
# Generate a text description of the ranges
desc = ""
numRanges = len(outRanges)
for i in xrange(numRanges):
if outRanges[i][0] != outRanges[i][1]:
desc += "%.2f-%.2f" % (outRanges[i][0], outRanges[i][1])
else:
desc += "%.2f" % (outRanges[i][0])
if i < numRanges-1:
desc += ", "
# Return result
if parentFieldName != '':
fieldName = "%s.%s" % (parentFieldName, self.name)
else:
fieldName = self.name
return ({fieldName: (outRanges, desc)}, [fieldName])
def getBucketValues(self):
"""
See the function description in base.py
"""
# Need to re-create?
if self._bucketValues is None:
scaledValues = self.encoder.getBucketValues()
self._bucketValues = []
for scaledValue in scaledValues:
value = math.pow(10, scaledValue)
self._bucketValues.append(value)
return self._bucketValues
def getBucketInfo(self, buckets):
"""
See the function description in base.py
"""
scaledResult = self.encoder.getBucketInfo(buckets)[0]
scaledValue = scaledResult.value
value = math.pow(10, scaledValue)
return [EncoderResult(value=value, scalar=value,
encoding = scaledResult.encoding)]
def topDownCompute(self, encoded):
"""
See the function description in base.py
"""