本文整理汇总了Python中nupic.encoders.coordinate.CoordinateEncoder.write方法的典型用法代码示例。如果您正苦于以下问题:Python CoordinateEncoder.write方法的具体用法?Python CoordinateEncoder.write怎么用?Python CoordinateEncoder.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.coordinate.CoordinateEncoder
的用法示例。
在下文中一共展示了CoordinateEncoder.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CoordinateEncoderTest
# 需要导入模块: from nupic.encoders.coordinate import CoordinateEncoder [as 别名]
# 或者: from nupic.encoders.coordinate.CoordinateEncoder import write [as 别名]
#.........这里部分代码省略.........
self.assertDecreasingOverlaps(overlaps)
def testEncodeRelativePositionsAndRadii(self):
# As radius increases and positions change, the overlap should decrease
overlaps = overlapsForRelativeAreas(999, 25, np.array([100, 200]), 5,
dPosition=np.array([1, 1]),
dRadius=1,
num=5)
self.assertDecreasingOverlaps(overlaps)
def testEncodeUnrelatedAreas(self):
"""
assert unrelated areas don"t share bits
(outside of chance collisions)
"""
avgThreshold = 0.3
maxThreshold = 0.12
overlaps = overlapsForUnrelatedAreas(1499, 37, 5)
self.assertLess(np.max(overlaps), maxThreshold)
self.assertLess(np.average(overlaps), avgThreshold)
maxThreshold = 0.12
overlaps = overlapsForUnrelatedAreas(1499, 37, 10)
self.assertLess(np.max(overlaps), maxThreshold)
self.assertLess(np.average(overlaps), avgThreshold)
maxThreshold = 0.17
overlaps = overlapsForUnrelatedAreas(999, 25, 10)
self.assertLess(np.max(overlaps), maxThreshold)
self.assertLess(np.average(overlaps), avgThreshold)
maxThreshold = 0.25
overlaps = overlapsForUnrelatedAreas(499, 13, 10)
self.assertLess(np.max(overlaps), maxThreshold)
self.assertLess(np.average(overlaps), avgThreshold)
def testEncodeAdjacentPositions(self, verbose=False):
repetitions = 100
n = 999
w = 25
radius = 10
minThreshold = 0.75
avgThreshold = 0.90
allOverlaps = np.empty(repetitions)
for i in range(repetitions):
overlaps = overlapsForRelativeAreas(n, w,
np.array([i * 10, i * 10]), radius,
dPosition=np.array([0, 1]),
num=1)
allOverlaps[i] = overlaps[0]
self.assertGreater(np.min(allOverlaps), minThreshold)
self.assertGreater(np.average(allOverlaps), avgThreshold)
if verbose:
print ("===== Adjacent positions overlap "
"(n = {0}, w = {1}, radius = {2}) ===").format(n, w, radius)
print "Max: {0}".format(np.max(allOverlaps))
print "Min: {0}".format(np.min(allOverlaps))
print "Average: {0}".format(np.average(allOverlaps))
def assertDecreasingOverlaps(self, overlaps):
self.assertEqual((np.diff(overlaps) > 0).sum(), 0)
@unittest.skipUnless(
capnp, "pycapnp is not installed, skipping serialization test.")
def testReadWrite(self):
coordinate = np.array([100, 200])
radius = 5
output1 = encode(self.encoder, coordinate, radius)
proto1 = CoordinateEncoderProto.new_message()
self.encoder.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 = CoordinateEncoderProto.read(f)
encoder = CoordinateEncoder.read(proto2)
self.assertIsInstance(encoder, CoordinateEncoder)
self.assertEqual(encoder.w, self.encoder.w)
self.assertEqual(encoder.n, self.encoder.n)
self.assertEqual(encoder.name, self.encoder.name)
self.assertEqual(encoder.verbosity, self.encoder.verbosity)
coordinate = np.array([100, 200])
radius = 5
output2 = encode(encoder, coordinate, radius)
self.assertTrue(np.array_equal(output1, output2))