## 4 BP and GA-BP Neural Network Realization
### BP Neural Network Model Analysis  
Figure 7 shows the dataset of six input parameters including the temperature, pressure, humidity, wind speed, sine value of wind angle, and cosine value of wind angle, respectively. It is worth noting that the data of columns 5 and 6 were processed by data normalization. Additionally, there are 96 lines of data which represent 4 days (96 h), where each line stands for 1 h parameters of the wind turbine. For 4 days, the first day and the third day are sunny weather, while the second day and the fourth day are rainy and cloudy. In other words, lines 1-24 and lines 49-72 represent the sunny day, while lines 25-48 and lines 73-96 represent the rainy and cloudy day. This is to distinguish the influence of different weather conditions on the accuracy of load forecasting. In this paper, the six above independent variables of a microgrid in four consecutive days are used as sample data for training, and a load of its microgrid is predicted. Table 1 presents the data on the power load of the wind turbine. In this model, it represents the output of the model. In the MATLAB simulation module, users can use the relevant functions of network design, training, and simulation provided by Neural Network Toolbox (NNbox) according to their requirements, normalize training samples, develop network initialization, learning rules, and network parameters. In this way, the neural network algorithm learning, and iterative procedures can be realized. Figure 7: Actual value and predicted value in the training set. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline  & & & \multicolumn{4}{c}{**Input**} \\ \hline
**Day** & **Temperature** & **Pressure** & **Humidity** & **Wind Speed** & \ \begin{tabular}{c} **Sine Value of** \\ **Wind Angle** \\ \end{tabular}  & \begin{tabular}{c} **Cosine Value of** \\ **Wind Angle** \\ \end{tabular}  & **Output** \\ \hline
1.00 & 290.16 & 1029 & 55 & 5 & \(-0.5\) & \(-0.866025\) & 1  
The trainable forward inverse feedback function \"newff\" was introduced in MATLAB to create a BP network. Moreover, the bipolar S\(-\)type function \"tansig\" is the neuron  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline  & & & & **Input** & & \\ \hline
**Day** & **Temperature** & **Pressure** & **Humidity** & **Wind Speed** & \ \begin{tabular}{c} **Sine Value of** \\ Wind Angle** \\ \end{tabular}  & \begin{tabular}{c} **Cosine Value of** \\ Wind Angle** \\ \end{tabular}  & **Output** \\ \hline
61.00 & 279.64 & 1028 & 93 & 2 & \(-0.866025404\) & 0.5 & 697 \\ \hline
62.00 & 279.64 & 102  
transfer function in the hidden layer. The pure linear transfer function \"purelin\" is the output layer neuron transfer function. After determining the network structure, \"newff\" will automatically introduce the initialization function \"init\" to initialize each weight with random default parameters and generate a trainable forward feedback network, which means the return value of this function \"net\". In MATLAB, network attributes are defined by structures. The function \"trainlm\" is being used to realize training. The iteration numbers are set to 1000. Additionally, the convergence error is set to 0.01. Part of the code parameters are shown in Algorithm 1:  
```
Procedure test1()  temp \(\leftarrow\) randperm(size(X, 1)) for i \(\leftarrow\) 1 to 60 do  P_train[i] \(\leftarrow\) X[temp(i)] end for for i \(\leftarrow\) 61 to end do  P_test[i] \(\leftarrow\) X[temp(i)] end for M \(\leftarrow\) size(P_train, 2); for i \(\leftarrow\) 1 to 60 do  T_train[i] \(\leftarrow\) Y[temp(i)] end for for i \(\leftarrow\) 61 to end do  T_test[i] \(\leftarrow\) Y[temp(i)] end for N \(\leftarrow\) size(T_test, 2) net. trainParam.epochs \(\leftarrow\) 1000 net. trainParam.goal \(\leftarrow\) 1e\(-\)3 net. trainParam.lr \(\leftarrow\) 0.01 end procedure
```  
**Algorithm 1** BP neural network parameters  
The training set is the data sample that may fit the model. During the process, the training uses the error gradient descent, learning, and trainable weight parameters.