## 4 UbiPriSEQ: The Proposed Framework
### Network Module (NetM)  
The data sent to the fog nodes for task processing and other cached data in fog needs to be protected against privacy leakages and eavesdroppers. Network Module (NetM) devises policies for data migration between fog nodes to preserve privacy and broadcasts dummy signals to confuse eavesdroppers to address privacy and security concerns. The algorithm for Network Module is given in Algorithm 2 and is explained in the following. ```
0:system state \(s_{t}\)
0:action \(\mathbf{a_{t}}=[a_{t}^{cl},a_{t}^{cf},a_{t}^{cc},c,f,fr]\)
1:while\(\
eg\)converged do
2: observe \(a_{t}^{cl},a_{t}^{cf},\text{ and }a_{t}^{cc}\)
3: compute \(\zeta_{t}\)
4: estimate \(h_{t}\)
5:\(s_{t}\leftarrow\{c_{t},h_{t},\zeta_{t},sinr_{t},\delta\}\)
6:if\(t\leq K\)then
7: Select \(\mathbf{a_{t}}\in\mathbf{A}\) at random
8:else
9: Form experience sequence
10:\(\Phi_{t}=((\mathbf{s_{t-K}},\mathbf{a_{t-K}}),\cdots,(\mathbf{s_{t-1}},\mathbf{a_{t-1}}),\bm {s_{t}})\)
11: Input \(\Phi_{t}\) to the DNN
12:\([Q(\mathbf{s_{t}},\mathbf{a_{t}})]\leftarrow\) get \(Q\)-value for \(\mathbf{A}\) using DNN
13:\(\epsilon\leftarrow\) random(0,1)
14: take action \(\mathbf{a_{t}}\)with probability \(\epsilon^{t}\)
15:\(a_{t}(a_{t}^{cl},a_{t}^{cf},a_{t}^{cc},c,f)\leftarrow\mathbf{a_{t}}\)
16:endif
17: locally store \(a_{t}^{cl}\); transmit \(a_{t}^{cf}\) to fog node \(f\) migrate \(a_{t}^{cc}\) from fog to cloud node \(c\) send dummy signal with frequency \(f\)
18:\(Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})\leftarrow\frac{1}{p(K(D_{i})\in M)-p(K(D_{j}) \in M)}\)
19: obtain the latency \(t_{t}\)
20:\(uf_{n}\leftarrow Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})-\mu\cdot\zeta_{t}\cdot t_{t}-\rho +\eta\cdot sinr_{t}\)
21:\(\mathcal{P}\leftarrow\mathcal{P}\cup(\Phi_{t},\mathbf{a_{t}},ud_{d}^{(f)},\mathbf{ \Phi_{t+1}})\)
22:for\(x\in\) DNN mini-batch do
23: Select \(\mathbf{\Phi_{t}}\in\mathcal{P}\) at random
24: Calculate DNN loss using Equation (6)
25:endfor
26: Update DNN weights \(\theta_{t}\) using gradient descent
27:\(t\gets t+1\)
28:endwhile
```  
**Algorithm 2** Network Module (NetM)  
NetM workflow is the same as of DevM (see Section 4.3.1), i.e., it observes its environment and takes a set of actions (see Figure 2). The difference lies in the specific observations and set of actions it takes, the way it calculates the PrivacyMetric and Utility, and the parameters it tries to improve. The **observations** include cache content, channel state, task priority, and SINR. The **actions** include which data to keep, and which ones to be offloaded, to which fog/cloud node, and which basestations the dummy signal is broadcasted to. The **PrivacyMetric** used by NetM, \(Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})\), defined in Equations (8), is based on differential privacy, i.e., the difference in hamming distance between two data blocks (from two arbitrary devices) present at a fog node should not exceed a certain threshold (i.e., required privacy) because a higher difference could allow attackers to identify types and content of data, and the device. NetM PrivacyMetric estimates the **data privacy** unlike the PrivacyMetric in DevM. \(\mathcal{K}\) is a privacy operation (Laplace mechanism) that operates on two data sets \(D_{i}\) and \(D_{j}\) received at a fog node from two arbitrary devices, \(i\) and \(j\). \(M\) is the local memory of the fog node and \(\epsilon_{diff}\) is the privacy parameter in differential privacy. \(Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})\) can be considered as the lower bound differential probability parameter \(\exp(\epsilon_{diff})\)[42]. \[Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})=\frac{p(\mathcal{K}(D_{i})\in M)}{p(\mathcal{K }(D_{j})\in M)}. \tag{8}\]  
The utility function (reward) \(ud_{n}\) is computed by Equation (9). \(Pri_{n}(\mathbf{s_{t}},\mathbf{a_{t}})\) represents the data privacy metric for NetM. \(c_{t}\) is the tasks' aggregated computational costs and \(sint_{t}\) is SINR at time \(t\); \(\mu\) and \(\eta\) are the weights giving their relative importance, respectively.