fl4health.strategies.noisy_aggregate module

add_noise_to_array(layer, noise_std_dev, denominator)[source]

For a given numpy array, this adds centered gaussian noise with a provided standard deviation to each element of the provided array. This noise is normalized by some value, as given in the denominator.

Parameters:
  • layer (NDArray) – The numpy array to have element-wise noise added to it.

  • noise_std_dev (float) – The standard deviation of the centered gaussian noise to be added to each element

  • denominator (int) – Normalization value for scaling down the values in the array.

Returns:

The element-wise noised array, scaled by the denominator value.

Return type:

NDArray

add_noise_to_ndarrays(client_model_updates, sigma, n_clients)[source]

This function adds centered gaussian noise (with standard deviation sigma) to the uniform average of the list of the numpy arrays provided.

Parameters:
  • client_model_updates (list[NDArrays]) – List of lists of numpy arrays. Each member of the list represents a set of numpy arrays, each of which should be averaged element-wise with the corresponding array from the other lists. These will have centered gaussian noise added.

  • sigma (float) – The standard deviation of the centered gaussian noise to be added to each element.

  • n_clients (int) – The number of arrays in the average. This should be the same as the size of client_model_updates in almost all cases.

Returns:

Average of the centered gaussian noised arrays.

Return type:

NDArrays

gaussian_noisy_aggregate_clipping_bits(bits, noise_std_dev)[source]

Computes the noisy aggregate of the clipping bits returned by each client as a list of numpy arrays. Note that each array should only have a single bit value. This returns the noisy unweighted average of these bits. The noise is centered Gaussian.

Parameters:
  • bits (NDArrays) – Clipping bit returned by each client.

  • noise_std_dev (float) – The standard deviation of the centered Gaussian noise applied to the bits.

Returns:

The uniformly averaged noisy bit.

Return type:

float

gaussian_noisy_unweighted_aggregate(results, noise_multiplier, clipping_bound)[source]

Compute unweighted average of weights. Apply gaussian noise to the sum of these weights prior to normalizing.

Parameters:
  • results (list[tuple[NDArrays, int]]) – List of tuples containing the model updates and the number of samples for each client.

  • noise_multiplier (float) – The multiplier on the clipping bound to determine the std of noise applied to weight updates.

  • clipping_bound (float) – The clipping bound applied to client model updates.

Returns:

Model update for a given round.

Return type:

NDArrays

gaussian_noisy_weighted_aggregate(results, noise_multiplier, clipping_bound, fraction_fit, per_client_example_cap, total_client_weight)[source]

Compute weighted average of weights. Apply gaussian noise to the sum of these weights prior to normalizing.

Weighted Implementation based on https://arxiv.org/pdf/1710.06963.pdf.

Parameters:
  • results (list[tuple[NDArrays, int]]) – List of tuples containing the model updates and the number of samples for each client.

  • noise_multiplier (float) – The multiplier on the clipping bound to determine the std of noise applied to weight updates.

  • clipping_bound (float) – The clipping bound applied to client model updates.

  • fraction_fit (float) – Fraction of clients sampled each round.

  • per_client_example_cap (float) – The maximum number samples per client.

  • total_client_weight (float) – The total client weight across samples.

Returns:

Noised model update for a given round.

Return type:

NDArrays