Skip to content

Commit

Permalink
Fix for Histogram lower computations (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvadym committed Nov 28, 2023
1 parent 89d9e32 commit c20852e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion analysis/tests/utility_analysis_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_multi_parameters(self):
expected_l0_error[i_configuration])

def test_generate_bucket_bounds(self):
self.assertLen(utility_analysis._generate_bucket_bounds(), 29)
self.assertLen(utility_analysis._generate_bucket_bounds(), 38)
self.assertEqual(utility_analysis._generate_bucket_bounds()[:10],
(0, 1, 10, 20, 50, 100, 200, 500, 1000, 2000))

Expand All @@ -304,6 +304,7 @@ def test_get_lower_bound(self):
self.assertEqual(utility_analysis._get_lower_bound(11), 10)
self.assertEqual(utility_analysis._get_lower_bound(20), 20)
self.assertEqual(utility_analysis._get_lower_bound(1234), 1000)
self.assertEqual(utility_analysis._get_upper_bound(10**13), -1)

def test_get_upper_bound(self):
self.assertEqual(utility_analysis._get_upper_bound(-1), 0)
Expand All @@ -313,6 +314,7 @@ def test_get_upper_bound(self):
self.assertEqual(utility_analysis._get_upper_bound(11), 20)
self.assertEqual(utility_analysis._get_upper_bound(20), 50)
self.assertEqual(utility_analysis._get_upper_bound(1234), 2000)
self.assertEqual(utility_analysis._get_upper_bound(10**13), -1)

def test_unnest_metrics(self):
input_data = self._get_per_partition_metrics(n_configurations=2)
Expand Down
12 changes: 6 additions & 6 deletions analysis/utility_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@

def _generate_bucket_bounds():
result = [0, 1]
for i in range(1, 10):
for i in range(1, 13):
result.append(10**i)
result.append(2 * 10**i)
result.append(5 * 10**i)
return tuple(result)


# Bucket bounds for metrics. UtilityReportHistogram.
# Bounds are logarithmic: [0, 1] + [1, 2, 5]*10**i , for i = 1, 10.
# Bucket bounds for metrics. UtilityReport histogram.
# Bounds are logarithmic: [0, 1] + [1, 2, 5]*10**i , for i = 1, 12
BUCKET_BOUNDS = _generate_bucket_bounds()


Expand Down Expand Up @@ -188,8 +188,8 @@ def _get_upper_bound(n: int) -> int:
if n < 0:
return 0
index = bisect.bisect_right(BUCKET_BOUNDS, n)
if index > len(BUCKET_BOUNDS):
return -1 # todo
if index >= len(BUCKET_BOUNDS):
return -1
return BUCKET_BOUNDS[index]


Expand All @@ -216,7 +216,7 @@ def _group_utility_reports(
'reports' contains the global report, i.e. which corresponds to all
partitions and reports that corresponds to partitions of some size range.
This function creates UtilityReportHistogram from reports by size range and
This function creates UtilityReport histogram from reports by size range and
sets it to the global report.
"""
global_report = None
Expand Down

0 comments on commit c20852e

Please sign in to comment.