本文整理汇总了Python中nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder.write方法的典型用法代码示例。如果您正苦于以下问题:Python GeospatialCoordinateEncoder.write方法的具体用法?Python GeospatialCoordinateEncoder.write怎么用?Python GeospatialCoordinateEncoder.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder
的用法示例。
在下文中一共展示了GeospatialCoordinateEncoder.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReadWrite
# 需要导入模块: from nupic.encoders.geospatial_coordinate import GeospatialCoordinateEncoder [as 别名]
# 或者: from nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder import write [as 别名]
def testReadWrite(self):
scale = 30 # meters
timestep = 60 # seconds
speed = 2.5 # meters per second
original = GeospatialCoordinateEncoder(scale, timestep, n=999, w=25)
encode(original, speed, -122.229194, 37.486782, 0)
encode(original, speed, -122.229294, 37.486882, 100)
proto1 = GeospatialCoordinateEncoderProto.new_message()
original.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 = GeospatialCoordinateEncoderProto.read(f)
encoder = GeospatialCoordinateEncoder.read(proto2)
self.assertIsInstance(encoder, GeospatialCoordinateEncoder)
self.assertEqual(encoder.w, original.w)
self.assertEqual(encoder.n, original.n)
self.assertEqual(encoder.name, original.name)
self.assertEqual(encoder.verbosity, original.verbosity)
# Compare a new value with the original and deserialized.
encoding3 = encode(original, speed, -122.229294, 37.486982, 1000)
encoding4 = encode(encoder, speed, -122.229294, 37.486982, 1000)
self.assertTrue(np.array_equal(encoding3, encoding4))