# SmartFog: Training the Fog for the Energy-Saving Analytics of Smart-Meter Data
## 3 The Proposed SmartFog Platform  
The proposed SmartFog technological platform is sketched in Figure 1. It consists of \(N\) virtualized Fog nodes and a virtualized Cloud node that can communicate with each other and the SMs through a set of Network Interface Cards (NICs). Each Fog node can gather data measurements from several SMs by using a Multiplexer (MUX). It uses an SDAE [3; 4; 5] for data analytics and a networked Fog platform for SDAE pretraining and execution. In this regard, we shortly point out that a Stacked Auto-Encoder (SAE) is a feed-forward neural network with \(2L-1\) hidden layers trained to (quasi) _reproduce_ its input at the output layer (see Figure 2). The aim of an SAE is to learn a compressed and distributed representation \(\mathbf{h}_{L}\) (_encoding_) for a set of (possibly, noisy) input data \(\mathbf{x}\) (typically for the purpose of dimensionality reduction), using a set of weight matrices \(\mathbf{W}_{k}\), \(k=1,\ldots,L\). Then, an estimate \(\widehat{\mathbf{x}}\) of the data \(\mathbf{x}\) is recovered (_decoding_) by using tied weights (i.e., \(\mathbf{W}_{k}^{*}=\mathbf{W}_{k}^{T}\)), as depicted in Figure 2[4]. As a robust variant, the Stacked _Denoising_ Auto-Encoder (SDAE) [5] is a stochastic version of the SAE, where a stochastically corrupted \(\widehat{\mathbf{x}}\) version of the input \(\mathbf{x}\) is employed to feed the SAE (usually, using a Gaussian additive noise), while the uncorrupted input \(\mathbf{x}\) is still used as the target for the optimization of the weight matrices (see Figure 2). As shown in Figure 2, the computation of the \(k\)-th layer in the encoding phase is performed according to the following relationship [5]:  
\[\mathbf{h}_{k}=\sigma_{k}\left(\mathbf{W}_{k}\mathbf{h}_{k-1}+\mathbf{b}_{k} \right),\quad k=1,\ldots,L, \tag{1}\]  
With \(\mathbf{h}_{0}=\widetilde{\mathbf{x}}\), while the companion decoding layer acts as follows [5]:  
\[\widehat{\mathbf{h}}_{k}=\mathbf{W}_{k+1}^{T}\widehat{\mathbf{h}}_{k+1}+ \mathbf{c}_{k},\quad k=L-1,\ldots,0. \tag{2}\]  
In Equations (1) and (2), \(\mathbf{W}_{k}\) is the weight matrix of the \(k\)-th layer of the considered SDAE, \(\mathbf{b}_{k}\) and \(\mathbf{c}_{k}\) are the bias vectors of the encoder and decoder at the \(k\)-th layer, \(\sigma(\cdot)_{k}\) is the element-wise nonlinear activation function of the \(k\)-th layer of the encoder (e.g., sigmoid or ReLU) and \(\widehat{\mathbf{h}}_{0}\equiv\widehat{\mathbf{x}}\). The decoder transformation in (2) is of affine type due to the continuous-valued nature of the input vector \(\mathbf{x}\). The unsupervised pretraining of such an architecture is done on a per-layer basis [5]. Specifically, each layer is trained as a denoising auto-encoder by minimizing with respect to \(\mathbf{h}_{k}\), \(\mathbf{b}_{k}\) and \(\mathbf{c}_{k}\) the total squared reconstruction error:  
\[\mathcal{L}\left(\widehat{\mathbf{h}}_{k}\right)\triangleq\frac{1}{2}\sum_{t }\left\|\widehat{\mathbf{h}}_{k}^{t}-\mathbf{h}_{k}^{t}\right\|_{2}^{2},\quad k =1,\ldots,L, \tag{3}\]  
Figure 1: A sketch of the proposed SmartFog technological platform. Arrowed paths indicate data links. SM: = Smart-Meter; MUX: = Multiplexer; FN: = Fog Node; CL: = Cloud; VC: = Virtual Clone; NIC: = Network Interface Card. where \(t\) is the batch index [5] and \(\mathbf{h}_{k}^{t}\) is the \(t\)-th batch of the input vector at layer \(k\). In our framework, the minimization of (3) is pursued by applying the Adam algorithm, a variant of the stochastic gradient descent that is based on the adaptive estimation of the first and second order moments of the gradient of (3) with respect to weights and bias of Figure 2[4]. A \(k\)-NN classifier [4] is used atop the final hidden representation \(\mathbf{h}_{L}\) to detect whether or not the input \(\mathbf{x}\) contains an anomaly. The implemented classifier is binary and its output is 0 for \"no anomalies\" while it is 1 for \"anomalies\" detected in the data \(\mathbf{x}\).