slicing#

functions associated with data and dataset slicing

Module Contents#

noniid_slicing(dataset, num_clients, num_shards)

Slice a dataset for non-IID.

random_slicing(dataset, num_clients)

Slice a dataset randomly and equally for IID.

noniid_slicing(dataset, num_clients, num_shards)#

Slice a dataset for non-IID.

Parameters

Notes

The size of a shard equals to int(len(dataset)/num_shards). Each client will get int(num_shards/num_clients) shards.

Returns:

dict: { 0: indices of dataset, 1: indices of dataset, ..., k: indices of dataset }

random_slicing(dataset, num_clients)#

Slice a dataset randomly and equally for IID.

Args:

dataset (torch.utils.data.Dataset): a dataset for slicing. num_clients (int): the number of client.

Returns:

dict: { 0: indices of dataset, 1: indices of dataset, ..., k: indices of dataset }