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


Python SpatialPooler.setPermanence方法代码示例

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


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

示例1: testCalculateOverlap

# 需要导入模块: from nupic.bindings.algorithms import SpatialPooler [as 别名]
# 或者: from nupic.bindings.algorithms.SpatialPooler import setPermanence [as 别名]
  def testCalculateOverlap(self):
    sp = SpatialPooler(inputDimensions = [10],
                       columnDimensions = [5])

    permanences = [
      [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]
    ]
    inputVectors = [
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],
      [1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
      [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
    ]
    expectedOverlaps = [
      [0,  0,  0,  0,  0],
      [10, 8,  6,  4,  2],
      [5,  4,  3,  2,  1],
      [5,  3,  1,  0,  0],
      [1,  1,  1,  1,  1]
    ]

    for column, permanence in enumerate(permanences):
      sp.setPermanence(column, np.array(permanence, dtype=realDType))

    for inputVector, expectedOverlap in zip(inputVectors, expectedOverlaps):
      inputVector = np.array(inputVector, dtype=uintDType)
      overlap = set(sp._calculateOverlap(inputVector))
      expected = set(expectedOverlap)
      self.assertSetEqual(overlap, expected,
                          "Input: {0}\tExpected: {1}\tActual: {2}".format(
                            inputVector, expected, overlap))
开发者ID:Erichy94,项目名称:nupic,代码行数:38,代码来源:spatial_pooler_cpp_unit_test.py

示例2: convertSP

# 需要导入模块: from nupic.bindings.algorithms import SpatialPooler [as 别名]
# 或者: from nupic.bindings.algorithms.SpatialPooler import setPermanence [as 别名]
  def convertSP(self, pySp, newSeed):
    columnDim = pySp._columnDimensions
    inputDim = pySp._inputDimensions
    numInputs = pySp.getNumInputs()
    numColumns = pySp.getNumColumns()
    cppSp = CPPSpatialPooler(inputDim,columnDim)
    cppSp.setPotentialRadius(pySp.getPotentialRadius())
    cppSp.setPotentialPct(pySp.getPotentialPct())
    cppSp.setGlobalInhibition(pySp.getGlobalInhibition())

    numActiveColumnsPerInhArea = pySp.getNumActiveColumnsPerInhArea()
    localAreaDensity = pySp.getLocalAreaDensity()
    if (numActiveColumnsPerInhArea > 0):
      cppSp.setNumActiveColumnsPerInhArea(numActiveColumnsPerInhArea)
    else:
      cppSp.setLocalAreaDensity(localAreaDensity)

    cppSp.setStimulusThreshold(pySp.getStimulusThreshold())
    cppSp.setInhibitionRadius(pySp.getInhibitionRadius())
    cppSp.setDutyCyclePeriod(pySp.getDutyCyclePeriod())
    cppSp.setMaxBoost(pySp.getMaxBoost())
    cppSp.setIterationNum(pySp.getIterationNum())
    cppSp.setIterationLearnNum(pySp.getIterationLearnNum())
    cppSp.setSpVerbosity(pySp.getSpVerbosity())
    cppSp.setUpdatePeriod(pySp.getUpdatePeriod())
    cppSp.setSynPermTrimThreshold(pySp.getSynPermTrimThreshold())
    cppSp.setSynPermActiveInc(pySp.getSynPermActiveInc())
    cppSp.setSynPermInactiveDec(pySp.getSynPermInactiveDec())
    cppSp.setSynPermBelowStimulusInc(pySp.getSynPermBelowStimulusInc())
    cppSp.setSynPermConnected(pySp.getSynPermConnected())
    cppSp.setMinPctOverlapDutyCycles(pySp.getMinPctOverlapDutyCycles())
    cppSp.setMinPctActiveDutyCycles(pySp.getMinPctActiveDutyCycles())

    boostFactors = numpy.zeros(numColumns).astype(realType)
    pySp.getBoostFactors(boostFactors)
    cppSp.setBoostFactors(boostFactors)

    overlapDuty = numpy.zeros(numColumns).astype(realType)
    pySp.getOverlapDutyCycles(overlapDuty)
    cppSp.setOverlapDutyCycles(overlapDuty)

    activeDuty = numpy.zeros(numColumns).astype(realType)
    pySp.getActiveDutyCycles(activeDuty)
    cppSp.setActiveDutyCycles(activeDuty)

    minOverlapDuty = numpy.zeros(numColumns).astype(realType)
    pySp.getMinOverlapDutyCycles(minOverlapDuty)
    cppSp.setMinOverlapDutyCycles(minOverlapDuty)

    minActiveDuty = numpy.zeros(numColumns).astype(realType)
    pySp.getMinActiveDutyCycles(minActiveDuty)
    cppSp.setMinActiveDutyCycles(minActiveDuty)

    for i in xrange(numColumns):
      potential = numpy.zeros(numInputs).astype(uintType)
      pySp.getPotential(i, potential)
      cppSp.setPotential(i, potential)

      perm = numpy.zeros(numInputs).astype(realType)
      pySp.getPermanence(i, perm)
      cppSp.setPermanence(i, perm)

    pySp._random = NupicRandom(newSeed)
    cppSp.seed_(newSeed)
    return cppSp
开发者ID:MaxDavila,项目名称:nupic,代码行数:67,代码来源:spatial_pooler_compatability_test.py

示例3: SpatialPoolerAPITest

# 需要导入模块: from nupic.bindings.algorithms import SpatialPooler [as 别名]
# 或者: from nupic.bindings.algorithms.SpatialPooler import setPermanence [as 别名]

#.........这里部分代码省略.........
    self.assertAlmostEqual(inParam, outParam)


  def testGetSynPermBelowStimulusInc(self):
    inParam = 0.0898
    self.sp.setSynPermBelowStimulusInc(inParam)
    outParam = self.sp.getSynPermBelowStimulusInc()
    self.assertAlmostEqual(inParam, outParam)


  def testGetSynPermConnected(self):
    inParam = 0.514
    self.sp.setSynPermConnected(inParam)
    outParam = self.sp.getSynPermConnected()
    self.assertAlmostEqual(inParam, outParam)


  def testGetMinPctOverlapDutyCycles(self):
    inParam = 0.11122
    self.sp.setMinPctOverlapDutyCycles(inParam)
    outParam = self.sp.getMinPctOverlapDutyCycles()
    self.assertAlmostEqual(inParam, outParam)


  def testGetPermanence(self):
    numInputs = 5
    numColumns = 5
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns], 
                       potentialRadius=1, 
                       potentialPct=1)
    inParam = numpy.array(
      [0.06, 0.07, 0.08, 0.12, 0.13]).astype(realType)
    self.sp.setPermanence(0,inParam)
    outParam = numpy.zeros(numInputs).astype(realType)
    self.sp.getPermanence(0, outParam)
    self.assertListEqual(list(inParam),list(outParam))


  def testGetBoostFactors(self):
    numInputs = 3
    numColumns = 3
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns])
    inParam = numpy.array([1, 1.2, 1.3, ]).astype(realType)
    self.sp.setBoostFactors(inParam)
    outParam = numpy.zeros(numInputs).astype(realType)
    self.sp.getBoostFactors(outParam)
    self.assertListEqual(list(inParam),list(outParam))


  def testGetOverlapDutyCycles(self):
    numInputs = 3
    numColumns = 3
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns])
    inParam = numpy.array([0.9, 0.3, 0.1]).astype(realType)
    self.sp.setOverlapDutyCycles(inParam)
    outParam = numpy.zeros(numInputs).astype(realType)
    self.sp.getOverlapDutyCycles(outParam)
    self.assertListEqual(list(inParam),list(outParam))


  def testGetActiveDutyCycles(self):
    numInputs = 3
    numColumns = 3
开发者ID:gaoxuesong,项目名称:nupic,代码行数:70,代码来源:spatial_pooler_py_api_test.py


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