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


Python connections.Connections类代码示例

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


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

示例1: testCreateSegment

  def testCreateSegment(self):
    connections = Connections(1024)

    segment1 = connections.createSegment(10)
    self.assertEqual(segment1.cell, 10)

    segment2 = connections.createSegment(10)
    self.assertEqual(segment2.cell, 10)

    self.assertEqual([segment1, segment2],
                     list(connections.segmentsForCell(10)))
开发者ID:blueburningcoder,项目名称:nupic,代码行数:11,代码来源:connections_test.py

示例2: read

  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,代码行数:33,代码来源:temporal_memory.py

示例3: __init__

  def __init__(self,
               columnDimensions=(2048,),
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement = 0.004,
               seed=42):
    """
    @param columnDimensions          (list)  Dimensions of the column space
    @param cellsPerColumn            (int)   Number of cells per column
    @param activationThreshold       (int)   If the number of active connected synapses on a segment is at least this threshold, the segment is said to be active.
    @param initialPermanence         (float) Initial permanence of a new synapse.
    @param connectedPermanence       (float) If the permanence value for a synapse is greater than this value, it is said to be connected.
    @param minThreshold              (int)   If the number of synapses active on a segment is at least this threshold, it is selected as the best matching cell in a bursting column.
    @param maxNewSynapseCount        (int)   The maximum number of synapses added to a segment during learning.
    @param permanenceIncrement       (float) Amount by which permanences of synapses are incremented during learning.
    @param permanenceDecrement       (float) Amount by which permanences of synapses are decremented during learning.
    @param predictedSegmentDecrement (float) Amount by which active permanences of synapses of previously predicted but inactive segments are decremented.
    @param seed                      (int)   Seed for the random number generator.
    """
    # Error checking
    if not len(columnDimensions):
      raise ValueError("Number of column dimensions must be greater than 0")

    if not cellsPerColumn > 0:
      raise ValueError("Number of cells per column must be greater than 0")

    # TODO: Validate all parameters (and add validation tests)

    # Save member variables
    self.columnDimensions = columnDimensions
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    # Initialize member variables
    self.connections = Connections(self.numberOfCells())
    self._random = Random(seed)

    self.activeCells = set()
    self.predictiveCells = set()
    self.activeSegments = set()
    self.winnerCells = set()
    self.matchingSegments = set()
    self.matchingCells = set()
开发者ID:zerocool438,项目名称:nupic,代码行数:55,代码来源:temporal_memory.py

示例4: testDestroySynapse

  def testDestroySynapse(self):
    """ Creates a segment, creates a number of synapses on it, destroys a
        synapse, and makes sure it got destroyed.
    """
    connections = Connections(1024)

    segment = connections.createSegment(20)
    synapse1 = connections.createSynapse(segment, 80, .85)
    synapse2 = connections.createSynapse(segment, 81, .85)
    synapse3 = connections.createSynapse(segment, 82, .15)

    self.assertEqual(3, connections.numSynapses())

    connections.destroySynapse(synapse2)

    self.assertEqual(2, connections.numSynapses())
    self.assertEqual(connections.synapsesForSegment(segment), [synapse1,
                                                               synapse3])
    active, matching = connections.computeActivity([80, 81, 82], .5, 2, 0.0, 1)
    self.assertEqual(0, len(active))
    self.assertEqual(1, len(matching))
    self.assertEqual(2, matching[0].overlap)
开发者ID:andrewmalta13,项目名称:nupic,代码行数:22,代码来源:connections_test.py

示例5: testDestroySynapse

  def testDestroySynapse(self):
    """ Creates a segment, creates a number of synapses on it, destroys a
        synapse, and makes sure it got destroyed.
    """
    connections = Connections(1024)

    segment = connections.createSegment(20)
    synapse1 = connections.createSynapse(segment, 80, .85)
    synapse2 = connections.createSynapse(segment, 81, .85)
    synapse3 = connections.createSynapse(segment, 82, .15)

    self.assertEqual(3, connections.numSynapses())

    connections.destroySynapse(synapse2)

    self.assertEqual(2, connections.numSynapses())
    self.assertEqual(set([synapse1, synapse3]),
                     connections.synapsesForSegment(segment))
    (numActiveConnected,
     numActivePotential) = connections.computeActivity([80, 81, 82], .5)

    self.assertEqual(1, numActiveConnected[segment.flatIdx])
    self.assertEqual(2, numActivePotential[segment.flatIdx])
开发者ID:blueburningcoder,项目名称:nupic,代码行数:23,代码来源:connections_test.py

示例6: read

  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,代码行数:47,代码来源:temporal_memory.py

示例7: testUpdateSynapsePermanence

  def testUpdateSynapsePermanence(self):
    """ Creates a synapse and updates its permanence, and makes sure that its
        data was correctly updated.
    """
    connections = Connections(1024)
    segment = connections.createSegment(10)
    synapse = connections.createSynapse(segment, 50, .34)

    connections.updateSynapsePermanence(synapse, .21)

    synapseData = connections.dataForSynapse(synapse)
    self.assertAlmostEqual(synapseData.permanence, .21)
开发者ID:blueburningcoder,项目名称:nupic,代码行数:12,代码来源:connections_test.py

示例8: testSynapseReuse

  def testSynapseReuse(self):
    """ Creates a synapse over the synapses per segment limit, and verifies
        that the lowest permanence synapse is removed to make room for the new
        synapse.
    """
    connections = Connections(1024, 1024, 2)
    segment = connections.createSegment(10)

    synapse1 = connections.createSynapse(segment, 50, .34)
    synapse2 = connections.createSynapse(segment, 51, .48)

    synapses = connections.synapsesForSegment(segment)
    self.assertEqual(set([synapse1, synapse2]), synapses)

    # Add an additional synapse to force it over the limit of num synapses
    # per segment.
    connections.createSynapse(segment, 52, .52)

    # Ensure lower permanence synapse was removed.
    self.assertEqual(set([51, 52]),
                     set(synapse.presynapticCell
                         for synapse in
                         connections.synapsesForSegment(segment)))
开发者ID:blueburningcoder,项目名称:nupic,代码行数:23,代码来源:connections_test.py

示例9: testSynapseReuse

  def testSynapseReuse(self):
    """ Creates a synapse over the synapses per segment limit, and verifies
        that the lowest permanence synapse is removed to make room for the new
        synapse.
    """
    connections = Connections(1024, 1024, 2)
    segment = connections.createSegment(10)

    synapse1 = connections.createSynapse(segment, 50, .34)
    synapse2 = connections.createSynapse(segment, 51, .34)

    synapses = connections.synapsesForSegment(segment)
    self.assertEqual(synapses, [synapse1, synapse2])

    #Add an additional synapse to force it over the limit of num synapses
    #per segment.
    synapse3 = connections.createSynapse(segment, 52, .52)
    self.assertEqual(0, synapse3.idx)

    #ensure lower permanence synapse was removed
    synapses = connections.synapsesForSegment(segment)
    self.assertEqual(synapses, [synapse3, synapse2])
开发者ID:andrewmalta13,项目名称:nupic,代码行数:22,代码来源:connections_test.py

示例10: TemporalMemory

class TemporalMemory(object):
  """ Class implementing the Temporal Memory algorithm. """

  def __init__(self,
               columnDimensions=(2048,),
               cellsPerColumn=32,
               activationThreshold=13,
               initialPermanence=0.21,
               connectedPermanence=0.50,
               minThreshold=10,
               maxNewSynapseCount=20,
               permanenceIncrement=0.10,
               permanenceDecrement=0.10,
               predictedSegmentDecrement=0.0,
               maxSegmentsPerCell=255,
               maxSynapsesPerSegment=255,
               seed=42,
               **kwargs):
    """
    @param columnDimensions          (list)  Dimensions of the column space
    @param cellsPerColumn            (int)   Number of cells per column
    @param activationThreshold       (int)   If the number of active connected
                                             synapses on a segment is at least
                                             this threshold, the segment is said
                                             to be active.
    @param initialPermanence         (float) Initial permanence of a new synapse
    @param connectedPermanence       (float) If the permanence value for a
                                             synapse is greater than this value,
                                             it is said to be connected.
    @param minThreshold              (int)   If the number of synapses active on
                                             a segment is at least this
                                             threshold, it is selected as the
                                             best matching cell in a bursting
                                             column
    @param maxNewSynapseCount        (int)   The maximum number of synapses
                                             added to a segment during learning
    @param permanenceIncrement       (float) Amount by which permanences of
                                             synapses are incremented during
                                             learning.
    @param permanenceDecrement       (float) Amount by which permanences of
                                             synapses are decremented during
                                             learning.
    @param predictedSegmentDecrement (float) Amount by which active permanences
                                             of synapses of previously predicted
                                             but inactive segments are
                                             decremented.
    @param seed                      (int)   Seed for the random number
                                             generator
    Notes:

    predictedSegmentDecrement: A good value is just a bit larger than
    (the column-level sparsity * permanenceIncrement). So, if column-level
    sparsity is 2% and permanenceIncrement is 0.01, this parameter should be
    something like 4% * 0.01 = 0.0004).
    """
    # Error checking
    if not len(columnDimensions):
      raise ValueError("Number of column dimensions must be greater than 0")

    if cellsPerColumn <= 0:
      raise ValueError("Number of cells per column must be greater than 0")

    # TODO: Validate all parameters (and add validation tests)

    # Save member variables
    self.columnDimensions = columnDimensions
    self.cellsPerColumn = cellsPerColumn
    self.activationThreshold = activationThreshold
    self.initialPermanence = initialPermanence
    self.connectedPermanence = connectedPermanence
    self.minThreshold = minThreshold
    self.maxNewSynapseCount = maxNewSynapseCount
    self.permanenceIncrement = permanenceIncrement
    self.permanenceDecrement = permanenceDecrement
    self.predictedSegmentDecrement = predictedSegmentDecrement
    # Initialize member variables
    self.connections = Connections(self.numberOfCells(),
                                   maxSegmentsPerCell=maxSegmentsPerCell,
                                   maxSynapsesPerSegment=maxSynapsesPerSegment)
    self._random = Random(seed)

    self.activeCells = []
    self.winnerCells = []
    self.activeSegments = []
    self.matchingSegments = []

  # ==============================
  # Main functions
  # ==============================

  def compute(self, activeColumns, learn=True):
    """ Feeds input record through TM, performing inference and learning.

    @param activeColumns (set)  Indices of active columns
    @param learn         (bool) Whether or not learning is enabled

    Updates member variables:
      - `activeCells`     (list)
      - `winnerCells`     (list)
      - `activeSegments`  (list)
#.........这里部分代码省略.........
开发者ID:andrewmalta13,项目名称:nupic,代码行数:101,代码来源:temporal_memory.py

示例11: testComputeActivity

  def testComputeActivity(self):
    """ Creates a sample set of connections, and makes sure that computing the
        activity for a collection of cells with no activity returns the right
        activity data.
    """
    connections = Connections(1024)

    # Cell with 1 segment.
    # Segment with:
    # - 1 connected synapse: active
    # - 2 matching synapses
    segment1a = connections.createSegment(10)
    connections.createSynapse(segment1a, 150, .85)
    connections.createSynapse(segment1a, 151, .15)

    # Cell with 1 segment.
    # Segment with:
    # - 2 connected synapse: 2 active
    # - 3 matching synapses: 3 active
    segment2a = connections.createSegment(20)
    connections.createSynapse(segment2a, 80, .85)
    connections.createSynapse(segment2a, 81, .85)
    synapse = connections.createSynapse(segment2a, 82, .85)
    connections.updateSynapsePermanence(synapse, .15)

    inputVec = [50, 52, 53, 80, 81, 82, 150, 151]
    (numActiveConnected,
     numActivePotential) = connections.computeActivity(inputVec, .5)

    self.assertEqual(1, numActiveConnected[segment1a.flatIdx])
    self.assertEqual(2, numActivePotential[segment1a.flatIdx])

    self.assertEqual(2, numActiveConnected[segment2a.flatIdx])
    self.assertEqual(3, numActivePotential[segment2a.flatIdx])
开发者ID:blueburningcoder,项目名称:nupic,代码行数:34,代码来源:connections_test.py

示例12: testDestroySynapsesThenReachLimit

  def testDestroySynapsesThenReachLimit(self):
    """ Destroy some synapses then verify that the maxSynapsesPerSegment is
        still correctly applied.
    """
    connections = Connections(1024, 2, 2)

    segment = connections.createSegment(10)

    synapse1 = connections.createSynapse(segment, 201, .85)
    synapse2 = connections.createSynapse(segment, 202, .85)

    self.assertEqual(2, connections.numSynapses())
    connections.destroySynapse(synapse1)
    connections.destroySynapse(synapse2)
    self.assertEqual(0, connections.numSynapses())

    connections.createSynapse(segment, 201, .85)
    self.assertEqual(1, connections.numSynapses())
    connections.createSynapse(segment, 202, .90)
    self.assertEqual(2, connections.numSynapses())
    synapse3 = connections.createSynapse(segment, 203, .8)
    self.assertEqual(2, connections.numSynapses())
开发者ID:blueburningcoder,项目名称:nupic,代码行数:22,代码来源:connections_test.py

示例13: testReachSegmentLimitMultipleTimes

  def testReachSegmentLimitMultipleTimes(self):
    """ Hit the maxSynapsesPerSegment threshold multiple times. Make sure it
        works more than once.
    """
    connections = Connections(1024, 2, 2)

    segment = connections.createSegment(10)
    connections.createSynapse(segment, 201, .85)
    self.assertEqual(1, connections.numSynapses())
    connections.createSynapse(segment, 202, .9)
    self.assertEqual(2, connections.numSynapses())
    connections.createSynapse(segment, 203, .8)
    self.assertEqual(2, connections.numSynapses())
    synapse = connections.createSynapse(segment, 204, .8)
    self.assertEqual(2, connections.numSynapses())
开发者ID:blueburningcoder,项目名称:nupic,代码行数:15,代码来源:connections_test.py

示例14: testReuseSegmentWithDestroyedSynapses

  def testReuseSegmentWithDestroyedSynapses(self):
    """ Destroy a segment that has a destroyed synapse and a non-destroyed
        synapse. Create a new segment in the same place. Make sure its synapse
        count is correct.
    """
    connections = Connections(1024)

    segment = connections.createSegment(11)

    synapse1 = connections.createSynapse(segment, 201, .85)
    connections.createSynapse(segment, 202, .85)

    connections.destroySynapse(synapse1)

    self.assertEqual(1, connections.numSynapses(segment))

    connections.destroySegment(segment)

    reincarnated = connections.createSegment(11)

    self.assertEqual(0, connections.numSynapses(reincarnated))
    self.assertEqual(0, len(connections.synapsesForSegment(reincarnated)))
开发者ID:blueburningcoder,项目名称:nupic,代码行数:22,代码来源:connections_test.py

示例15: testDestroySegmentsThenReachLimit

  def testDestroySegmentsThenReachLimit(self):
    """ Destroy some segments then verify that the maxSegmentsPerCell is still
        correctly applied.
    """
    connections = Connections(1024, 2, 2)

    segment1 = connections.createSegment(11)
    segment2 = connections.createSegment(11)

    self.assertEqual(2, connections.numSegments())
    connections.destroySegment(segment1)
    connections.destroySegment(segment2)
    self.assertEqual(0, connections.numSegments())

    connections.createSegment(11)
    self.assertEqual(1, connections.numSegments())
    connections.createSegment(11)
    self.assertEqual(2, connections.numSegments())
    segment3 = connections.createSegment(11)
    self.assertEqual(2, connections.numSegments(11))
    self.assertEqual(2, connections.numSegments())
开发者ID:blueburningcoder,项目名称:nupic,代码行数:21,代码来源:connections_test.py


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