当前位置: 首页>>代码示例>>Python>>正文


Python Connections.read方法代码示例

本文整理汇总了Python中nupic.research.connections.Connections.read方法的典型用法代码示例。如果您正苦于以下问题:Python Connections.read方法的具体用法?Python Connections.read怎么用?Python Connections.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nupic.research.connections.Connections的用法示例。


在下文中一共展示了Connections.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testWriteRead

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import read [as 别名]
  def testWriteRead(self):
    c1 = Connections(1024)

    # Add data before serializing
    s1 = c1.createSegment(0)
    c1.createSynapse(s1, 254, 0.1173)

    s2 = c1.createSegment(100)
    c1.createSynapse(s2, 20, 0.3)

    c1.createSynapse(s1, 40, 0.3)

    s3 = c1.createSegment(0)
    c1.createSynapse(s3, 0, 0.5)
    c1.createSynapse(s3, 1, 0.5)

    s4 = c1.createSegment(10)
    c1.createSynapse(s4, 0, 0.5)
    c1.createSynapse(s4, 1, 0.5)
    c1.destroySegment(s4)

    proto1 = ConnectionsProto_capnp.ConnectionsProto.new_message()
    c1.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 = ConnectionsProto_capnp.ConnectionsProto.read(f)

    # Load the deserialized proto
    c2 = Connections.read(proto2)

    # Check that the two connections objects are functionally equal
    self.assertEqual(c1, c2)
开发者ID:blueburningcoder,项目名称:nupic,代码行数:37,代码来源:connections_test.py

示例2: read

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import read [as 别名]
  def read(cls, proto):
    """
    Reads deserialized data from proto object

    @param proto (DynamicStructBuilder) Proto object

    @return (TemporalMemory) TemporalMemory instance
    """
    tm = object.__new__(cls)

    tm.columnDimensions = list(proto.columnDimensions)
    tm.cellsPerColumn = int(proto.cellsPerColumn)
    tm.activationThreshold = int(proto.activationThreshold)
    tm.initialPermanence = proto.initialPermanence
    tm.connectedPermanence = proto.connectedPermanence
    tm.minThreshold = int(proto.minThreshold)
    tm.maxNewSynapseCount = int(proto.maxNewSynapseCount)
    tm.permanenceIncrement = proto.permanenceIncrement
    tm.permanenceDecrement = proto.permanenceDecrement
    tm.predictedSegmentDecrement = proto.predictedSegmentDecrement

    tm.connections = Connections.read(proto.connections)
    tm._random = Random()
    tm._random.read(proto.random)

    tm.activeCells = set([int(x) for x in proto.activeCells])
    tm.predictiveCells = set([int(x) for x in proto.predictiveCells])
    tm.activeSegments = set([int(x) for x in proto.activeSegments])
    tm.winnerCells = set([int(x) for x in proto.winnerCells])
    tm.matchingSegments = set([int(x) for x in proto.matchingSegments])
    tm.matchingCells = set([int(x) for x in proto.matchingCells])

    return tm
开发者ID:zerocool438,项目名称:nupic,代码行数:35,代码来源:temporal_memory.py

示例3: read

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import read [as 别名]
  def read(cls, proto):
    """ Reads deserialized data from proto object

    @param proto (DynamicStructBuilder) Proto object

    @return (TemporalMemory) TemporalMemory instance
    """
    tm = object.__new__(cls)

    tm.columnDimensions = list(proto.columnDimensions)
    tm.cellsPerColumn = int(proto.cellsPerColumn)
    tm.activationThreshold = int(proto.activationThreshold)
    tm.initialPermanence = proto.initialPermanence
    tm.connectedPermanence = proto.connectedPermanence
    tm.minThreshold = int(proto.minThreshold)
    tm.maxNewSynapseCount = int(proto.maxNewSynapseCount)
    tm.permanenceIncrement = proto.permanenceIncrement
    tm.permanenceDecrement = proto.permanenceDecrement
    tm.predictedSegmentDecrement = proto.predictedSegmentDecrement

    tm.connections = Connections.read(proto.connections)
    #pylint: disable=W0212
    tm._random = Random()
    tm._random.read(proto.random)
    #pylint: enable=W0212

    tm.activeCells = [int(x) for x in proto.activeCells]
    tm.winnerCells = [int(x) for x in proto.winnerCells]

    tm.activeSegments = []
    tm.matchingSegments = []

    for i in xrange(len(proto.activeSegmentOverlaps)):
      protoSegmentOverlap = proto.activeSegmentOverlaps[i]
      segment = tm.connections.getSegment(protoSegmentOverlap.segment,
                                          protoSegmentOverlap.cell)
      segmentOverlap = SegmentOverlap(segment, protoSegmentOverlap.overlap)
      tm.activeSegments.append(segmentOverlap)

    for i in xrange(len(proto.matchingSegmentOverlaps)):
      protoSegmentOverlap = proto.matchingSegmentOverlaps[i]
      segment = tm.connections.getSegment(protoSegmentOverlap.segment,
                                          protoSegmentOverlap.cell)
      segmentOverlap = SegmentOverlap(segment, protoSegmentOverlap.overlap)
      tm.matchingSegments.append(segmentOverlap)

    return tm
开发者ID:andrewmalta13,项目名称:nupic,代码行数:49,代码来源:temporal_memory.py


注:本文中的nupic.research.connections.Connections.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。