Skip to content

Commit

Permalink
Fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
haoyueping committed May 30, 2020
1 parent 6b06f50 commit 9f476eb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions DataSynthesizer/lib/PrivBayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,20 @@ def construct_noisy_conditional_distributions(bayesian_network, encoded_dataset,

if idx < k:
stats = noisy_dist_of_kplus1_attributes.copy().loc[:, parents + [child, 'count']]
stats = stats.groupby(parents + [child], as_index=False).sum()
else:
stats = get_noisy_distribution_of_attributes(parents + [child], encoded_dataset, epsilon)
stats = stats.loc[:, parents + [child, 'count']]

stats = DataFrame(stats.loc[:, parents + [child, 'count']].groupby(parents + [child]).sum())
for parents_instance, stats_sub in stats.groupby(parents):
stats_sub = stats_sub.sort_values(by=child)
dist = normalize_given_distribution(stats_sub['count']).tolist()

if len(parents) == 1:
for parent_instance in stats.index.levels[0]:
dist = normalize_given_distribution(stats.loc[parent_instance]['count']).tolist()
conditional_distributions[child][str([parent_instance])] = dist
else:
for parents_instance in product(*stats.index.levels[:-1]):
dist = normalize_given_distribution(stats.loc[parents_instance]['count']).tolist()
conditional_distributions[child][str(list(parents_instance))] = dist
if len(parents) == 1:
parents_key = str([parents_instance])
else:
parents_key = str(list(parents_instance))

conditional_distributions[child][parents_key] = dist

return conditional_distributions

0 comments on commit 9f476eb

Please sign in to comment.