logistic_regression.server module¶
Server module for logistic regression
- class logistic_regression.server.Server(config)[source]¶
Bases:
objectThe Server class. Responsible for aggregating results of the clients.
- __init__(config)[source]¶
Initializes the server by setting the config and initializing the communication pool.
- Parameters:
config (
Config) – The configuration for the experiment
- async static aggregate(gradient_per_client, weights_per_client)[source]¶
Aggregate gradients by taking weighted average. Works for gradients of any order. First sorts the gradients and weights in order, then averages the gradients based on their weights.
- Parameters:
gradient_per_client (
dict[str,ndarray[tuple[Any,...],dtype[float64]]]) – Dictionary containing clients as keys and their gradient as values.weights_per_client (
dict[str,int]) – Dictionary containing clients as keys and their weights as values.
- Return type:
ndarray[tuple[Any,...],dtype[float64]]- Returns:
A weighted average of the gradients.
- create_communication_pool()[source]¶
Create a communication pool with all the clients.
- Return type:
Pool- Returns:
The communication pool
- async get_gradients_from_clients(msg_id)[source]¶
Receive gradients from the clients and put them in a dictionary.
- Parameters:
msg_id (
str) – The message id for receiving the gradients.- Return type:
dict[str,ndarray[tuple[Any,...],dtype[float64]]]- Returns:
A dictionary containing the gradients. Each key is a client id and its value is the corresponding gradient from that client.
- async get_weights_from_clients()[source]¶
Receive the weights from all clients.
- Return type:
dict[str,int]- Returns:
A dictionary containing the weights. Each key is a client id and its value is the corresponding weight.
- initial_model()[source]¶
Returns an initialized model.
- Return type:
ndarray[tuple[Any,...],dtype[float64]]- Returns:
An initialized model (all zeros).