LinearPartitioner#
- class LinearPartitioner(num_partitions: int)[source]#
Bases:
SizePartitioner
Partitioner creates partitions of size that are linearly correlated with id.
The amount of data each client gets is linearly correlated with the partition ID. For instance, if the IDs range from 1 to M, client with ID 1 gets 1 unit of data, client 2 gets 2 units, and so on, up to client M which gets M units.
- Parameters:
num_partitions (int) – The total number of partitions that the data will be divided into.
Examples
>>> from flwr_datasets import FederatedDataset >>> from flwr_datasets.partitioner import LinearPartitioner >>> >>> partitioner = LinearPartitioner(num_partitions=10) >>> fds = FederatedDataset(dataset="mnist", partitioners={"train": partitioner}) >>> partition = fds.load_partition(0)
Methods
Check if a dataset has been assigned to the partitioner.
load_partition
(partition_id)Load a single partition based on the partition index.
Attributes
Dataset property.
Total number of partitions.
Node id to the list of indices.
Node id to the number of samples.
- property dataset: Dataset#
Dataset property.
- is_dataset_assigned() bool #
Check if a dataset has been assigned to the partitioner.
This method returns True if a dataset is already set for the partitioner, otherwise, it returns False.
- Returns:
dataset_assigned – True if a dataset is assigned, otherwise False.
- Return type:
bool
- load_partition(partition_id: int) Dataset #
Load a single partition based on the partition index.
The number of samples is dependent on the partition partition_id.
- Parameters:
partition_id (int) – the index that corresponds to the requested partition
- Returns:
dataset_partition – single dataset partition
- Return type:
Dataset
- property num_partitions: int#
Total number of partitions.
- property partition_id_to_indices: Dict[int, List[int]]#
Node id to the list of indices.
- property partition_id_to_size: Dict[int, int]#
Node id to the number of samples.