# Energy Prediction of Access Points in Wi-Fi Networks According to Users' Behaviour
## 3 An Energy Prediction Proposal
### Predicting Roamings after Removing an Access Point  
The removal of an AP can be due to several reasons, related to the infrastructure maintenance or planning. In this second phase of the energy prediction proposal (middle of Figure 1), we take advantage of a methodology inspired on RS and validated empirically, where the number of roamings can be predicted after removing an access point, as basis for a energy prediction in the simulated network. The model starts from a matrix \(R\) (_Roamings_) built from \(CR\) after performing two operations: First, we set to zero the roamings in the column corresponding to the AP removed. Second, we establish a set of cells (\(D^{unk}\)), distributed along the entire matrix following a particular strategy, as unknown values of roamings (they will be predicted), whereas the remaining cells are considered as known roamings (\(D^{knw}\)). In addition, we choose a set of training values as subset of known roamings (\(D^{train}\subseteq D^{knw}\)) to train the prediction model. This model will be more accurate if we consider a wider \(D^{train}\), because it is built from more observed data. Last, we select a set of test roamings and also known values (\(D^{test}\subseteq D^{knw}\)), although usually much smaller than \(D^{train}\), in order to validate the model by using the Root Mean Squared Error (_RMSE_) criterion (2). \[RMSE=\sqrt{\frac{\sum_{s,j\in D^{test}}{(r_{s,i}-\hat{r}_{s,i})^{2}}}{|D^{ test}|}} \tag{2}\]  
The prediction model considers Matrix Factorisation (MF). This technique approaches \(R\) to the product \(W1W2^{T}\), where \(W1\) and \(W2\) are matrices of sizes (\(S\times K\)) and (\(I\times K\)) respectively. The \(s\)-th row \(w1_{s}\) of \(W1\) contains the \(K\) features that describe the user \(s\) and the \(i\)-th row \(w2_{i}\) of \(W2\) contains \(K\) corresponding features for the AP \(i\). Then, the number of roamings \(r_{s,i}\) given by the user \(s\) in the AP \(i\) is predicted as \(pr_{s,i}\) according to (3), where \(k\) identifies the latent factor from \(1\) to \(K\). Therefore, a new matrix \(PR\) is built from \(R\) with the predicted values for the unknown roamings. \[pr_{s,i}=\sum_{k=1}^{K}{(w1_{s,k}w2_{i,k})}=(W1W2^{T})_{s,i} \tag{3}\]  
The methodology to predict the number of roamings by each user in each AP follows several steps as we can see in Figure 2. Initially, we select the train and test roaming datasets from \(R\), and the main parameters for the learning phase (number of latent factors, learning rate and regularisation factor). Then, we define a prediction model in the learning phase by using MF, and learn it considering \(D^{train}\) by using the algorithm Gradient Descent (GD) [21] in order to find the best values for \(W1\) and \(W2\). The optimal values are generated iteratively from the differences between real and predicted values. Once the model (both matrices) is obtained, we measure its goodness predicting the values of \(D^{test}\) and calculating the difference with the real values by using the \(RMSE\) criterion. Last, all the values of the roaming matrix \(R\) are predicted from the optimal model found, in order to build the entire matrix \(PR\). Learning the model by GD means finding the optimal solutions \(W1\) and \(W2\), for a particular \(K\). In this process, the initial solutions can be randomly chosen as positive real numbers generated from the normal distribution \(N(0,\sigma^{2})\) with standard deviation \(\sigma^{2}=0.01\). Then, we calculate the difference \(e_{s,i}\) (4) between real and predicted values in order to obtain the error (5). \[e_{s,i}=p_{s,i}-\hat{p}_{s,i}=p_{s,i}-\sum_{k=1}^{K}(w1_{s,k}w2_{i,k}) \tag{4}\]  
\[err=\sum_{(s,i)\in D^{train}}e_{s,i}^{2} \tag{5}\]  
This error is minimised updating \(W1\) and \(W2\) iteratively, which is very efficient in handling large datasets [22]. Gradient Descent needs to know, for each data, in which direction to update the values of \(w1_{s,k}\) and \(w2_{i,k}\).