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
9 changes: 6 additions & 3 deletions dpsynth/discrete_mechanisms/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,16 @@ def supporting_cliques(

Args:
domain: The domain of the dataset.
workload: A workload specification. Defaults to all three-way marginals.
workload: A workload specification. Defaults to all three-way marginals,
or the maximum possible degree for fewer than three columns.
max_marginal_size: The maximum domain size of a clique to include.

Returns:
A list of cliques from the workload whose domain size is within the limit.
"""
if workload is None:
cliques = list(itertools.combinations(domain.attributes, 3))
degree = min(3, len(domain.attributes))
cliques = list(itertools.combinations(domain.attributes, degree))
elif isinstance(workload, Mapping):
cliques = [tuple(cl) for cl in workload.keys()]
else:
Expand Down Expand Up @@ -458,7 +460,8 @@ def compiled_workload(
"""

if workload is None:
workload = list(itertools.combinations(domain.attributes, 3))
degree = min(3, len(domain.attributes))
workload = list(itertools.combinations(domain.attributes, degree))

if not isinstance(workload, Mapping):
workload = {tuple(cl): 1.0 for cl in workload}
Expand Down
12 changes: 12 additions & 0 deletions tests/discrete_mechanisms/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def test_supporting_cliques(self):
self.assertCountEqual(
cliques, list(itertools.combinations(domain.attributes, 3))
)
# Default workload with two columns.
two_column_domain = mbi.Domain(["a", "b"], [3, 3])
cliques = common.supporting_cliques(two_column_domain, workload=None)
self.assertCountEqual(cliques, [("a", "b")])
# List workload.
cliques = common.supporting_cliques(domain, [("a", "b"), ("c", "d")])
self.assertCountEqual(cliques, [("a", "b"), ("c", "d")])
Expand All @@ -105,6 +109,14 @@ def test_compiled_workload_with_lists(self):
for cl in workload.keys():
self.assertIsInstance(cl, tuple)

def test_compiled_workload_default_with_two_columns(self):
domain = mbi.Domain(["a", "b"], [3, 3])
workload = common.compiled_workload(domain, None)
self.assertCountEqual(
workload.keys(),
[("a",), ("b",), ("a", "b")],
)

def test_precompute_marginals_standard_and_jax(self):
domain = mbi.Domain(["a", "b"], [3, 4])
data = mbi.Dataset.synthetic(domain, N=100)
Expand Down
Loading