fl4health.clients.fed_pca_client module

class FedPCAClient(data_path, device, model_save_path)[source]

Bases: NumPyClient

__init__(data_path, device, model_save_path)[source]

Client that facilitates the execution of federated PCA.

Parameters:
  • data_path (Path) – path to the data to be used to load the data for client-side training

  • device (torch.device) – Device indicator for where to send the model, batches, labels etc. Often ‘cpu’ or ‘cuda’

  • model_save_path (Path) – Path to save the PCA components for use later, perhaps in dimensionality reduction

evaluate(parameters, config)[source]

Evaluate merged principal components on the local validation set.

Parameters:
  • parameters (NDArrays) – Server-merged principal components.

  • config (dict[str, Scalar]) – Config file.

Return type:

tuple[float, int, dict[str, Union[bool, bytes, float, int, str]]]

fit(parameters, config)[source]

Perform PCA using the locally held dataset.

Return type:

tuple[List[ndarray[Any, dtype[Any]]], int, dict[str, Union[bool, bytes, float, int, str]]]

generate_hash(length=8)[source]
Return type:

str

get_data_loaders(config)[source]

User defined method that returns a PyTorch Train DataLoader and a PyTorch Validation DataLoader

Return type:

tuple[DataLoader, DataLoader]

get_data_tensor(data_loader)[source]
Return type:

Tensor

get_model(config)[source]

Returns an instance of the PCAModule.

Return type:

PcaModule

get_parameters(config)[source]

Return the current local model parameters.

Return type:

List[ndarray[Any, dtype[Any]]]

Parameters:
configConfig

Configuration parameters requested by the server. This can be used to tell the client which parameters are needed along with some Scalar attributes.

Returns:
parametersNDArrays

The local model parameters as a list of NumPy ndarrays.

save_model()[source]
Return type:

None

set_parameters(parameters, config)[source]

Sets the merged principal components transferred from the server. Since federated PCA only runs for one round, the principal components obtained here are in fact the final result, so they are saved locally by each client for downstream tasks.

Return type:

None

setup_client(config)[source]
Return type:

None