## 3 Problem Solution Using Adaptive Learning Artificial Neural Network
### FANN Prediction Phase  
The prediction phase starts after finishing the learning process when receiving the last ONU report in BBU processing cycle (i.e., the newest ONU report received after finishing the training and testing process). This phase is done using prediction Algorithm 2. The first step of this algorithm is used to update the learning set for ONUs by adjusting the initial ONU learning set by adding the newest report received after the training and testing process to the initial set and eliminating the earliest report received at beginning of the BBU process cycle from it. The second step of the algorithm is to perform the prediction process. In this step a set containing ONU reports up to the newest report  
Figure 5: Fast artificial neural network (**a**) FANN leaning phase; (**b**) FANN prediction phase.  
received after the learning phase \(R_{t}^{j}\) (\(t=0,\ 1,\ 2\ldots T\)) is provided as an input to the trained FANN module to predict the upcoming report \(R_{T+1}^{j}\)  for each ONU (see Figure 5b). After predicting the reports for all the ONUs and collecting them in a set, this set of reports is provided as an input to the grant assignment Algorithm 3 to assigns the final grant to each ONU.  
```
Input: New ONU report received after the learning \(R_{T}^{j}\),  The learning set for \(j\)th ONU \([R_{0}^{j},\ R_{1}^{j},\ldots\ R_{T-1}^{j}]\).  The trained FANN module for \(j\)th ONU. Output: A set contain the predicted ONU reports \(R_{T+1}^{j}\). For\(j=0\); \(j\)  the total number of ONU K, \(j\)++do  Update learning set for \(j\)th ONU by adding the newly received report \(R_{T}^{j}\)  to the end of the learning set and deleting the first report from it.  Run the trained FANN network with the set of reports \([R_{0}^{j},\ R_{1}^{j},\ldots R_{T}^{j}]\) as inputs to predict \(R_{T+1}^{j}\)  for this ONU. Endfor  Call the grant assignment Algorithm 3 with the set of the predicted ONU reports \(\hat{R}_{T+1}^{j}\), \(j=1,\ 2,\ 3\ldots K\), to calculate the grants for ONUs for the upcoming XGS-PON upstream frame cycle.
```  
**Algorithm 2** Prediction  
```
Input: Set of the predicted ONU reports \(\hat{R}_{T+1}^{j}\) Output: Bandwidth map for the upcoming XGS-PON frame Initialize: \(N\ =\ 0\ ;\ t=1,2,\ \ldots\ ;\ t=1,2,\ldots\ ;\ j=0\), \(Ex_{0}^{j}\ =\ 0\ ;\ W_{0}^{j}\ =\frac{\text{BW}}{\text{K}}\) For every predicted ONU report \(R_{T+1}^{j}\), do  Set \(\text{B}=False\) -  Allocate a grant \(G_{t}^{j}\) to \(j\)th ONU using the updated limit from previous cycle (\(t-1\)), -  Update the counter of the number of scheduled ONUs \(j\) if\((R_{T+1}^{j}\leq W_{t-1}^{j})\ G_{t}^{j}=R_{T+1}^{j}\) else\(G_{t}^{j}=W_{t-1}^{j}\) EndIf -  Determine whether \(j\)-th T-CONT is overloaded in the current cycle; if so, update \(N\) accordingly. If\(R_{T+1}^{j}>W_{0}\) \(N++\ ;\ \text{B}=True\) EndIf -  Update the next cycle allocation byte limit for current ONU using If\(B=True\) \(W_{t}^{j}=W_{0}^{j}+\ \ \ \ \ Ex_{t-1}^{j}\) else\(W_{t}^{j}=W_{0}^{j}+\ \ \ \ Ex_{t-1}^{j}\). EndIf EndFor -  Formulate the bandwidth map for ONUs -  Calculate ONUs excess share in this cycle as \[Ex_{t}^{j}=(BW-\sum_{j=0}^{K}\ G_{t}^{j})/N.\]
```  
**Algorithm 3** Grant assignment  
Repeat the procedure from the **Initialize** step to map the upcoming XGS-PON upstream frames.