Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dpsynth/discrete_mechanisms/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def build_best_clique_tree(
if len(cl) == 2 and tuple(sorted(cl)) in supported
)

if score > best_score:
if best_tree is None or score > best_score:
best_score = score
best_tree = tree
assert best_tree is not None
Expand Down
13 changes: 13 additions & 0 deletions tests/discrete_mechanisms/swift_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ def test_select_queries(self):
self.assertAlmostEqual(selected[('a', 'c')], expected_budget_ac)
self.assertAlmostEqual(selected[('b', 'c')], expected_budget_bc)

def test_select_queries_nonpositive_errors(self):
errors = {('a', 'b'): 0.0, ('b', 'c'): -1.0, ('a', 'c'): -2.0}
domain = mbi.Domain(['a', 'b', 'c'], [2, 3, 4])
candidates = {key: 1.0 for key in errors}
gdp_budget = 100.0

selected, jtree = swift.select_queries(
errors, candidates, domain, max_clique_size=100, gdp_budget=gdp_budget
)

self.assertNotEmpty(jtree.nodes)
self.assertAlmostEqual(sum(selected.values()), gdp_budget)

def test_best_subset_and_allocation(self):
candidates = [
swift_utils.Candidate(id='a', error=1.0, size=1.0, weight=1.0),
Expand Down