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


Python SpatialPooler._adaptSynapses方法代码示例

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


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

示例1: testInhibition

# 需要导入模块: from nupic.research.spatial_pooler import SpatialPooler [as 别名]
# 或者: from nupic.research.spatial_pooler.SpatialPooler import _adaptSynapses [as 别名]
  def testInhibition(self):
    """
    Test if the firing number of coincidences after inhibition
    equals spatial pooler numActiveColumnsPerInhArea.
    """
    # Miscellaneous variables:
    # n, w:                 n, w of encoders
    # inputLen:             Length of binary input
    # synPermConnected:     Spatial pooler synPermConnected
    # synPermActiveInc:     Spatial pooler synPermActiveInc
    # connectPct:           Initial connect percentage of permanences
    # columnDimensions:     Number of spatial pooler coincidences
    # numActiveColumnsPerInhArea:  Spatial pooler numActiveColumnsPerInhArea
    # stimulusThreshold:    Spatial pooler stimulusThreshold
    # spSeed:               Spatial pooler for initial permanences
    # stimulusThresholdInh: Parameter for inhibition, default value 0.00001
    # kDutyCycleFactor:     kDutyCycleFactor for dutyCycleTieBreaker in
    #                       Inhibition
    # spVerbosity:          Verbosity to print other sp initial parameters
    # testIter:             Testing iterations
    n = 100
    w = 15
    inputLen = 300
    columnDimensions = 2048
    numActiveColumnsPerInhArea = 40
    stimulusThreshold = 0
    spSeed = 1956
    stimulusThresholdInh = 0.00001
    kDutyCycleFactor = 0.01
    spVerbosity = 0
    testIter = 100

    spTest = SpatialPooler(
                           columnDimensions=(columnDimensions, 1),
                           inputDimensions=(1, inputLen),
                           potentialRadius=inputLen / 2,
                           numActiveColumnsPerInhArea=numActiveColumnsPerInhArea,
                           spVerbosity=spVerbosity,
                           stimulusThreshold=stimulusThreshold,
                           seed=spSeed
                           )
    initialPermanence = spTest._initialPermanence()
    spTest._masterPotentialM, spTest._masterPermanenceM = (
        spTest._makeMasterCoincidences(spTest.numCloneMasters,
                                       spTest._coincRFShape,
                                       spTest.potentialPct,
                                       initialPermanence,
                                       spTest.random))

    spTest._updateInhibitionObj()
    boostFactors = numpy.ones(columnDimensions)

    for i in range(testIter):
      spTest._iterNum = i
      # random binary input
      input_ = numpy.zeros((1, inputLen))
      nonzero = numpy.random.random(inputLen)
      input_[0][numpy.where (nonzero < float(w)/float(n))] = 1

      # overlap step
      spTest._computeOverlapsFP(input_,
                                stimulusThreshold=spTest.stimulusThreshold)
      spTest._overlaps *= boostFactors
      onCellIndices = numpy.where(spTest._overlaps > 0)
      spTest._onCells.fill(0)
      spTest._onCells[onCellIndices] = 1
      denseOn = spTest._onCells

      # update _dutyCycleBeforeInh
      spTest.dutyCyclePeriod = min(i + 1, 1000)
      spTest._dutyCycleBeforeInh = (
          (spTest.dutyCyclePeriod - 1) *
          spTest._dutyCycleBeforeInh +denseOn) / spTest.dutyCyclePeriod
      dutyCycleTieBreaker = spTest._dutyCycleAfterInh.copy()
      dutyCycleTieBreaker *= kDutyCycleFactor

      # inhibition step
      numOn = spTest._inhibitionObj.compute(
          spTest._overlaps + dutyCycleTieBreaker, spTest._onCellIndices,
          stimulusThresholdInh,  # stimulusThresholdInh
          max(spTest._overlaps)/1000,  # addToWinners
      )
      # update _dutyCycleAfterInh
      spTest._onCells.fill(0)
      onCellIndices = spTest._onCellIndices[0:numOn]
      spTest._onCells[onCellIndices] = 1
      denseOn = spTest._onCells
      spTest._dutyCycleAfterInh = (((spTest.dutyCyclePeriod-1) *
                                    spTest._dutyCycleAfterInh + denseOn) /
                                   spTest.dutyCyclePeriod)

      # learning step
      spTest._adaptSynapses(onCellIndices, [], input_)

      # update boostFactor
      spTest._updateBoostFactors()
      boostFactors = spTest._firingBoostFactors

      # update dutyCycle and boost
      if ((spTest._iterNum+1) % 50) == 0:
#.........这里部分代码省略.........
开发者ID:08s011003,项目名称:nupic,代码行数:103,代码来源:inhibition_object_test.py

示例2: testAdaptSynapses

# 需要导入模块: from nupic.research.spatial_pooler import SpatialPooler [as 别名]
# 或者: from nupic.research.spatial_pooler.SpatialPooler import _adaptSynapses [as 别名]
  def testAdaptSynapses(self):
    sp = SpatialPooler(inputDimensions=[8],
                       columnDimensions=[4],
                       synPermInactiveDec=0.01,
                       synPermActiveInc=0.1,
                       synPermActiveSharedDec=0.02,
                       synPermOrphanDec=0.03)
    sp._synPermTrimThreshold = 0.05

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

    inputVector = numpy.array([1, 0, 0, 1, 1, 0, 1, 0])
    sharedInputs = numpy.where(numpy.array(
        [1, 0, 0, 0, 0, 0, 1, 0]) > 0)[0]
    activeColumns = numpy.array([0,1,2])

    sp._permanences = SparseMatrix(
        [[0.200, 0.120, 0.090, 0.040, 0.000, 0.000, 0.000, 0.000],
         [0.150, 0.000, 0.000, 0.000, 0.180, 0.120, 0.000, 0.450],
         [0.000, 0.000, 0.014, 0.000, 0.000, 0.000, 0.110, 0.000],
         [0.040, 0.000, 0.000, 0.000, 0.000, 0.000, 0.178, 0.000]])

    truePermanences = [
        [0.280, 0.110, 0.080, 0.140, 0.000, 0.000, 0.000, 0.000],
      #  Inc/Sh   Dec     Dec    Inc   -    -    -  -
        [0.230, 0.000, 0.000, 0.000, 0.280, 0.110, 0.000, 0.440],
      #  Inc/Sh    -      -     -      Inc    Dec    -     Dec  
        [0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.190, 0.000],
      #   -      -     Trim     -     -     -    Inc/Sh   - 
        [0.040, 0.000, 0.000, 0.000, 0.000, 0.000, 0.178, 0.000]]
      #   -      -      -    -      -    -    -    -   -   

    sp._adaptSynapses(inputVector,sharedInputs, activeColumns)
    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])

    # test orphan columns
    sp._potentialPools = SparseBinaryMatrix(
        [[1, 1, 1, 0, 0, 0, 0, 0],
         [0, 1, 1, 1, 0, 0, 0, 0],
         [0, 0, 1, 1, 1, 0, 0, 0],
         [1, 0, 0, 0, 0, 0, 1, 0]])

    inputVector = numpy.array([1, 0, 0, 1, 1, 0, 1, 0])
    sharedInputs = numpy.where(numpy.array([1, 0, 0, 1, 0, 0, 0, 0]) > 0)[0]
    activeColumns = numpy.array([0,1,2])

    sp._permanences = SparseMatrix(
        [[0.200, 0.120, 0.090, 0.000, 0.000, 0.000, 0.000, 0.000],
         [0.000, 0.017, 0.232, 0.400, 0.000, 0.000, 0.000, 0.000],
         [0.000, 0.000, 0.014, 0.051, 0.730, 0.000, 0.000, 0.000],
         [0.170, 0.000, 0.000, 0.000, 0.000, 0.000, 0.380, 0.000]])

    truePermanences = [
        [0.280, 0.110, 0.080, 0.000, 0.000, 0.000, 0.000, 0.000],
        #  Inc/Sh    Dec     Dec     -       -    -    -    -
        [0.000, 0.000, 0.222, 0.480, 0.000, 0.000, 0.000, 0.000],
        #     -      Trim     Dec  Inc/Sh   -       -      -      -
        [0.000, 0.000, 0.000, 0.131, 0.830, 0.000, 0.000, 0.000],
        #   -      -      Trim Inc/Sh  Inc     -     -     -
        [0.170, 0.000, 0.000, 0.000, 0.000, 0.000, 0.380, 0.000]]
        #  -    -      -      -      -       -       -     -

    sp._adaptSynapses(inputVector,sharedInputs, activeColumns)
    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])
开发者ID:Ueelee,项目名称:nupic,代码行数:76,代码来源:spatial_pooler_test.py


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