本文整理匯總了Python中nupic.encoders.date.DateEncoder.read方法的典型用法代碼示例。如果您正苦於以下問題:Python DateEncoder.read方法的具體用法?Python DateEncoder.read怎麽用?Python DateEncoder.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nupic.encoders.date.DateEncoder
的用法示例。
在下文中一共展示了DateEncoder.read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testReadWrite
# 需要導入模塊: from nupic.encoders.date import DateEncoder [as 別名]
# 或者: from nupic.encoders.date.DateEncoder import read [as 別名]
def testReadWrite(self):
originalTS = datetime.datetime(1997, 8, 29, 2, 14)
originalValue = self._e.encode(originalTS)
proto1 = DateEncoderProto.new_message()
self._e.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 = DateEncoderProto.read(f)
encoder = DateEncoder.read(proto2)
self.assertIsInstance(encoder, DateEncoder)
self.assertEqual(encoder.width, self._e.width)
self.assertEqual(encoder.weekendOffset, self._e.weekendOffset)
self.assertEqual(encoder.timeOfDayOffset, self._e.timeOfDayOffset)
self.assertEqual(encoder.seasonOffset, self._e.seasonOffset)
self.assertEqual(encoder.dayOfWeekOffset, self._e.dayOfWeekOffset)
self.assertIsInstance(encoder.customDaysEncoder,
self._e.customDaysEncoder.__class__)
self.assertIsInstance(encoder.dayOfWeekEncoder,
self._e.dayOfWeekEncoder.__class__)
self.assertIsInstance(encoder.seasonEncoder,
self._e.seasonEncoder.__class__)
self.assertIsInstance(encoder.timeOfDayEncoder,
self._e.timeOfDayEncoder.__class__)
self.assertIsInstance(encoder.weekendEncoder,
self._e.weekendEncoder.__class__)
self.assertTrue(numpy.array_equal(self._bits, encoder.encode(self._d)))
self.assertTrue(numpy.array_equal(encoder.encode(originalTS),
originalValue))
self.assertEqual(self._e.decode(encoder.encode(self._d)),
encoder.decode(self._e.encode(self._d)))