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


Python RandomDistributedScalarEncoder._countOverlapIndices方法代码示例

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


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

示例1: testCountOverlapIndices

# 需要导入模块: from nupic.encoders.random_distributed_scalar import RandomDistributedScalarEncoder [as 别名]
# 或者: from nupic.encoders.random_distributed_scalar.RandomDistributedScalarEncoder import _countOverlapIndices [as 别名]
  def testCountOverlapIndices(self):
    """
    Test that the internal method _countOverlapIndices works as expected.
    """
    # Create a fake set of encodings.
    encoder = RandomDistributedScalarEncoder(name="encoder", resolution=1.0,
                                             w=5, n=5*20)
    midIdx = encoder._maxBuckets/2
    encoder.bucketMap[midIdx-2] = numpy.array(range(3, 8))
    encoder.bucketMap[midIdx-1] = numpy.array(range(4, 9))
    encoder.bucketMap[midIdx]   = numpy.array(range(5, 10))
    encoder.bucketMap[midIdx+1] = numpy.array(range(6, 11))
    encoder.bucketMap[midIdx+2] = numpy.array(range(7, 12))
    encoder.bucketMap[midIdx+3] = numpy.array(range(8, 13))
    encoder.minIndex = midIdx - 2
    encoder.maxIndex = midIdx + 3

    # Indices must exist
    with self.assertRaises(ValueError):
      encoder._countOverlapIndices(midIdx-3, midIdx-2)
    with self.assertRaises(ValueError):
      encoder._countOverlapIndices(midIdx-2, midIdx-3)

    # Test some overlaps
    self.assertEqual(encoder._countOverlapIndices(midIdx-2, midIdx-2), 5,
                     "_countOverlapIndices didn't work")
    self.assertEqual(encoder._countOverlapIndices(midIdx-1, midIdx-2), 4,
                     "_countOverlapIndices didn't work")
    self.assertEqual(encoder._countOverlapIndices(midIdx+1, midIdx-2), 2,
                     "_countOverlapIndices didn't work")
    self.assertEqual(encoder._countOverlapIndices(midIdx-2, midIdx+3), 0,
                     "_countOverlapIndices didn't work")
开发者ID:leotam,项目名称:cupic,代码行数:34,代码来源:random_distributed_scalar_test.py


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