本文整理匯總了Python中nupic.encoders.adaptivescalar.AdaptiveScalarEncoder.read方法的典型用法代碼示例。如果您正苦於以下問題:Python AdaptiveScalarEncoder.read方法的具體用法?Python AdaptiveScalarEncoder.read怎麽用?Python AdaptiveScalarEncoder.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nupic.encoders.adaptivescalar.AdaptiveScalarEncoder
的用法示例。
在下文中一共展示了AdaptiveScalarEncoder.read方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read
# 需要導入模塊: from nupic.encoders.adaptivescalar import AdaptiveScalarEncoder [as 別名]
# 或者: from nupic.encoders.adaptivescalar.AdaptiveScalarEncoder import read [as 別名]
def read(cls, proto):
encoder = object.__new__(cls)
encoder.width = proto.width
encoder.name = proto.name or None
encoder.n = proto.n
encoder._adaptiveScalarEnc = (
AdaptiveScalarEncoder.read(proto.adaptiveScalarEnc)
)
encoder._prevAbsolute = proto.prevAbsolute
encoder._prevDelta = proto.prevDelta
encoder._stateLock = proto.stateLock
return encoder
示例2: testReadWrite
# 需要導入模塊: from nupic.encoders.adaptivescalar import AdaptiveScalarEncoder [as 別名]
# 或者: from nupic.encoders.adaptivescalar.AdaptiveScalarEncoder import read [as 別名]
def testReadWrite(self):
originalValue = self._l.encode(1)
proto1 = AdaptiveScalarEncoderProto.new_message()
self._l.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 = AdaptiveScalarEncoderProto.read(f)
encoder = AdaptiveScalarEncoder.read(proto2)
self.assertIsInstance(encoder, AdaptiveScalarEncoder)
self.assertEqual(encoder.recordNum, self._l.recordNum)
self.assertDictEqual(encoder.slidingWindow.__dict__,
self._l.slidingWindow.__dict__)
self.assertEqual(encoder.w, self._l.w)
self.assertEqual(encoder.minval, self._l.minval)
self.assertEqual(encoder.maxval, self._l.maxval)
self.assertEqual(encoder.periodic, self._l.periodic)
self.assertEqual(encoder.n, self._l.n)
self.assertEqual(encoder.radius, self._l.radius)
self.assertEqual(encoder.resolution, self._l.resolution)
self.assertEqual(encoder.name, self._l.name)
self.assertEqual(encoder.verbosity, self._l.verbosity)
self.assertEqual(encoder.clipInput, self._l.clipInput)
self.assertTrue(numpy.array_equal(encoder.encode(1), originalValue))
self.assertEqual(self._l.decode(encoder.encode(1)),
encoder.decode(self._l.encode(1)))
# Feed in a new value and ensure the encodings match
result1 = self._l.encode(7)
result2 = encoder.encode(7)
self.assertTrue(numpy.array_equal(result1, result2))