class_docstr: A container for items from a stream, that implements reservoir sampling.
  
  It always stores the most recent item as its final item.
docstr: Filter items in a ReservoirBucket, using a filtering function.
  
  Filtering items from the reservoir bucket must update the
  internal state variable self._num_items_seen, which is used for determining
  the rate of replacement in reservoir sampling. Ideally, self._num_items_seen
  would contain the exact number of items that have ever seen by the
  ReservoirBucket and satisfy filterFn. However, the ReservoirBucket does not
  have access to all items seen -- it only has access to the subset of items
  that have survived sampling (self.items). Therefore, we estimate
  self._num_items_seen by scaling it by the same ratio as the ratio of items
  not removed from self.items.
  
  Args:
    filterFn: A function that returns True for items to be kept.
  
  Returns:
    The number of items removed from the bucket.
docstr_tok: ["Filter","items","in","a","ReservoirBucket",",","using","a","filtering","function",".","Filtering","items","from","the","reservoir","bucket","must","update","the","internal","state","variable","self._num_items_seen",",","which","is","used","for","determining","the","rate","of","replacement","in","reservoir","sampling",".","Ideally",",","self._num_items_seen","would","contain","the","exact","number","of","items","that","have","ever","seen","by","the","ReservoirBucket","and","satisfy","filterFn",".","However",",","the","ReservoirBucket","does","not","have","access","to","all","items","seen","--","it","only","has","access","to","the","subset","of","items","that","have","survived","sampling","(","self.items",")",".","Therefore",",","we","estimate","self._num_items_seen","by","scaling","it","by","the","same","ratio","as","the","ratio","of","items","not","removed","from","self.items",".","Args",":","filterFn",":","A","function","that","returns","True","for","items","to","be","kept",".","Returns",":","The","number","of","items","removed","from","the","bucket","."]
code: def FilterItems(self, filterFn):
      """Filter items in a ReservoirBucket, using a filtering function.
  
      Filtering items from the reservoir bucket must update the
      internal state variable self._num_items_seen, which is used for determining
      the rate of replacement in reservoir sampling. Ideally, self._num_items_seen
      would contain the exact number of items that have ever seen by the
      ReservoirBucket and satisfy filterFn. However, the ReservoirBucket does not
      have access to all items seen -- it only has access to the subset of items
      that have survived sampling (self.items). Therefore, we estimate
      self._num_items_seen by scaling it by the same ratio as the ratio of items
      not removed from self.items.
  
      Args:
        filterFn: A function that returns True for items to be kept.
  
      Returns:
        The number of items removed from the bucket.
      """
      with self._mutex:
          size_before = len(self.items)
          self.items = list(filter(filterFn, self.items))
          size_diff = size_before - len(self.items)
  
          # Estimate a correction the number of items seen
          prop_remaining = (
              len(self.items) / float(size_before)
              if size_before > 0
              else 0
          )
          self._num_items_seen = int(
              round(self._num_items_seen * prop_remaining)
          )
          return size_diff
  
file_path: tensorboard/tensorboard/backend/event_processing/reservoir.py
imports: import collections
  import random
  import threading
label_desc: Use image node_id 3 for calling the _ReservoirBucket obj's underlying member method code with example usage: obj.FilterItems(filterFn) and returns: size_diff