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


Python SpatialPooler.getConnectedSynapses方法代码示例

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


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

示例1: testUpdatePermanencesForColumn

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

    permanencesList = [
      [ -0.10, 0.500, 0.400, 0.010, 0.020 ],
      [ 0.300, 0.010, 0.020, 0.120, 0.090 ],
      [ 0.070, 0.050, 1.030, 0.190, 0.060 ],
      [ 0.180, 0.090, 0.110, 0.010, 0.030 ],
      [ 0.200, 0.101, 0.050, -0.09, 1.100 ]]

    expectedPermanencesList = [
      [ 0.000, 0.500, 0.400, 0.000, 0.000],
       # Clip     -     -      Trim   Trim
      [0.300, 0.000, 0.000, 0.120, 0.090],
       # -    Trim   Trim   -     -
      [0.070, 0.050, 1.000, 0.190, 0.060],
       # -     -   Clip   -     -
      [0.180, 0.090, 0.110, 0.000, 0.000],
       # -     -    -      Trim   Trim
      [0.200, 0.101, 0.050, 0.000, 1.000]]
       # -      -     -      Clip   Clip

    expectedConnectedSynapsesList = [
      [0, 1, 1, 0, 0],
      [1, 0, 0, 1, 0],
      [0, 0, 1, 1, 0],
      [1, 0, 1, 0, 0],
      [1, 1, 0, 0, 1]]

    expectedConnectedCounts = [2, 2, 2, 2, 3]

    for i in xrange(5):
      permanences = np.array(permanencesList[i], dtype=realDType)
      expectedPermanences = np.array(expectedPermanencesList[i],
                                     dtype=realDType)
      expectedConnectedSynapses = expectedConnectedSynapsesList[i]

      sp._updatePermanencesForColumn(permanences, i, False)

      updatedPermanences = np.zeros(5, dtype=realDType)
      connectedSynapses = np.zeros(5, dtype=uintDType)
      connectedCounts = np.zeros(5, dtype=uintDType)

      sp.getPermanence(i, updatedPermanences)
      sp.getConnectedSynapses(i, connectedSynapses)
      sp.getConnectedCounts(connectedCounts)

      np.testing.assert_almost_equal(updatedPermanences, expectedPermanences)
      self.assertEqual(list(connectedSynapses), expectedConnectedSynapses)
      self.assertEqual(connectedCounts[i], expectedConnectedCounts[i])
开发者ID:Erichy94,项目名称:nupic,代码行数:54,代码来源:spatial_pooler_cpp_unit_test.py

示例2: SpatialPoolerAPITest

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

#.........这里部分代码省略.........
    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
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns])
    inParam = numpy.array([0.9, 0.99, 0.999, ]).astype(realType)
    self.sp.setActiveDutyCycles(inParam)
    outParam = numpy.zeros(numInputs).astype(realType)
    self.sp.getActiveDutyCycles(outParam)
    self.assertListEqual(list(inParam),list(outParam))


  def testGetMinOverlapDutyCycles(self):
    numInputs = 3
    numColumns = 3
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns])
    inParam = numpy.array([0.01, 0.02, 0.035, ]).astype(realType)
    self.sp.setMinOverlapDutyCycles(inParam)
    outParam = numpy.zeros(numInputs).astype(realType)
    self.sp.getMinOverlapDutyCycles(outParam)
    self.assertListEqual(list(inParam),list(outParam))


  def testGetPotential(self):
    self.sp.initialize(columnDimensions=[3], inputDimensions=[3])
    numInputs = 3
    numColumns = 3
    self.sp.initialize(columnDimensions=[numInputs], 
                       inputDimensions=[numColumns])
    inParam1 = numpy.array([1, 0, 1]).astype(uintType)
    self.sp.setPotential(0, inParam1)
    inParam2 = numpy.array([1, 1, 0]).astype(uintType)
    self.sp.setPotential(1, inParam2)

    outParam1 = numpy.zeros(numInputs).astype(uintType)
    outParam2 = numpy.zeros(numInputs).astype(uintType)
    self.sp.getPotential(0, outParam1)
    self.sp.getPotential(1, outParam2)

    self.assertListEqual(list(inParam1),list(outParam1))
    self.assertListEqual(list(inParam2),list(outParam2))


  def testGetConnectedSynapses(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)
    trueConnected = numpy.array([0, 0, 0, 1, 1])
    self.sp.setSynPermConnected(0.1)
    self.sp.setPermanence(0,inParam)
    outParam = numpy.zeros(numInputs).astype(uintType)
    self.sp.getConnectedSynapses(0, outParam)
    self.assertListEqual(list(trueConnected),list(outParam))


  def testGetConnectedCounts(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.11]).astype(realType)
    trueConnectedCount = 2
    self.sp.setSynPermConnected(0.1)
    self.sp.setPermanence(0, inParam)
    outParam = numpy.zeros(numInputs).astype(uintType)
    self.sp.getConnectedCounts(outParam)
    self.assertEqual(trueConnectedCount, outParam[0])


  def assertListAlmostEqual(self, alist, blist):
    self.assertEqual(len(alist), len(blist))
    for (a,b) in zip(alist,blist):
      diff = abs(a - b)
      self.assertLess(diff,1e-5)
开发者ID:gaoxuesong,项目名称:nupic,代码行数:104,代码来源:spatial_pooler_py_api_test.py


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