FedSDM: Federated Learning based Smart Decision Making Module for ECG Data in IoT Integrated Edge-Fog-Cloud Computing Environments

Massive data collection in modern systems has paved the way for data-driven machine learning, a promising technique for creating reliable and robust statistical models. By combining the data into centralized storage to develop a reliable learning model, there are concerns with privacy, ownership, and strict rules. It is self-evident that the samples in the typical machine learning centralized server paradigm have vastly different probability distributions of data supplied by each user. As a result, the typical model needs to be personalized for critical medical applications, and the deployment needs an efficient mechanism that can adapt to varying user inputs. Due to the heterogeneous and dynamic nature of critical medical IoT applications in such Edge/Fog scenarios, the privacy of patients become a crucial problem. Federated Learning, the model trained on diversity helps in addressing these concerns when used. This paper proposes the integration of Federated Learning for distributed Edge-Fog-Cloud architecture in the IoT smart healthcare sector. This paper presents FedSDM, the Federated Learning-based Smart Decision Making framework for the ECG data in microservice-based IoT medical applications. This proposal makes use of the advantages of Edge/Fog computing for real-time critical applications. It deploys the Federated Learning model at the Edge, Fog, and Cloud layers for performance comparison. The parameters considered for performance evaluation are energy consumption, network usage, cost, execution time, and latency. The proposed method shows that Edge-based deployment outperforms Fog and Cloud in terms of energy consumption, network usage, cost, execution time, and latency (i.e.) 0.3%, 2%, 15%, 11%, and 3% when compared with


Introduction
The unprecedented technological developments over the last two decades have accelerated data growth, which has led to data privacy issues when stored in centralized systems. This is visible in many domains, especially in the healthcare sector, where hospitals still store patients' sensitive information in centralized repositories. A recent study on cyber security statistics disclose that 5 data breaches in the first half of 2020 alone revealed 36 billion records [1]. This motivates the introduction of the next level of artificial intelligence, which works on the concept of data privacy as its foundation to address the users' concern about the privacy of available data such as personally identifiable details, payment details, protected health information, confidential information, and others [2]. Due to the heavy movement of data into and out of the Cloud, two additional challenges 10 arise with Cloud/centralized-based techniques namely latency and data transfer cost. Users or end devices may be unwilling to disclose private data to preserve privacy or conserve their phone's limited bandwidth/battery capacity [2]. In such scenarios, Federated Learning enables smarter models with less latency, and reduced battery usage while ensuring privacy. Defense, telecommunications, Internet of Things (IoT), and pharmaceutics are just a couple of applications where it can be used. 15 Federated Learning (FL) is a machine learning methodology that involves training an algorithm across numerous decentralized servers or Edge devices while retaining data samples locally and preventing data transmission. Using data from tens to millions of remote devices helps build a global statistical model. FL allows devices like mobile phones to develop a shared prediction model while retaining all the training data on the end device, removing the requirement to store it in related work. Section 4 presents the proposed method followed by the experimental setup in Section 5. Section 6 summarizes the results, and Section 7 concludes the paper. 60 The concept of intelligent healthcare involves utilizing AI to learn and analyze patient data.

Background and Motivation
However, it can be challenging to find large and diverse datasets to train machine learning models in individual medical centers. This means that traditional centralized AI methods require sensitive data to be moved from medical facilities to data centers, which not only increases the demand for communication resources and energy, but also violates privacy. This has become a significant issues before they become acute, reducing the likelihood of hospitalizations and emergency room visits. Overall, real-time ECG anomaly detection has the potential to improve patient care, increase accuracy, and reduce healthcare costs, making it a valuable tool in healthcare. Since the healthcare 90 issues related to ECG anomaly detection in microservice-based IoT systems are not sufficiently addressed by existing research on Edge/Fog/Cloud Federated learning approaches, we were motivated to do this study.

FL aggregation methods
The literature proposes FedAvg as a privacy, security-preserving, and efficient communication 105 aggregation algorithm for FL over-Edge devices. FedAvg assumes uniform involvement from all participants and excludes clients responding slowly [20]. The FedMA aggregation approach's foundation is a layer-wise learning strategy that matches and merges nodes with comparable weights.
Independently trained layers interact with the server [21]. FedProx addresses the heterogeneity issue in federated networks by allowing each participant device to execute a different amount of 110 work. It incorporates partial information from stragglers and adds a proximal term to account for heterogeneity, which promises a steady and precise convergence behavior [2]. The principle of the FedPer approach is that the model is divided into personalized and base layers. While the personalized layers are not communicating with the server, the base layers are aggregated using transfer learning methodologies by the federated server [22]. FedDist is a Federated Learning 115 aggregation algorithm based on the Euclidean distance dissimilarity measurement. This algorithm cost and the cost of interconnection for mobile devices. This is achieved by offloading a few calculations from mobile clients to the Edge server [24].
A comparison of the above-discussed aggregation algorithms is presented in Table 1 is effective for real-world applications as well [30]. EdgeFed, draws inspiration from Edge computing and aims to enhance the learning efficiency and reduce global communication frequency. It achieves this by separating the process of updating the local model, which is done independently by mobile devices. The edge server aggregates the outputs of these devices [24].
In order to reduce the model training loss and the overall time consumption, Zaw  technique for detecting anomalies in univariate time series data using a long short-term memory (LSTM) algorithm. This method learns the structural characteristics of non-anomalous training data, and then applies a statistical approach to detect anomalies based on prediction error in observed data [39].

Smart Decision Making in IoT applications
190 Cambra et al. showcase the benefits of using a tool that utilizes data in real-time decision-making.
The data includes variable rate irrigation and specific parameters derived from field and weather conditions. The decision-making system processes data obtained from periodic sampling of field parameters, vegetation indices estimated through aerial images, and irrigation events like flow level, pressure level, and wind speed. The data is analyzed using a learning prediction system combined

SDM in smart healthcare applications
Decision support systems (DSS) aim to provide experts with timely and relevant information.
They offer tools for data processing, models, and knowledge to assist experts in making more

Federated Learning in healthcare
Among many applications, the healthcare sector deserves to be prioritized in terms of service quality compared to other domains. Critical functions such as simultaneous reporting and monitoring, 225 tracking and alerts, and remote medical aid are all possible with IoT-based apps. The center for connected health policy conducted a study that observed that remote health monitoring systems lower the re-admission rates of heart failure patients by 50 percent [46]. Machine learning will not be able to realize its full potential or, eventually, make the leap from academic study to the clinical application without access to enough data. Rieke et al. examine the major contributing causes to 230 this problem, evaluates the challenges faced in the field of digital health and discuss how Federated Learning can provide a solution [47]. Chen et al. propose FedHealth, a system that uses federated and transfer learning to aggregate and create reasonably personalized models. The model uses homomorphic encryption to ensure that no user data is leaked [48]. Microservices architecture is suggested as a new design style that is simpler to update and deploy 250 Fog IoT applications due to its fundamental properties, such as small granularity and low coupling.
Microservice deployments are significant today because of their high performance and suitability for IoT applications [54]. Compared to service-oriented and monolithic architectures, the purpose of microservice architecture is to divide the system into discrete, independent components that can be connected to share services and architectures [55]. Each microservice is responsible for a single

. Multi-tier architecture
A multi-tier architecture paradigm has been identified for an integrated Fog healthcare application.
IoT devices such as sensors and actuators constitute tier-0. The Edge/Fog (proxy servers, gateways) and the Cloud nodes constitute the architecture's tier-1 and tier-2. In the proposed Fog-based smart 305 healthcare system, the Fog layer act as a supportive intermediate layer for processing and analyzing real-time critical healthcare data near end-users. The Cloud, which acts as tier 3, supplies additional processing and storage resources if the Fog devices cannot handle the incoming request requirements.
Virtualized processing cores, storage, and memory are considered as the resources at Fog nodes. If a request meets the resource requirements such as CPU, memory, and bandwidth, the request can be 310 processed by the current Fog or Edge device else, the request can be transmitted to the neighboring device.
The proposed approach is simulated using iFogSim2 [12], the details of which are presented in

Mobility
The mobility of Fog nodes or users raises an issue for the Fog computing platform by maintaining resources close to users at all times [60]. In addition, IoT device mobility can impact the performance of Fog applications because of the rapid movement of the devices from one access point to another.

330
The mobility component of iFogSim2 allows distributed node movements and also enable to customize the movement direction and speed of the end devices. This helps in the better simulation of the system which is at par in real-time.

Clustering
Resource augmentation can considerably assist resource-limited Fog resources, particularly  • Preprocessing microservice: Before transferring data for further processing, the preprocessing microservice performs data validation and cleaning to remove the noise of ECG sensor data.
• Decision-making microservice: The microservice is in charge of real-time decision-making whether the ECG is normal or anomalous. Based on the decision, a warning signal regarding 360 the patient's health is sent to the client microservice.
These microservices communicate with one another to keep track of users' health. Based on the placement policy, preprocessing and decision-making constitutes a time-critical service that can be deployed on Edge or Fog. The data for permanent storage is being moved to the storage module.
An effective resource provisioning methodology uses a multi-level hierarchical Fog architecture in 365 which application placement requests are handled at the Fog node at different levels. It models an IoT-critical medical application as groupings of containerized microservices and uses a decentralized placement strategy to distribute them within the Fog environment.   The architecture of the autoencoder is presented in Figure 5 (a). The proposed approach has two layers in both the encoder and decoder, without accounting for the input and output, as shown in 400 Figure 5 (b). The number of nodes per layer reduces with each subsequent encoder layer and grows back in the decoder. In terms of layer structure, the decoder and encoder are also symmetrical. The loss function is the mean squared error in the proposed system configuration. The proposed architecture implements an encoder and a decoder using an ANN architecture.

Federated Learning model
The ECG data is fed as input to the model, and the model tries to reconstruct it. The error between 405 the original data and the reconstructed output will be called the reconstruction error. Based on this reconstruction error, the ECG data is classified as anomalous. In order to do this, the model is first trained on the standard ECG data and is tested on the complete test set. The autoencoder reconstructs the abnormal ECG when the input is provided. However, since it has been trained only on the standard ECG data, the output will have a more significant reconstruction error. The input   Figure 6 (a). As can be seen in Figure 6 (b), the 420 autoencoder is added to the flower framework.

Proposed method
The proposed method works as follows: ECG sensor values collected from the patient are  policies is presented in Figure 7. Each deployment has been compared for its performance in the learning efficiency and the QoS parameters, which are presented in the next section.

Evaluation metrics
This section explains the performance evaluation measures used to evaluate the FedSDM. By comparing these KPIs, organizations can determine the approach that best fits their requirement and ensure that they are making the most effective use of their computing resources 455 [62,63,64]. We have chosen latency, energy consumption, network use, cost, and execution time as evaluation criteria in our proposed method, as they are crucial for evaluating critical medical applications. The subsequent section outlines the evaluation parameters for our proposed approach.

Evaluation parameters for proposed approach
A set of n independent tasks are delivered to the system at each time, assuming that T k represents 460 the k th task denoted as follows: The assumed infrastructure comprises Edge/Fog/Cloud nodes, which are processors with characteristics such as CPU rate, CPU usage cost, bandwidth usage cost, and memory usage cost. The set of m processors is made up of fog nodes as mentioned below: where N i represent the i th processing node. The processor N i allocated with job T k is denoted by A set of one or more tasks may be assigned to one processor for computing: The subsequent information discuss the performance metrics employed to assess the implementation of FedSDM across the Edge, Fog and Cloud layers.

465
Execution time. The execution time (EXT) required by node N i to finish a set of N i Tasks assigned to it is: where length(T i k ) denote the number of instructions in the task T k . The node N i 's CPU rate is represented by CP U i and depends on factors such as clock rate, core count, instruction level parallelism, etc. Total execution time is the total time taken by the system to complete all the tasks, defined from the time when the request is received until the last task, or the time when the last machine completes. Total execution time is determined by the formula: The time used to complete the job while utilizing system services is included in the task's execution time. Execution times differ amongst tasks because they rely on how intensive the processing and input-output activities are. The variable energy for server utilization while processing the requests is EN i k . E is the total 500 energy consumption which can be calculated by where EN i k is the energy consumption by the task T k running on the virtual machine or node i. Operating the data centre requires E 0 , the fixed energy of the server in idle state, and e 1 , the energy consumption per unit time in node N i . The suggested method makes some fixed assumptions regarding the simulation setup, including the distance between fog nodes, energy efficiency, and 505 power consumption of communication devices. However, we are aware that these factors typically affect the amount of energy used for communication, therefore we will address this in the future to improve our model. In comparison to cloud operations, the latency can be significantly reduced if the edge of the network can manage the portion of the workload. Additionally, the Edge-to-Cloud traffic is to be maintained.
Data transmission size could be considerably decreased by data pre-processing at the edge and fog devices. However, bandwidth conservation is essential because many endpoints connect to the 515 network and many database servers are needed to run them. Network usage depends on the latency experienced by the network and the tuple size of the data for ′ n ′ VMs in the host as listed in Equation 11.
where l denote the latency experienced by the network and T N S denote the tuple network size.
Tuple network size refers to the number of tuples that can be processed simultaneously within the Processing cost is defined as: where c 1 denote the CPU usage fee per time unit in node N i , and EXT(T i k ) is given in Equation 5. c 2 denote the memory usage fee per data unit in node N i and M(T i k ) represent the memory needed by task T k . Task T k processed in node N i needs an amount of bandwidth Bw(T i k ), which is the sum of input and output file size. c 3 is the bandwidth usage fee per data unit. The following formula is used to determine the cost of each task in the Edge-Fog-Cloud system in total.
Our proposed strategy aims to deploy FedSDM in Edge/Fog/Cloud layers and evaluate the above-mentioned parameters. • The data parser class separates and assimilates location data from many IoT end devices so that application services may be handled based on their unique mobility patterns.
• MobilityController class helps to dynamically start the required sequential and parallel actions on separate FogDevice and AppModule referenced objects for mobility management.
During simulation, the proposed model assumes two mobility patterns: 'RANDOM MOBILITY'

565
This section explains the simulation environment used to evaluate the proposed approach. The sensors detect the ECG of the patient and send the data to the Fog nodes regularly. Data is processed and analyzed on the Fog nodes to determine whether the patient's health status is normal or critical. The results are subsequently sent to the Cloud for storage and the patient's smartphone.
The Fog nodes' connection to the Cloud server is established through the proxy server. The client 570 module is integrated in IoT devices to get sensor data. The processing module is embedded in Fog nodes to process and analyze the incoming data to assess the patient's health status. The Fog node then communicates the results to the associated IoT device, which displays them. It must define values for numerous parameters in iFogSim2 when generating Fog devices, such as CPU length,

Analysis and Observations
This section presents the results and the observation. The model is evaluated as described in the previous sections for varying placement policies. Figure 10 presents the normal and abnormal ECG 610 samples. Figure 11 shows the reconstructed normal and abnormal ECG plots. The reconstructed ECG helps in predicting whether the ECG is anomalous. The reconstructed one with the error beyond a threshold is considered anomalous. The error calculated from these figures helps in this classification. Figure 12 highlights the training and the testing loss graphically.       increase of 0.3%, 2%, 15%, 11%, and 3% for energy consumption, network usage, cost, execution time, and latency, respectively as presented in Table 5. Table 6 shows the number of simulations conducted and the average results for each of the parameters. In conclusion, FL module deployment in the Edge layer is superior to FL module deployment in Fog or Cloud, which adds to the fact that the integration of AI on Edge enables smart healthcare systems. This could also support real-time 630 or advanced remote patient monitoring by immediately processing the clinical tests.

Comparative analysis
In order to have an effective conclusion, the proposed approach has been compared for its accuracy and the training loss parameters against the existing results presented in the literature  [24]. Figure 14 and Figure 15 show the contrast of the parameters used for various batch sizes and 635 epochs. These results also prove the conclusion statement in the previous sub-section. applications. In addition, we also examine the performance of the proposed system with three different placement policies considering the deployment at Edge, Fog and Cloud layers. Future work will include addressing this work's limitations and experimenting with the model's energy usage.
Also, we want to put the suggested method into action. To boost prediction models, we will also look into, improve, and deploy more aggregation techniques. In order to increase system security in