當前位置: 首頁>>代碼示例>>Python>>正文


Python GeospatialCoordinateEncoder.read方法代碼示例

本文整理匯總了Python中nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder.read方法的典型用法代碼示例。如果您正苦於以下問題:Python GeospatialCoordinateEncoder.read方法的具體用法?Python GeospatialCoordinateEncoder.read怎麽用?Python GeospatialCoordinateEncoder.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder的用法示例。


在下文中一共展示了GeospatialCoordinateEncoder.read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testReadWrite

# 需要導入模塊: from nupic.encoders.geospatial_coordinate import GeospatialCoordinateEncoder [as 別名]
# 或者: from nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder import read [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))
開發者ID:Afey,項目名稱:nupic,代碼行數:31,代碼來源:geospatial_coordinate_test.py


注:本文中的nupic.encoders.geospatial_coordinate.GeospatialCoordinateEncoder.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。