本文整理汇总了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)
示例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
示例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