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


Python SpatialPooler._connectedSynapses方法代码示例

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


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

示例1: testRaisePermanenceThreshold

# 需要导入模块: from nupic.research.spatial_pooler import SpatialPooler [as 别名]
# 或者: from nupic.research.spatial_pooler.SpatialPooler import _connectedSynapses [as 别名]
  def testRaisePermanenceThreshold(self):
    sp = SpatialPooler(inputDimensions=[5],
                       columnDimensions=[5],
                       synPermConnected=0.1,
                       stimulusThreshold=3)
    sp._synPermBelowStimulusInc = 0.01
    sp._permanences = SparseMatrix(
        [[0.0, 0.11, 0.095, 0.092, 0.01],
         [0.12, 0.15, 0.02, 0.12, 0.09],
         [0.51, 0.081, 0.025, 0.089, 0.31],
         [0.18, 0.0601, 0.11, 0.011, 0.03],
         [0.011, 0.011, 0.011, 0.011, 0.011]])

    sp._connectedSynapses = SparseBinaryMatrix(
        [[0, 1, 0, 0, 0],
         [1, 1, 0, 1, 0],
         [1, 0, 0, 0, 1],
         [1, 0, 1, 0, 0],
         [0, 0, 0, 0, 0]])

    sp._connectedCounts = numpy.array([1, 3, 2, 2, 0])

    truePermanences = [
        [0.0, 0.12, 0.105, 0.102, 0.0],  # incremented once
        [0.12, 0.15, 0.02, 0.12, 0.09],  # no change
        [0.53, 0.101, 0.0, 0.109, 0.33],  # increment twice
        [0.22, 0.1001, 0.15, 0.051, 0.07],  # increment four times
        [0.101, 0.101, 0.101, 0.101, 0.101]]  #increment 9 times

    trueConnectedSynapses = [
        [0, 1, 1, 1, 0],
        [1, 1, 0, 1, 0],
        [1, 1, 0, 1, 1],
        [1, 1, 1, 0, 0],
        [1, 1, 1, 1, 1]]

    trueConnectedCounts = [3, 3, 4, 3, 5]
    sp._raisePermanenceToThreshold()
    for i in xrange(sp._numColumns):
      perm = list(sp._permanences.getRow(i))
      for j in xrange(sp._numInputs):
        self.assertAlmostEqual(truePermanences[i][j],perm[j])
      self.assertListEqual(
        trueConnectedSynapses[i],
        list(sp._connectedSynapses.getRow(i))
      )
      self.assertEqual(trueConnectedCounts[i], sp._connectedCounts[i])
开发者ID:Ueelee,项目名称:nupic,代码行数:49,代码来源:spatial_pooler_test.py

示例2: testCalculateOverlap

# 需要导入模块: from nupic.research.spatial_pooler import SpatialPooler [as 别名]
# 或者: from nupic.research.spatial_pooler.SpatialPooler import _connectedSynapses [as 别名]
  def testCalculateOverlap(self):
    """
    Test that column computes overlap and percent overlap correctly.
    """
    sp = SpatialPooler(inputDimensions = [10],
                       columnDimensions = [5])
    sp._connectedSynapses = SparseBinaryMatrix(
      [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]])
    sp._connectedCounts = numpy.array([10.0, 8.0, 6.0, 4.0, 2.0])
    inputVector = numpy.zeros(sp._numInputs, dtype='float32')
    overlaps, overlapsPct = sp._calculateOverlap(inputVector)
    trueOverlaps = list(numpy.array([0, 0, 0, 0, 0]))
    trueOverlapsPct = list(numpy.array([0, 0, 0, 0, 0]))
    self.assertListEqual(list(overlaps), trueOverlaps)
    self.assertListEqual(list(overlapsPct), trueOverlapsPct)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]])
    sp._connectedCounts = numpy.array([10.0, 8.0, 6.0, 4.0, 2.0])
    inputVector = numpy.ones(sp._numInputs, dtype='float32')
    overlaps, overlapsPct = sp._calculateOverlap(inputVector)
    trueOverlaps = list(numpy.array([10, 8, 6, 4, 2]))
    trueOverlapsPct = list(numpy.array([1, 1, 1, 1, 1]))
    self.assertListEqual(list(overlaps), trueOverlaps)
    self.assertListEqual(list(overlapsPct), trueOverlapsPct)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 1]])
    sp._connectedCounts = numpy.array([10.0, 8.0, 6.0, 4.0, 2.0])
    inputVector = numpy.zeros(sp._numInputs, dtype='float32')
    inputVector[9] = 1
    overlaps, overlapsPct = sp._calculateOverlap(inputVector)
    trueOverlaps = list(numpy.array([1, 1, 1, 1, 1]))
    trueOverlapsPct = list(numpy.array([0.1, 0.125, 1.0/6, 0.25, 0.5]))
    self.assertListEqual(list(overlaps), trueOverlaps)
    self.assertListEqual(list(overlapsPct), trueOverlapsPct)

    # Zig-zag
    sp._connectedSynapses = SparseBinaryMatrix(
      [[1, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 1]])
    sp._connectedCounts = numpy.array([2.0, 2.0, 2.0, 2.0, 2.0])
    inputVector = numpy.zeros(sp._numInputs, dtype='float32')
    inputVector[range(0,10,2)] = 1
    overlaps, overlapsPct = sp._calculateOverlap(inputVector)
    trueOverlaps = list(numpy.array([1, 1, 1, 1, 1]))
    trueOverlapsPct = list(numpy.array([0.5, 0.5, 0.5, 0.5, 0.5]))
    self.assertListEqual(list(overlaps), trueOverlaps)
    self.assertListEqual(list(overlapsPct), trueOverlapsPct)
开发者ID:Ueelee,项目名称:nupic,代码行数:66,代码来源:spatial_pooler_test.py

示例3: testCalculateSharedInputs

# 需要导入模块: from nupic.research.spatial_pooler import SpatialPooler [as 别名]
# 或者: from nupic.research.spatial_pooler.SpatialPooler import _connectedSynapses [as 别名]
  def testCalculateSharedInputs(self):
    sp = SpatialPooler(inputDimensions=[8],
                       columnDimensions=[5])
    sp._connectedSynapses = SparseBinaryMatrix(
      [[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 1, 0, 0, 0, 1, 0],
       [1, 0, 0, 0, 1, 0, 0, 0]])
    inputVector = numpy.array(
       [1, 1, 1, 1, 0, 0, 0, 0])
    activeColumns = range(5)
    sharedTrue = set([3])
    shared = set(sp._calculateSharedInputs(inputVector, activeColumns))
    self.assertSetEqual(shared, sharedTrue)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 1, 0, 0, 0, 1, 0],
       [1, 0, 0, 0, 1, 0, 0, 0]])
    inputVector = numpy.array(
       [1, 1, 1, 0, 1, 1, 1, 1])
    activeColumns = range(5)
    sharedTrue = set([6,7])
    shared = set(sp._calculateSharedInputs(inputVector, activeColumns))
    self.assertSetEqual(shared, sharedTrue)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 1, 0, 0, 0, 1, 0],
       [1, 0, 0, 0, 1, 0, 0, 0]])
    inputVector = numpy.array(
       [0, 0, 0, 0, 0, 0, 0, 0])

    activeColumns = range(5)
    sharedTrue = set([])
    shared = set(sp._calculateSharedInputs(inputVector, activeColumns))
    self.assertSetEqual(shared, sharedTrue)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 1, 0, 0, 0, 1, 0],
       [1, 0, 0, 0, 1, 0, 0, 0]])
    inputVector = numpy.array(
       [1, 0, 1, 0, 1, 1, 1, 0])

    activeColumns = [1,2,3]
    sharedTrue = set([6])
    shared = set(sp._calculateSharedInputs(inputVector, activeColumns))
    self.assertSetEqual(shared, sharedTrue)

    sp._connectedSynapses = SparseBinaryMatrix(
      [[0, 1, 0, 1, 0, 1, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 1, 0, 0, 0, 1, 0],
       [1, 0, 0, 0, 1, 0, 0, 0]])
    inputVector = numpy.array([1, 0, 1, 1, 1, 1, 1, 1])
    activeColumns = [0,1,3,4]
    sharedTrue = set([3,7])
    shared = set(sp._calculateSharedInputs(inputVector, activeColumns))
    self.assertSetEqual(shared, sharedTrue)
开发者ID:Ueelee,项目名称:nupic,代码行数:70,代码来源:spatial_pooler_test.py


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