本文整理汇总了Python中nupic.utils.MovingAverage.write方法的典型用法代码示例。如果您正苦于以下问题:Python MovingAverage.write方法的具体用法?Python MovingAverage.write怎么用?Python MovingAverage.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.utils.MovingAverage
的用法示例。
在下文中一共展示了MovingAverage.write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMovingAverageReadWrite
# 需要导入模块: from nupic.utils import MovingAverage [as 别名]
# 或者: from nupic.utils.MovingAverage import write [as 别名]
def testMovingAverageReadWrite(self):
ma = MovingAverage(windowSize=3)
ma.next(3)
ma.next(4)
ma.next(5)
proto1 = MovingAverageProto.new_message()
ma.write(proto1)
# Write the proto to a temp file and read it back into a new proto
with tempfile.TemporaryFile() as f:
proto1.write(f)
f.seek(0)
proto2 = MovingAverageProto.read(f)
resurrectedMa = MovingAverage.read(proto2)
newAverage = ma.next(6)
self.assertEqual(newAverage, resurrectedMa.next(6))
self.assertListEqual(ma.getSlidingWindow(),
resurrectedMa.getSlidingWindow())
self.assertEqual(ma.total, resurrectedMa.total)
示例2: AdaptiveScalarEncoder
# 需要导入模块: from nupic.utils import MovingAverage [as 别名]
# 或者: from nupic.utils.MovingAverage import write [as 别名]
#.........这里部分代码省略.........
#initialBump = abs(self.minval-minOverWindow)*(1-(min(self.recordNum, 200.0)/200.0))*2 #decrement minval more aggressively in the beginning
if self.verbosity >= 2:
print "Input {0!s}={1:.2f} smaller than minval {2:.2f}. Adjusting minval to {3:.2f}".format(self.name, input, self.minval, minOverWindow)
self.minval = minOverWindow #-initialBump
self._setEncoderParams()
if maxOverWindow > self.maxval:
#initialBump = abs(self.maxval-maxOverWindow)*(1-(min(self.recordNum, 200.0)/200.0))*2 #decrement maxval more aggressively in the beginning
if self.verbosity >= 2:
print "Input {0!s}={1:.2f} greater than maxval {2:.2f}. Adjusting maxval to {3:.2f}".format(self.name, input, self.maxval, maxOverWindow)
self.maxval = maxOverWindow #+initialBump
self._setEncoderParams()
def getBucketIndices(self, input, learn=None):
"""
[overrides nupic.encoders.scalar.ScalarEncoder.getBucketIndices]
"""
self.recordNum +=1
if learn is None:
learn = self._learningEnabled
if type(input) is float and math.isnan(input):
input = SENTINEL_VALUE_FOR_MISSING_DATA
if input == SENTINEL_VALUE_FOR_MISSING_DATA:
return [None]
else:
self._setMinAndMax(input, learn)
return super(AdaptiveScalarEncoder, self).getBucketIndices(input)
def encodeIntoArray(self, input, output,learn=None):
"""
[overrides nupic.encoders.scalar.ScalarEncoder.encodeIntoArray]
"""
self.recordNum +=1
if learn is None:
learn = self._learningEnabled
if input == SENTINEL_VALUE_FOR_MISSING_DATA:
output[0:self.n] = 0
elif not math.isnan(input):
self._setMinAndMax(input, learn)
super(AdaptiveScalarEncoder, self).encodeIntoArray(input, output)
def getBucketInfo(self, buckets):
"""
[overrides nupic.encoders.scalar.ScalarEncoder.getBucketInfo]
"""
if self.minval is None or self.maxval is None:
return [EncoderResult(value=0, scalar=0,
encoding=numpy.zeros(self.n))]
return super(AdaptiveScalarEncoder, self).getBucketInfo(buckets)
def topDownCompute(self, encoded):
"""
[overrides nupic.encoders.scalar.ScalarEncoder.topDownCompute]
"""
if self.minval is None or self.maxval is None:
return [EncoderResult(value=0, scalar=0,
encoding=numpy.zeros(self.n))]
return super(AdaptiveScalarEncoder, self).topDownCompute(encoded)
def dump(self):
"""
Prints details about current state to stdout.
"""
print "AdaptiveScalarEncoder:"
print " min: {0:f}".format(self.minval)
print " max: {0:f}".format(self.maxval)
print " w: {0:d}".format(self.w)
print " n: {0:d}".format(self.n)
print " resolution: {0:f}".format(self.resolution)
print " radius: {0:f}".format(self.radius)
print " periodic: {0!s}".format(self.periodic)
print " nInternal: {0:d}".format(self.nInternal)
print " rangeInternal: {0:f}".format(self.rangeInternal)
print " padding: {0:d}".format(self.padding)
@classmethod
def read(cls, proto):
encoder = super(AdaptiveScalarEncoder, cls).read(proto)
encoder.recordNum = proto.recordNum
encoder.slidingWindow = MovingAverage.read(proto.slidingWindow)
return encoder
def write(self, proto):
super(AdaptiveScalarEncoder, self).write(proto)
proto.recordNum = self.recordNum
self.slidingWindow.write(proto.slidingWindow)