• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python reservoir._ReservoirBucket函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tensorflow.python.summary.impl.reservoir._ReservoirBucket函数的典型用法代码示例。如果您正苦于以下问题:Python _ReservoirBucket函数的具体用法?Python _ReservoirBucket怎么用?Python _ReservoirBucket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testRemovesItems

 def testRemovesItems(self):
   b = reservoir._ReservoirBucket(100)
   for i in xrange(10):
     b.AddItem(i)
   self.assertEqual(len(b.Items()), 10)
   self.assertEqual(b._num_items_seen, 10)
   self.assertEqual(b.FilterItems(lambda x: x <= 7), 2)
   self.assertEqual(len(b.Items()), 8)
   self.assertEqual(b._num_items_seen, 8)
开发者ID:niclar,项目名称:tensorflow,代码行数:9,代码来源:reservoir_test.py


示例2: testMaintainsOrder

 def testMaintainsOrder(self):
   b = reservoir._ReservoirBucket(100)
   for i in xrange(10000):
     b.AddItem(i)
   items = b.Items()
   prev = None
   for item in items:
     self.assertTrue(item > prev)
     prev = item
开发者ID:niclar,项目名称:tensorflow,代码行数:9,代码来源:reservoir_test.py


示例3: testRemovesItemsWhenItemsAreReplaced

    def testRemovesItemsWhenItemsAreReplaced(self):
        b = reservoir._ReservoirBucket(100)
        for i in xrange(10000):
            b.AddItem(i)
        self.assertEqual(b._num_items_seen, 10000)

        # Remove items
        num_removed = b.FilterItems(lambda x: x <= 7)
        self.assertGreater(num_removed, 92)
        self.assertEqual([], [item for item in b.Items() if item > 7])
        self.assertEqual(b._num_items_seen, int(round(10000 * (1 - float(num_removed) / 100))))
开发者ID:CCChaos,项目名称:tensorflow,代码行数:11,代码来源:reservoir_test.py


示例4: testLazyFunctionEvaluationAndAlwaysKeepLast

  def testLazyFunctionEvaluationAndAlwaysKeepLast(self):

    class FakeRandom(object):

      def randint(self, a, b):  # pylint:disable=unused-argument
        return 999

    class Incrementer(object):

      def __init__(self):
        self.n = 0

      def increment_and_double(self, x):
        self.n += 1
        return x * 2

    # We've mocked the randomness generator, so that once it is full, the last
    # item will never get durable reservoir inclusion. Since always_keep_last is
    # false, the function should only get invoked 100 times while filling up
    # the reservoir. This laziness property is an essential performance
    # optimization.
    b = reservoir._ReservoirBucket(100, FakeRandom(), always_keep_last=False)
    incrementer = Incrementer()
    for i in xrange(1000):
      b.AddItem(i, incrementer.increment_and_double)
    self.assertEqual(incrementer.n, 100)
    self.assertEqual(b.Items(), [x * 2 for x in xrange(100)])

    # This time, we will always keep the last item, meaning that the function
    # should get invoked once for every item we add.
    b = reservoir._ReservoirBucket(100, FakeRandom(), always_keep_last=True)
    incrementer = Incrementer()

    for i in xrange(1000):
      b.AddItem(i, incrementer.increment_and_double)
    self.assertEqual(incrementer.n, 1000)
    self.assertEqual(b.Items(), [x * 2 for x in xrange(99)] + [999 * 2])
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:37,代码来源:reservoir_test.py


示例5: testBucketReservoirSamplingViaStatisticalProperties

  def testBucketReservoirSamplingViaStatisticalProperties(self):
    # Not related to a 'ReservoirBucket', but instead number of buckets we put
    # samples into for testing the shape of the distribution
    b = reservoir._ReservoirBucket(_max_size=self.samples)
    # add one extra item because we always keep the most recent item, which
    # would skew the distribution; we can just slice it off the end instead.
    for i in xrange(self.total + 1):
      b.AddItem(i)

    divbins = [0] * self.n_buckets
    modbins = [0] * self.n_buckets
    # Slice off the last item when we iterate.
    for item in b.Items()[0:-1]:
      divbins[item // self.total_per_bucket] += 1
      modbins[item % self.n_buckets] += 1

    for bucket_index in xrange(self.n_buckets):
      divbin = divbins[bucket_index]
      modbin = modbins[bucket_index]
      self.AssertBinomialQuantity(divbin)
      self.AssertBinomialQuantity(modbin)
开发者ID:niclar,项目名称:tensorflow,代码行数:21,代码来源:reservoir_test.py


示例6: testDoesntOverfill

 def testDoesntOverfill(self):
   b = reservoir._ReservoirBucket(10)
   for i in xrange(1000):
     b.AddItem(i)
   self.assertEqual(len(b.Items()), 10)
   self.assertEqual(b._num_items_seen, 1000)
开发者ID:niclar,项目名称:tensorflow,代码行数:6,代码来源:reservoir_test.py


示例7: testFillToSize

 def testFillToSize(self):
   b = reservoir._ReservoirBucket(100)
   for i in xrange(100):
     b.AddItem(i)
   self.assertEqual(b.Items(), list(xrange(100)))
   self.assertEqual(b._num_items_seen, 100)
开发者ID:niclar,项目名称:tensorflow,代码行数:6,代码来源:reservoir_test.py


示例8: testEmptyBucket

 def testEmptyBucket(self):
   b = reservoir._ReservoirBucket(1)
   self.assertFalse(b.Items())
开发者ID:niclar,项目名称:tensorflow,代码行数:3,代码来源:reservoir_test.py


示例9: testSizeRequirement

 def testSizeRequirement(self):
   with self.assertRaises(ValueError):
     reservoir._ReservoirBucket(-1)
   with self.assertRaises(ValueError):
     reservoir._ReservoirBucket(10.3)
开发者ID:niclar,项目名称:tensorflow,代码行数:5,代码来源:reservoir_test.py


示例10: testSizeZeroBucket

 def testSizeZeroBucket(self):
   b = reservoir._ReservoirBucket(0)
   for i in xrange(20):
     b.AddItem(i)
     self.assertEqual(b.Items(), list(range(i + 1)))
   self.assertEqual(b._num_items_seen, 20)
开发者ID:niclar,项目名称:tensorflow,代码行数:6,代码来源:reservoir_test.py


示例11: testSizeOneBucket

 def testSizeOneBucket(self):
   b = reservoir._ReservoirBucket(1)
   for i in xrange(20):
     b.AddItem(i)
     self.assertEqual(b.Items(), [i])
   self.assertEqual(b._num_items_seen, 20)
开发者ID:niclar,项目名称:tensorflow,代码行数:6,代码来源:reservoir_test.py


示例12: testKeepsLatestItem

 def testKeepsLatestItem(self):
   b = reservoir._ReservoirBucket(5)
   for i in xrange(100):
     b.AddItem(i)
     last = b.Items()[-1]
     self.assertEqual(last, i)
开发者ID:niclar,项目名称:tensorflow,代码行数:6,代码来源:reservoir_test.py


示例13: testFillToSize

 def testFillToSize(self):
   b = reservoir._ReservoirBucket(100)
   for i in xrange(100):
     b.AddItem(i)
   self.assertEqual(b.Items(), range(100))
开发者ID:debaratidas1994,项目名称:tensorflow,代码行数:5,代码来源:reservoir_test.py


示例14: testSizeZeroBucket

 def testSizeZeroBucket(self):
   b = reservoir._ReservoirBucket(0)
   for i in xrange(20):
     b.AddItem(i)
     self.assertEqual(b.Items(), range(i+1))
开发者ID:debaratidas1994,项目名称:tensorflow,代码行数:5,代码来源:reservoir_test.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python plugin_asset.get_plugin_asset函数代码示例发布时间:2022-05-27
下一篇:
Python summary.scalar函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap