本文整理汇总了Python中nupic.encoders.scalar.ScalarEncoder.setFieldStats方法的典型用法代码示例。如果您正苦于以下问题:Python ScalarEncoder.setFieldStats方法的具体用法?Python ScalarEncoder.setFieldStats怎么用?Python ScalarEncoder.setFieldStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.scalar.ScalarEncoder
的用法示例。
在下文中一共展示了ScalarEncoder.setFieldStats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testNonPeriodicBottomUp
# 需要导入模块: from nupic.encoders.scalar import ScalarEncoder [as 别名]
# 或者: from nupic.encoders.scalar.ScalarEncoder import setFieldStats [as 别名]
#.........这里部分代码省略.........
iterlist[j] =1
npar = numpy.array(iterlist)
decoded = l.topDownCompute(npar)[0]
self.assertTrue(decoded.value <= 141)
self.assertTrue(decoded.value >= 1)
self.assertTrue(decoded.value < 141 or i==137)
self.assertTrue(decoded.value > 1 or i == 0)
# -------------------------------------------------------------------------
# Test the input description generation and top-down compute on a small number
# non-periodic encoder
l = ScalarEncoder(name='scalar', n=15, w=3, minval=.001, maxval=.002,
periodic=False, forced=True)
print "\nTesting non-periodic encoder decoding, resolution of %f..." % \
l.resolution
v = l.minval
while v < l.maxval:
output = l.encode(v)
decoded = l.decode(output)
print "decoding", output, "(%f)=>" % v, l.decodedToStr(decoded)
(fieldsDict, fieldNames) = decoded
self.assertEqual(len(fieldsDict), 1)
(ranges, desc) = fieldsDict.values()[0]
self.assertEqual(len(ranges), 1)
(rangeMin, rangeMax) = ranges[0]
self.assertEqual(rangeMin, rangeMax)
self.assertTrue(abs(rangeMin - v) < l.resolution)
topDown = l.topDownCompute(output)[0].value
print "topdown =>", topDown
self.assertTrue(abs(topDown - v) <= l.resolution / 2)
v += l.resolution / 4
# -------------------------------------------------------------------------
# Test the input description generation on a large number, non-periodic encoder
l = ScalarEncoder(name='scalar', n=15, w=3, minval=1, maxval=1000000000,
periodic=False, forced=True)
print "\nTesting non-periodic encoder decoding, resolution of %f..." % \
l.resolution
v = l.minval
while v < l.maxval:
output = l.encode(v)
decoded = l.decode(output)
print "decoding", output, "(%f)=>" % v, l.decodedToStr(decoded)
(fieldsDict, fieldNames) = decoded
self.assertEqual(len(fieldsDict), 1)
(ranges, desc) = fieldsDict.values()[0]
self.assertEqual(len(ranges), 1)
(rangeMin, rangeMax) = ranges[0]
self.assertEqual(rangeMin, rangeMax)
self.assertTrue(abs(rangeMin - v) < l.resolution)
topDown = l.topDownCompute(output)[0].value
print "topdown =>", topDown
self.assertTrue(abs(topDown - v) <= l.resolution / 2)
v += l.resolution / 4
# -------------------------------------------------------------------------
# Test setting fieldStats after initialization
if False:
#TODO: remove all this? (and fieldstats from ScalarEncoder (if applicable) )?
# Modified on 11/20/12 12:53 PM - setFieldStats not applicable for ScalarEncoder
l = ScalarEncoder(n=14, w=3, minval=100, maxval=800, periodic=True, forced=True)
l.setFieldStats("this", {"this":{"min":1, "max":8}})
l = ScalarEncoder(name='scalar', n=14, w=3, minval=100, maxval=800, periodic=True, forced=True)
l.setFieldStats("this", {"this":{"min":1, "max":8}})
self.assertTrue((l.encode(3) == numpy.array([0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(3.1) == l.encode(3)).all())
self.assertTrue((l.encode(3.5) == numpy.array([0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(3.6) == l.encode(3.5)).all())
self.assertTrue((l.encode(3.7) == l.encode(3.5)).all())
self.assertTrue((l.encode(4) == numpy.array([0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(1) == numpy.array([1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(1.5) == numpy.array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(7) == numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(7.5) == numpy.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
dtype=defaultDtype)).all())
l = ScalarEncoder(name='scalar', n=14, w=5, minval=100, maxval=1000, periodic=False, forced=True)
l.setFieldStats("this", {"this":{"min":1, "max":10}})
print "\nTesting non-periodic encoding using setFieldStats, resolution of %f..." % \
l.resolution
self.assertTrue((l.encode(1) == numpy.array([1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(2) == numpy.array([0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],
dtype=defaultDtype)).all())
self.assertTrue((l.encode(10) == numpy.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
dtype=defaultDtype)).all())