# Federated Learning-Based Service Caching in Multi-Access Edge Computing System
## 4 Proposed Service Caching Framework
### FL-Based Service Popularity Score
#### 4.2.1 Distributed Training Phase
In addition, \(\mathbf{p}_{\theta}(\hat{R}_{u}(t_{m})|\mathbf{z})\) denotes the probability of a reconstructed value \(\hat{R}_{u}(t_{m})\) given the latent representation \(\mathbf{z}\). Hence, the reconstruction loss can be calculated as follows:  
\[\mathcal{L}_{res}(R_{u}(t_{m}),\hat{R}_{u}(t_{m}),\phi,\theta)=-\mathbb{E}_{ \mathbf{q}_{\phi}(\mathbf{z}|R_{u}(t_{m}))}\log(\mathbf{p}_{\theta}(\hat{R}_{ u}(t_{m})|\mathbf{z})). \tag{7}\]  
The AAE employs an adversarial training approach to match the posterior distributions of the latent space \(\mathbf{z}\) with a given distribution \(\mathbf{p}(\mathbf{z}_{pri})\). The GAN-based model has one generator and one discriminator. The discriminator is used to differentiate between data that derives from the generator and target distribution \(\mathbf{p}(\mathbf{z}_{pri})\). Conversely, the generator attempts to produce data that the discriminator classifies incorrectly. It is evident that after finishing the training phase, the generator can produce data samples that closely match those created from the target distribution. The encoder sub-network \(\mathbf{q}_{\phi}(\mathbf{z}|R_{u}(t_{m}))\) of the AE is utilized as the generator in the AAE architecture. \(\mathbf{d}_{\psi}\) denotes the discriminative network. Thus, the optimization problem for adversaries can be expressed as follows:  
\[\underset{\mathbf{q}_{\phi}(\mathbf{z}|R_{u}(t_{m}))}{min}\underset{\mathbf{d }_{\phi}}{max}\mathbb{E}_{\mathbf{z}_{pri}\sim\mathbf{p}(\mathbf{z}_{pri})} \log(\mathbf{d}_{\psi}(\mathbf{z}_{pri}))+\mathbb{E}_{\mathbf{z}\sim\mathbf{p} (\mathbf{z})}\log(1-\mathbf{d}_{\psi}(\mathbf{z})). \tag{8}\]  
The optimization issue can be addressed using a two-stage regularization process, including the training of both the discriminative network \(\mathbf{d}_{\psi}\) and the generative network \(\mathbf{q}_{\phi}(\mathbf{z}|R_{u}(t_{m}))\). The discriminator is trained to distinguish between samples generated by the latent variable \(\mathbf{z}\in\mathbb{R}^{1\times d_{z}}\) (negative samples) and samples created from prior distribution \(\mathbf{z}_{pri}\in\mathbb{R}^{1\times d_{z}}\) (positive samples) by using the following loss function:  
\[\mathcal{L}_{dis}(R_{u}(t_{m}),\mathbf{z},\phi,\psi)=\mathbb{E}_{\mathbf{z}_{ pri}\sim\mathbf{p}(\mathbf{z}_{pri})}\log(\mathbf{d}_{\psi}(\mathbf{z}_{pri}))+ \mathbb{E}_{\mathbf{z}\sim\mathbf{p}(\mathbf{z})}\log(1-\mathbf{d}_{\psi}( \mathbf{z})). \tag{9}\]  
Figure 3:0 Adversarial Autoencoder Architecture. On the other hand, the generator is trained with the objective of fooling the discriminator by optimizing the following loss function:  
Figure 3:1  
After adversarial training, the samples generated by \(\mathbf{q}_{\phi}(\mathbf{z}|R_{u}(t_{m}))\) cannot be distinguished from those generated by \(\mathbf{p}(\mathbf{z}_{pri})\). In this study, the prior distribution \(\mathbf{p}(\mathbf{z}_{pri})\) is set as a normal distribution \(\mathcal{N}(0,1)\)[24]. After completing the local training process, each MEC server is provided with trained weights for the AAE model. Let \(w_{m}(t_{m})\) be the weight of the local model trained by MEC server \(m\) in time slot \(t_{m}\). It is important to note that \(w_{m}(t_{m})\) comprises the weights of both the generator and discriminator sub-networks in the AAE model. (3) Sending Local Model to Cloud Server: Once the training operation time slot \(t_{m}\) is finished, the MEC servers send the local models \(w_{m}(t_{m})\) to the Cloud server, where \(m\in\mathcal{M}\). The local models are trained using the data specific to each MEC server, including the distinct data characteristics associated with each MEC coverage area. In addition, the cloud server is given with information on the number of requests, denoted as \(n_{m}(t_{m})\), which are received by the MEC server \(m\) during the time slot \(t_{m}\). (4) Global Model Aggregation: In contrast to conventional approaches to model training, the Cloud server does not have the requisite data for conducting training.