本文整理汇总了Python中nupic.encoders.date.DateEncoder.decodedToStr方法的典型用法代码示例。如果您正苦于以下问题:Python DateEncoder.decodedToStr方法的具体用法?Python DateEncoder.decodedToStr怎么用?Python DateEncoder.decodedToStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.date.DateEncoder
的用法示例。
在下文中一共展示了DateEncoder.decodedToStr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DateEncoderTest
# 需要导入模块: from nupic.encoders.date import DateEncoder [as 别名]
# 或者: from nupic.encoders.date.DateEncoder import decodedToStr [as 别名]
class DateEncoderTest(unittest.TestCase):
'''Unit tests for DateEncoder class'''
def setUp(self):
##TODO: comment and code don't match - weekend?!!
# 3 bits for season, 1 bit for day of week, 2 for weekend, 5 for time of day
# use of forced is not recommended, used here for readibility, see scalar.py
self._e = DateEncoder(season=3, dayOfWeek=1, weekend=3, timeOfDay=5)
# in the middle of fall, Thursday, not a weekend, afternoon - 4th Nov, 2010, 14:55
self._d = datetime.datetime(2010, 11, 4, 14, 55)
self._bits = self._e.encode(self._d)
# season is aaabbbcccddd (1 bit/month) # TODO should be <<3?
# should be 000000000111 (centered on month 11 - Nov)
seasonExpected = [0,0,0,0,0,0,0,0,0,1,1,1]
# week is MTWTFSS
# contrary to localtime documentation, Monday = 0 (for python
# datetime.datetime.timetuple()
dayOfWeekExpected = [0,0,0,1,0,0,0]
# not a weekend, so it should be "False"
weekendExpected = [1,1,1,0,0,0]
# time of day has radius of 4 hours and w of 5 so each bit = 240/5 min = 48min
# 14:55 is minute 14*60 + 55 = 895; 895/48 = bit 18.6
# should be 30 bits total (30 * 48 minutes = 24 hours)
timeOfDayExpected = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0]
self._expected = numpy.array(seasonExpected + dayOfWeekExpected + weekendExpected \
+ timeOfDayExpected, dtype=defaultDtype)
def testDateEncoder(self):
'''creating date encoder instance'''
self.assertEqual(self._e.getDescription(), [("season", 0), ("day of week", 12),
("weekend", 19), ("time of day", 25)])
self.assertTrue((self._expected == self._bits).all())
print
self._e.pprintHeader()
self._e.pprint(self._bits)
print
def testMissingValues(self):
'''missing values'''
mvOutput = self._e.encode(SENTINEL_VALUE_FOR_MISSING_DATA)
self.assertEqual(sum(mvOutput), 0)
def testDecoding(self):
'''decoding date'''
decoded = self._e.decode(self._bits)
(fieldsDict, fieldNames) = decoded
self.assertEqual(len(fieldsDict), 4)
(ranges, desc) = fieldsDict['season']
self.assertEqual(len(ranges), 1)
self.assertSequenceEqual(ranges[0], [305, 305])
(ranges, desc) = fieldsDict['time of day']
self.assertEqual(len(ranges), 1)
self.assertSequenceEqual(ranges[0], [14.4, 14.4])
(ranges, desc) = fieldsDict['day of week']
self.assertEqual(len(ranges), 1)
self.assertSequenceEqual(ranges[0], [3, 3])
(ranges, desc) = fieldsDict['weekend']
self.assertEqual(len(ranges), 1)
self.assertSequenceEqual(ranges[0], [0, 0])
print decoded
print "decodedToStr=>", self._e.decodedToStr(decoded)
def testTopDownCompute(self):
'''Check topDownCompute'''
topDown = self._e.topDownCompute(self._bits)
topDownValues = numpy.array([elem.value for elem in topDown])
errs = topDownValues - numpy.array([320.25, 3.5, .167, 14.8])
self.assertAlmostEqual(errs.max(), 0, 4)
def testBucketIndexSupport(self):
'''Check bucket index support'''
bucketIndices = self._e.getBucketIndices(self._d)
print "bucket indices:", bucketIndices
topDown = self._e.getBucketInfo(bucketIndices)
topDownValues = numpy.array([elem.value for elem in topDown])
errs = topDownValues - numpy.array([320.25, 3.5, .167, 14.8])
self.assertAlmostEqual(errs.max(), 0, 4)
encodings = []
for x in topDown:
encodings.extend(x.encoding)
self.assertTrue((encodings == self._expected).all())
def testHoliday(self):
'''look at holiday more carefully because of the smooth transition'''
# use of forced is not recommended, used here for readibility, see scalar.py
e = DateEncoder(holiday=5, forced=True)
holiday = numpy.array([0,0,0,0,0,1,1,1,1,1], dtype='uint8')
#.........这里部分代码省略.........