Skip to content

Commit

Permalink
add report for all partitinoer
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentDS committed Dec 7, 2023
1 parent be21ab4 commit e315584
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fedlab/utils/dataset/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,18 @@ def partition_report(targets, data_indices, class_num=None, verbose=True, file=N
Check ``data_indices`` may look like:
>>> data_indices
{0: array([8, 6, 5, 7, 2]),
1: array([ 3, 10, 14, 4, 1]),
2: array([13, 9, 12, 11, 0])}
{0: array([ 4, 1, 14, 8, 5]),
1: array([ 0, 13, 12, 3, 2]),
2: array([10, 9, 7, 6, 11])}
Now generate partition report for each client and each class:
>>> partition_report(labels, data_indices, class_num=class_num, verbose=True, file=None)
Class sample statistics:
client,class0,class1,class2,class3,Amount
Client 0,0.200,0.00,0.200,0.600,5
Client 1,0.400,0.200,0.200,0.200,5
Client 2,0.00,0.400,0.400,0.200,5
cid class-0 class-1 class-2 class-3 TotalAmount
0 0 3 2 0 0 5
1 1 1 1 1 2 5
2 2 3 1 1 0 5
"""
if not isinstance(targets, np.ndarray):
Expand Down
1 change: 1 addition & 0 deletions fedlab/utils/dataset/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def __init__(self, targets, num_clients,
self.client_dict = self._perform_partition()
# get sample number count for each client
self.client_sample_count = F.samples_num_count(self.client_dict, self.num_clients)
self.stats_report = F.partition_report(targets, self.client_dict, class_num=self.num_classes, verbose=False)

def _perform_partition(self):
if self.partition == "noniid-#label":
Expand Down

0 comments on commit e315584

Please sign in to comment.