xain_fl.fl.coordinator package

Contains coordinator logic which runs the central server in federated learning. It consists of the following modules:

  • aggregate

  • controller

Submodules

xain_fl.fl.coordinator.aggregate module

Provides an abstract base class Aggregator and multiple sub-classes such as FederatedAveragingAgg.

class xain_fl.fl.coordinator.aggregate.Aggregator

Bases: abc.ABC

Abstract base class which provides an interface to the coordinator that enables different aggregation implementations.

abstract aggregate(thetas)

Aggregates given a list of thetas and returns the aggregate.

Parameters
  • thetas (List[Tuple[Theta, int]]) – List of tuples with theta and the number

  • examples used to obtain theta. (of) –

Return type

List[ndarray]

Returns

Theta

class xain_fl.fl.coordinator.aggregate.FederatedAveragingAgg

Bases: xain_fl.fl.coordinator.aggregate.Aggregator

Provides federated averaging aggregation, i.e. a weighted average.

aggregate(thetas)

Aggregates given a list of thetas and returns the aggregate.

Parameters
  • thetas (List[Tuple[Theta, int]]) – List of tuples with theta and the number

  • examples used to obtain theta. (of) –

Return type

List[ndarray]

Returns

Theta

class xain_fl.fl.coordinator.aggregate.IdentityAgg

Bases: xain_fl.fl.coordinator.aggregate.Aggregator

Provides identity aggregation, i.e. the aggregate method expects a list containing a single element and returns that element.

aggregate(thetas)

Accepts only a thetas list of length one.

Return type

List[ndarray]

class xain_fl.fl.coordinator.aggregate.ModelSumAgg

Bases: xain_fl.fl.coordinator.aggregate.Aggregator

Provides a sum-of-models aggregation.

aggregate(thetas)

Aggregates a given list of models by summation.

Parameters

thetas (List[Theta]) – List of thetas.

Returns

The aggregated model weights.

Return type

Theta

xain_fl.fl.coordinator.aggregate.federated_averaging(thetas, weighting)
Calculates weighted averages of provided list of thetas, as proposed by McMahan et al. in:

https://arxiv.org/abs/1602.05629

Parameters
  • thetas (List[Theta]) – List of thetas.

  • weighting (np.ndarray) – Describes relative weight of each theta. Required to be the same length as argument thetas.

Return type

List[ndarray]

Returns

Theta

xain_fl.fl.coordinator.controller module

Provides an abstract base class Controller and the RandomController currently used by the Coordinator.

class xain_fl.fl.coordinator.controller.Controller(fraction_of_participants=1.0)

Bases: abc.ABC

Abstract base class which provides an interface to the coordinator that enables different selection strategies.

fraction_of_participants

The fraction of total participant IDs to be selected. Defaults to 1.0, meaning that all participant IDs will be selected. It must be in the (0.0, 1.0] interval.

Type

float, optional

get_num_ids_to_select(len_participant_ids)

Calculates how many participant IDs need to be selected.

Parameters

len_participant_ids (int) – The length of the list of IDs of all the available participants.

Returns

Number of participant IDs to be selected

Return type

int

abstract select_ids(participant_ids)

Returns the selected indices of next round.

Parameters

participant_ids (list of str) – The list of IDs of all the available participants, a subset of which will be selected.

Returns

List of selected participant IDs

Return type

list of str

class xain_fl.fl.coordinator.controller.IdController(fraction_of_participants=1.0)

Bases: xain_fl.fl.coordinator.controller.Controller

[summary

… todo: Advance docstrings (https://xainag.atlassian.net/browse/XP-425)

select_ids(participant_ids)

Selects all given participants.

Parameters

participant_ids (list of str) – The list of IDs of all the available participants, a subset of which will be selected.

Returns

List of selected participant IDs

Return type

list of str

class xain_fl.fl.coordinator.controller.RandomController(fraction_of_participants=1.0)

Bases: xain_fl.fl.coordinator.controller.Controller

[summary]

Parameters

Controller ([type]) – [description]

select_ids(participant_ids)

Randomly samples self.num_ids_to_select from the population of participants_ids, without replacement.

Parameters

participant_ids (list of str) – The list of IDs of all the available participants, a subset of which will be selected.

Returns

List of selected participant IDs

Return type

list of str