def test_quantile_query_raises_inconsistent(self):
   hierarchical_histogram = _create_noisy_hierarchical_histogram(
       arity=2, depth=2)
   decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
       hierarchical_histogram, 0, 2)
   with self.assertRaises(ValueError):
     decoder.quantile_query(0.5)
Example #2
0
 def test_quantile_query_raises_invalid_quantile(self, q):
     hierarchical_histogram = _create_hierarchical_histogram(arity=2,
                                                             depth=2)
     decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
         hierarchical_histogram)
     with self.assertRaises(ValueError):
         decoder.quantile_query(q)
Example #3
0
 def test_range_query_raises(self, left, right):
     hierarchical_histogram = _create_hierarchical_histogram(arity=2,
                                                             depth=2)
     decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
         hierarchical_histogram)
     with self.assertRaises(ValueError):
         decoder.range_query(left, right)
Example #4
0
 def test_node_query_raises(self, layer, index):
     hierarchical_histogram = _create_hierarchical_histogram(arity=2,
                                                             depth=1)
     decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
         hierarchical_histogram)
     with self.assertRaises(ValueError):
         decoder.node_query(layer, index)
  def test_enforce_consistency(self, arity, depth, scale):
    noisy_hierarchical_histogram = _create_noisy_hierarchical_histogram(
        arity, depth, scale)
    decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
        noisy_hierarchical_histogram, 0, arity**(depth - 1))
    decoder.enforce_consistency()

    self.assertTrue(decoder._check_consistency())
 def test_check_consistency(self, is_consistent, arity, depth):
   if is_consistent:
     hierarchical_histogram = _create_hierarchical_histogram(arity, depth)
   else:
     hierarchical_histogram = _create_noisy_hierarchical_histogram(
         arity, depth)
   decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
       hierarchical_histogram, 0, arity**(depth - 1))
   self.assertEqual(decoder._check_consistency(), is_consistent)
Example #7
0
 def test_range_query(self, arity, depth, use_efficient, left, right):
     hierarchical_histogram = _create_hierarchical_histogram(arity, depth)
     decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
         hierarchical_histogram, use_efficient=use_efficient)
     range_sum = decoder.range_query(left, right)
     # The test histogram is from 0 to the length of the histogram, so the
     # expected node value is as follows.
     expected_range_sum = (left + right) * (right - left + 1) // 2
     self.assertAllClose(range_sum, expected_range_sum)
Example #8
0
    def test_node_query(self, arity, depth, use_efficient, layer, index):
        hierarchical_histogram = _create_hierarchical_histogram(arity, depth)
        decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
            hierarchical_histogram, use_efficient=use_efficient)
        node_value = decoder.node_query(layer, index)
        # The test histogram is from 0 to the length of the histogram, so the
        # expected node value is as follows.
        expected_node_value = 0.
        reverse_depth = depth - layer - 1
        expansion_factor = arity**reverse_depth
        for i in range(index * expansion_factor,
                       (index + 1) * expansion_factor):
            expected_node_value += i

        self.assertAllClose(node_value, expected_node_value)
 def test_quantile_query(self, arity, q, expected_quantile):
   hierarchical_histogram = _create_hierarchical_histogram(arity, depth=4)
   decoder = hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
       hierarchical_histogram, 0, arity**3)
   quantile = decoder.quantile_query(q)
   self.assertEqual(quantile, expected_quantile)
 def test_init_raises(self, hierarchical_histogram):
   with self.assertRaises(ValueError):
     hierarchical_histogram_decoder.HierarchicalHistogramDecoder(
         hierarchical_histogram, 0, 0)