fedlib.datasets.DatasetPartitioner

class fedlib.datasets.DatasetPartitioner(num_clients, random_seed=123, client_id_generator=None)[source]

Bases: ABC

An abstract base class for dataset splitting strategies that considers random states from both NumPy and PyTorch.

generate_client_datasets(train_dataset, test_dataset, **kwargs)[source]

Generates client keyconcepts from two keyconcepts that may interact with each other.

Parameters:
  • train_dataset – The training dataset to be split.

  • test_dataset – The testing dataset to be split.

Returns:

A list of ClientDataset instances.

Return type:

List[ClientDataset]

generate_client_ids()[source]

Generate a list of client IDs using the specified client ID generator.

Return type:

List[Any]

generate_paired_subsets(train_dataset, test_dataset)[source]

Generates paired subsets from two keyconcepts that may interact with each other.

Parameters:
  • train_dataset – The training dataset to be split.

  • test_dataset – The testing dataset to be split.

Returns:

A dictionary with client IDs as keys and tuples of corresponding training and testing subsets as values.

Return type:

Dict[str, Tuple[Subset, Subset]]

generate_subsets(dataset)[source]

Generates subsets from a single dataset.

Parameters:

dataset – The dataset to be split.

Returns:

A dictionary with client IDs as keys and corresponding subsets as values.

Return type:

Dict[str, Subset]

abstract split_dataset(dataset)[source]

Split a single dataset into multiple subsets, each keyed by a unique client_id.

Parameters:

dataset (Dataset) – The dataset to be split.

Returns:

A dictionary where the key is a string client_id and the

value is a Subset.

Return type:

Dict[str, Subset]

Return type:

List[Subset]

abstract split_datasets(train_dataset, test_dataset)[source]

Split two keyconcepts (e.g., training and testing keyconcepts) into multiple pairs of subsets, each keyed by a unique client_id.

Parameters:
  • train_dataset (Dataset) – The training dataset to be split.

  • test_dataset (Dataset) – The testing dataset to be split.

Returns:

A dictionary where the key is a string

client_id and the value is a tuple of two Subsets (training and testing).

Return type:

Dict[str, Tuple[Subset, Subset]]

Return type:

List[Tuple[Subset, Subset]]