# Towards Mobile Federated Learning with Unreliable Participants and Selective Aggregation
## 3 Proposed Federated Learning Infrastructure
### Development and Implementation  
In this section, we first describe the implementation of the FL server and then we provide details about the implementation of the mobile clients. **REST Server (Server Implementation)**  
As seen before, the REST server started the communication rounds and monitored whether all updated weights were sent to the server by the clients. This server also sent the updated model to all clients. The services supported by the REST API were as follows:  
* A GET method to retrieve the latest shared model on the server;
* A POST method to upload the updates from the clients;
* A GET method to retrieve the information about the current round. The first training round started immediately after the server was initialized. Once the local training was finished, the server asynchronously received updates from all clients. When a client sent the updated weights to be aggregated to the global model, the server stored them in a file in JSON format. This file contained all the information about each client's training rounds known so far. After the server received information from all clients, it proceeded to aggregate the weights to create the global model. In a production environment, the server should have protection mechanisms to prevent it from receiving new information during the model aggregation process, as this can lead to system degradation. It was assumed that all available clients participated in each training round. Therefore, this paper did not consider the elimination or addition of clients during the training process. Once the model aggregation was complete, the server sent it back to all participating clients in response to the previously received update message. **Android Application (Client Implementation)**  
An Android client application was developed using Android Studio based on the above-mentioned strategy. A functional.apk file was created that allowed any user to install the application for local training on an Android mobile device. This application had to be able to communicate with the server. To do this, each client sent a REST message to an endpoint created for the server described above and with a known IP address. The clients sent weights from the local training and received in a response the updated global model to be used in the next round. The client side implementation consisted of four phases:  
* Setting up the connection to the server and loading the client dataset into memory;
* Receiving the global model through a REST message;
* Performing training on the client dataset;
* Sending the resulting weights to the server through a REST message. The training function was developed using TensorFlow Federated for Android ([[https://www.tensorflow.org/federated](https://www.tensorflow.org/federated)]([https://www.tensorflow.org/federated](https://www.tensorflow.org/federated)), accessed on 28 February 2023). For our implementation, tests were initially performed with Android devices emulated in Android Studio. These tests showed that the software application would consume large amounts of computational resources and would therefore affect scalability with a larger number of clients. After further testing with alternative solutions, BlueStacks software was selected as it proved to scale better. Like any other emulator, BlueStacks creates a virtual version of an Android device that runs locally on any computer. On this virtual device, the application was installed to run the developed FL client. The multi-instance manager lets a user create multiple instances of BlueStacks. Using this feature, one can emulate several Android devices to test scenarios with multiple clients. Ideally, one should consider the computational capacity and energy efficiency of each client, since in most real-world cases, client devices are heterogeneous. This has a significant impact on training, as there are clients that perform their local training fasterthan others. This not only affects the total training time but also the ability of each client to train with a considerably large dataset.