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


Python Connections.updateSynapsePermanence方法代码示例

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


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

示例1: testComputeActivity

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import updateSynapsePermanence [as 别名]
  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,代码行数:36,代码来源:connections_test.py

示例2: testComputeActivity

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import updateSynapsePermanence [as 别名]
  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 2 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)


    # Segment with:
    # - 2 connected synapses: 1 active, 1 inactive
    # - 3 matching synapses: 2 active, 1 inactive
    # - 1 non-matching synapse: 1 active
    segment2b = connections.createSegment(20)
    connections.createSynapse(segment2b, 50, .85)
    connections.createSynapse(segment2b, 51, .85)
    connections.createSynapse(segment2b, 52, .15)
    connections.createSynapse(segment2b, 53, .05)

    # Cell with one segment.
    # Segment with:
    # - 1 non-matching synapse: 1 active
    segment3a = connections.createSegment(30)
    connections.createSynapse(segment3a, 53, .05)

    inputVec = [50, 52, 53, 80, 81, 82, 150, 151]
    active, matching = connections.computeActivity(inputVec, .5, 2, .1, 1)

    self.assertEqual(1, len(active))
    self.assertEqual(segment2a, active[0].segment)
    self.assertEqual(2, active[0].overlap)

    self.assertEqual(3, len(matching))
    self.assertEqual(segment1a, matching[0].segment)
    self.assertEqual(2, matching[0].overlap)
    self.assertEqual(segment2a, matching[1].segment)
    self.assertEqual(3, matching[1].overlap)
    self.assertEqual(segment2b, matching[2].segment)
    self.assertEqual(2, matching[2].overlap)
开发者ID:andrewmalta13,项目名称:nupic,代码行数:58,代码来源:connections_test.py

示例3: testUpdateSynapsePermanence

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import updateSynapsePermanence [as 别名]
  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,代码行数:14,代码来源:connections_test.py

示例4: TemporalMemory

# 需要导入模块: from nupic.research.connections import Connections [as 别名]
# 或者: from nupic.research.connections.Connections import updateSynapsePermanence [as 别名]

#.........这里部分代码省略.........
        synapses.add(synapse)

    return synapses


  def adaptSegment(self, segment, activeSynapses,
                   permanenceIncrement, permanenceDecrement):
    """
    Updates synapses on segment.
    Strengthens active synapses; weakens inactive synapses.

    @param segment              (int)    Segment index
    @param activeSynapses       (set)    Indices of active synapses
    @param permanenceIncrement  (float)  Amount to increment active synapses
    @param permanenceDecrement  (float)  Amount to decrement inactive synapses
    """
    # Need to copy synapses for segment set below because it will be modified
    # during iteration by `destroySynapse`
    for synapse in set(self.connections.synapsesForSegment(segment)):
      synapseData = self.connections.dataForSynapse(synapse)
      permanence = synapseData.permanence

      if synapse in activeSynapses:
        permanence += permanenceIncrement
      else:
        permanence -= permanenceDecrement

      # Keep permanence within min/max bounds
      permanence = max(0.0, min(1.0, permanence))

      if (abs(permanence) < EPSILON):
        self.connections.destroySynapse(synapse)
      else:
        self.connections.updateSynapsePermanence(synapse, permanence)


  def pickCellsToLearnOn(self, n, segment, winnerCells):
    """
    Pick cells to form distal connections to.

    TODO: Respect topology and learningRadius

    @param n           (int) Number of cells to pick
    @param segment     (int) Segment index
    @param winnerCells (set) Indices of winner cells in `t`

    @return (set) Indices of cells picked
    """
    candidates = set(winnerCells)

    # Remove cells that are already synapsed on by this segment
    for synapse in self.connections.synapsesForSegment(segment):
      synapseData = self.connections.dataForSynapse(synapse)
      presynapticCell = synapseData.presynapticCell

      if presynapticCell in candidates:
        candidates.remove(presynapticCell)

    n = min(n, len(candidates))
    candidates = sorted(candidates)
    cells = set()

    # Pick n cells randomly
    for _ in range(n):
      i = self._random.getUInt32(len(candidates))
      cells.add(candidates[i])
开发者ID:GeraldLoeffler,项目名称:nupic,代码行数:70,代码来源:temporal_memory.py


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