Using MATLAB to Develop Artificial Neural Network Models for Predicting Global Solar Radiation in Al Ain City – UAE

Information about the availability of solar radiation on horizontal surface is essential for the optimum design and study of solar energy systems. For a country like UAE, the efficient application of solar energy seems inevitable because of abundant sunshine available throughout the year. The traditional way of knowing the amount of global solar radiation (GSR) in a particular region is to install pyranometers at as many locations as possible in this region thus requiring daily maintenance and data recording, and consequently increasing cost of GSR data collection. Therefore, it is rather more economical to develop methods to estimate the GSR using climatological parameters (Akhlaque et al., 2009; Kassem et al., 2009; Falayi et al., 2008; El-Sebaii & Trabea, 2005). Many researchers estimated global solar radiation by using artificial neural networks. (Mohandes et al, 1998) applied ANN techniques to predict GSR using weather data from 41 stations in Saudi Arabia. Data from 31 stations was used in training the NN and the remaining data was used for testing. Input variables to the NN included 4 parameters: latitude, longitude, altitude and sunshine duration. Their sample data was not large enough to allow a credible comparison between the ANN models used and empirical regression models. (Lam et al., 2008) have used Artificial Neural networks ANNs to develop predication models for daily global solar radiation using measured sunshine duration for 40 cities covering 9 major thermal climatic zones and sub-zones in China. (Alam et al., 2009) used ANNs to estimate monthly mean hourly and daily diffuse solar radiation based on weather data from 10 Indian stations which have different climatic conditions. (Alawi & Hinai, 1998) applied ANNs to predict solar radiation in areas not covered by direct measurement instrumentation. The input data that was used for building the network were the location, month, mean pressure, mean temperature, mean vapor pressure, mean relative humidity, mean wind speed and mean duration of sunshine. (Tasadduq et al., 2002) have used neural networks for the prediction of hourly mean values of ambient temperature 24 hours in advance. Full year hourly values of ambient temperature are used to train a neural network model for a coastal location — Jeddah, Saudi Arabia. (Elminir et al., 2005) applied ANN modeling techniques to predict solar radiation data in different spectrum bands from data of meteorology for Helwan (Egypt) meteorology monitoring station. (Rehman & Mohandes, 2008) developed ANN-based estimation GSR for Abha city in Saudi Arabia; by


Introduction
Information about the availability of solar radiation on horizontal surface is essential for the optimum design and study of solar energy systems. For a country like UAE, the efficient application of solar energy seems inevitable because of abundant sunshine available throughout the year. The traditional way of knowing the amount of global solar radiation (GSR) in a particular region is to install pyranometers at as many locations as possible in this region thus requiring daily maintenance and data recording, and consequently increasing cost of GSR data collection. Therefore, it is rather more economical to develop methods to estimate the GSR using climatological parameters (Akhlaque et al., 2009;Kassem et al., 2009;Falayi et al., 2008;El-Sebaii & Trabea, 2005). Many researchers estimated global solar radiation by using artificial neural networks. (Mohandes et al, 1998) applied ANN techniques to predict GSR using weather data from 41 stations in Saudi Arabia. Data from 31 stations was used in training the NN and the remaining data was used for testing. Input variables to the NN included 4 parameters: latitude, longitude, altitude and sunshine duration. Their sample data was not large enough to allow a credible comparison between the ANN models used and empirical regression models. (Lam et al., 2008) have used Artificial Neural networks ANNs to develop predication models for daily global solar radiation using measured sunshine duration for 40 cities covering 9 major thermal climatic zones and sub-zones in China. (Alam et al., 2009) used ANNs to estimate monthly mean hourly and daily diffuse solar radiation based on weather data from 10 Indian stations which have different climatic conditions. (Alawi & Hinai, 1998) applied ANNs to predict solar radiation in areas not covered by direct measurement instrumentation. The input data that was used for building the network were the location, month, mean pressure, mean temperature, mean vapor pressure, mean relative humidity, mean wind speed and mean duration of sunshine. (Tasadduq et al., 2002) have used neural networks for the prediction of hourly mean values of ambient temperature 24 hours in advance. Full year hourly values of ambient temperature are used to train a neural network model for a coastal location -Jeddah, Saudi Arabia. (Elminir et al., 2005) applied ANN modeling techniques to predict solar radiation data in different spectrum bands from data of meteorology for Helwan (Egypt) meteorology monitoring station. (Rehman & Mohandes, 2008) developed ANN-based estimation GSR for Abha city in Saudi Arabia; by www.intechopen.com using different combination of day of year, time day of year, air temperature and relative humidity. (Krishnaiah et al., 2007) considered the artificial neural network (ANN) approach for estimating hourly global solar radiation (HGSR) in India. The ANN models are presented and implemented on real meteorological data. The solar radiation data from 7 stations are used for training the ANN and data from two stations are used for testing the predicted values. (Mubiru, 2008) predicted a monthly average daily total solar irradiation on a horizontal surface for locations in Uganda by using artificial neural network technique, where both geographical and meteorological data are used to develop model. For countries like UAE, where solar radiation has significant strength, the average annual solar hours is 3568 h (i.e. 9.7 h/day), which corresponds to an average annual solar radiation of approximately 2285 kWh/m 2 (i.e. 6.3 kWh/m 2 per day) (Assi & Jama, 2010). This book chapter will show the potential of MATLAB tools in writing scripts that help in developing Artificial Neural Network (ANN) models for the prediction of global solar radiation in Al Ain city, UAE. The developed scripts use built-in commands and functions for customizing data processing, network architecture, training algorithms and testing performance of the ANN models.

Neural network
A neural network is a massively parallel distributed processor made up of simple processing units that have a natural tendency for storing experiential knowledge and making it available for us. Artificial neural network (ANN) is a type of Artificial Intelligence technique that mimics the behavior of the human brain (Haykin, 2009). ANNs have the ability to model linear and non-linear systems without the need to make assumptions implicitly as in most traditional statistical approaches. They have been applied in various aspects of science and engineering (Rivard & Zmeureanu, 2005;Chantasut et al., 2005). ANNs can be grouped into two major categories: feed-forward and feedback (recurrent) networks. In the former network, no loops are formed by the network connections, while one or more loops may exist in the latter. The most commonly used family of feed-forward networks is a layered network in which neurons are organized into layers with connections strictly in one direction from one layer to another (Jain et al., 1996).

Multilayer preceptor (MLP)
MLPs are the most common type of feed-forward networks. Fig. 1 shows an MLP which has three types of layers: an input layer, an output layer and a hidden layer. Neurons in input layer only act as buffers for distributing the input signals x i (i=1, 2 …n) to neurons in the hidden layer. Each neuron j (Fig. 2) in the hidden layer sums up its input signals x i after weighting them with the strengths of the respective connections w ji from the input layer and computes its output y j as a function f of the sum. (1) f can be a simple threshold function or a sigmoidal, hyperbolic tangent or radial basis function. www.intechopen.com

Input Layer
Hidden Layer (s) Output Layer The output of neurons in the output layer is computed similarly. The backpropagation algorithm, a gradient descent algorithm, is the most commonly adopted MLP training algorithm. It gives the change ∆w ji the weight of a connection between neurons iand j as follows: x 1 x i x n w ji y j

Fig. 2. Detail of the perceptron process
where η is a parameter called the learning rate and δ j is a factor depending on whether neuron j is an input neuron or a hidden neuron. For output neurons, and for hidden neurons In Eq. (3), net j is the total weighted sum of input signals to neurons j and y j (t) is the target output for neuron j.
As there are no target outputs for hidden neurons, in Eq. (4), the difference between the target and actual output of a hidden neurons j is replaced by the weighted sum of the δ q terms already obtained for neurons q connected to the output of j. The process begins with the output layer, the δ term is computed for neurons in all layers and weight updates determined for all connections, iteratively. The weight updating process can happen after the presentation of each training pattern (pattern-based training) or after the presentation of the whole set of training patterns (batch training). Training epoch is completed when all training patterns have been presented once to the MLP. A commonly adopted method to speed up the training is to add a "momentum" term to Eq. (5) which effectively lets the previous weight change influence the new weight change: where ∆w ij (I + 1) and ∆w ij (I) are weight changes in epochs (I + 1) and (I), respectively, and µ is "momentum" coefficient (Jayawardena & Fernando, 1998).

Radial Basis Function (RBF)
Radial basis function network consists of three layers Fig 3. The input layer has neurons with a linear function that simply feed the input signals to the hidden layer. Moreover, the connections between the input and hidden layer are not weighted. The hidden neurons are processing units that perform the radial basis function. Each unit is mathematically defined as Center .

Fig. 3. Radial basis function network
The j th input data point x j denotes the center of the radial basis function, and the vector x is the pattern applied to input layer. Selecting the basis function is not crucial to the performance of the network the most common being the Gaussian basis function which is used in this study. It is defined as The output neuron is a summing unit to produce the output as a weighted sum of the hidden layer outputs as shown by (Haykin, 2009;Jayawardena & Fernando, 1998)

Problem definition
Building reliable solar energy systems regardless whether the system is a photovoltaic or thermal solar energy system requires information on the GSR in the region where the system is to be built. Many countries developed models for the GSR to predict the solar radiation and help in building solar energy systems. In UAE we still lack such models for GSR, and this work is the first attempt to generate a weather model for Al Ain city (see Fig.4 for its geographical location in the UAE) and which will later be extended to other UAE cities.
In this work, the maximum temperature (°C), mean wind speed(knot), sunshine(hours), mean relative humidity(%) and solar radiation ( The radius value (known as spread) of the function and the number of neurons are varied for best performance of the RBF network. Basically, the larger the value of spread, the smoother the function approximation will be. However, if the spread value is too large, many neurons may be required to fit the rapidly-changing function. On the other hand, very small spread values will require many neurons in order to fit the smooth function and networks cannot be generalized well (Beale et al, 2010). In this paper, the spread will be varied between 1 and 60 whereas the number of neurons is changed between 5 and 600 in order to come up with the most suitable ANN prediction models.

Designing ANN models
Designing ANN models follows a number of systemic procedures. In general, there are five basics steps: (1) collecting data, (2) preprocessing data, (3) building the network, (4) train, and (5) test performance of model as shown in Fig 6.

Data collection
Collecting and preparing sample data is the first step in designing ANN models. As it is outlined in section 3, measurement data of maximum temperature (°C), mean wind speed(knot), sunshine (hours), mean relative humidity(%) and solar radiation (kWh/m 2 ) for Al Ain city for 13-year period from 1995 to 2007 was collected through the NCMS.

Data pre-processing
After data collection, three data preprocessing procedures are conducted to train the ANNs more efficiently. These procedures are: (1) solve the problem of missing data, (2) normalize data and (3) randomize data. The missing data are replaced by the average of neighboring values during the same week. Normalization procedure before presenting the input data to the network is generally a good practice, since mixing variables with large magnitudes and small magnitudes will confuse the learning algorithm on the importance of each variable and may force it to finally reject the variable with the smaller magnitude (Tymvios et al., 2008).

Building the network
At this stage, the designer specifies the number of hidden layers, neurons in each layer, transfer function in each layer, training function, weight/bias learning function, and performance function. In this work, multilayer perceptron (MLP) and radial basis function (RBF) networks are used.

Training the network
During the training process, the weights are adjusted in order to make the actual outputs (predicated) close to the target (measured) outputs of the network. In this study, 10-year data period from 1995 to 2004 are used for training. As it is outlined in section 3, fourteen different types of training algorithms are investigated for developing the MLP network. MATLAB provides built-in transfer functions which are used in this study; linear (purelin), Hyperbolic Tangent Sigmoid (logsig) and Logistic Sigmoid (tansig). The graphical illustration and mathematical form of such functions are shown in Table 2.

Function Name Graphical Illustration Mathematical form
Linear

Testing the network
The next step is to test the performance of the developed model. At this stage unseen data are exposed to the model. For the case study of Al-Ain city, weather data between 2005 and 2007 have been used for testing the ANN models.
In order to evaluate the performance of the developed ANN models quantitatively and verify whether there is any underlying trend in performance of ANN models, statistical analysis involving the coefficient of determination (R 2 ), the root mean square error (RMSE), and the mean bias error (MBE) were conducted. RMSE provides information on the short term performance which is a measure of the variation of predicated values around the measured data. The lower the RMSE, the more accurate is the estimation. MBE is an indication of the average deviation of the predicted values from the corresponding measured data and can provide information on long term performance of the models; the lower MBE the better is the long term model prediction. where I p,I denotes the predicted GSR on horizontal surface in kWh/m 2 , I i denotes the measured GSR on horizontal surface in kWh/m 2 , and n denotes the number of observations.

Programming the neural network model
MATLAB is a numerical computing environment and also a programming language. It allows easy matrix manipulation, plotting of functions and data, implementation of algorithms, creating user interfaces and interfacing with programs in other languages. The Neural Network Toolbox contains the MATLAB tools for designing, implementing, visualizing and simulating neural networks. It also provides comprehensive support for many proven network paradigms, as well as graphical user interfaces (GUIs) that e n a b l e t h e u s e r t o d e s i g n a n d m a n a g e n e u r a l n e t w o r k s i n a v e r y s i m p l e way(http://www.mathworks.com/products/neuralnet). In this paper MATLAB (R2010a) is used to write script files for developing MLP and RBF ANN models and performance functions for calculating the model performance error statistics such as R 2 , RMSE and MBE. Fig. 7 shows the procedural steps to develop the ANN models. The MLP program starts by reading data from an Excel file (Training.xlsx and Testing.xlsx). "xlsread" function is used to read the data specified in the Excel file. Data_Inputs = xlsread('AlAin_TrainingSet_1995-2004_Model_1.xlsx'); Testing_Data = xlsread('AlAin_TestingSet_2005-2007_Model1.xlsx'); Training data samples are randomized by using the function "randperm". This function returns a random permutation of the 3650 integers (training samples) while the order of columns is kept unchanged (T, W, SH, RH & GSR). Shuffling_Inputs = Data_Inputs(randperm(3650),1:5); Next, the input variables (maximum temperature, mean wind speed, sunshine and mean relative humidity) and output variable (global solar radiation) are specified for training and testing. The first four columns present the inputs while the last column denotes the output data (target). The total number of training samples is 3650 ( [1995 -2004] Target_Set = Shuffling_Inputs(1:3650,5) % specify target set [1995 -2004] Testing_Set = Testing_Data(1:1095,1:4) % specify Testing set [2005][2006][2007] Testing_Target_Set = Testing_Data(1:1095, 5) % specify Testing set, Target [2005][2006][2007] A normalization process is applied for training and testing the data. Function "mapstd" is used to normalize the inputs and target in order to yield zero mean and unity standard deviation. The output is converted back into the same unit that is used for the original target. Training and testing data are converted to rows (MATLAB requires that all data must be presented as row vectors).
[pn, ps] = mapstd(Training_Set'); [tn, ts] = mapstd(Target_Set'); The settings structures pn and tn contain normalized values of inputs and output, respectively, while ps and ts contain the means and standard deviations of the original inputs and targets. MATLAB helps devise the MLP model by using the built-in function "newff" which creates a feed-forward back-propagation network. The designer can specify the number of hidden layers, the neurons in each layer, the transfer function in each layer, the training function, the weight/bias learning function, and the performance function. Moreover, this command will automatically initialize the weights and biases. The function is called as follows: MyNetwork = newff(pn,tn, [i] , {tf}); where the arguments pn and tn are the normalized input and output, respectively. [i] implies that the network structure consists of one hidden layer and "i" neurons. For "j" hidden layers we use [i, j]. The argument {tf} denotes the transfer function of the i th layer. The network is next configured as follows MyNetwork.trainFcn = LM; MyNetwork.trainparam.min_grad = 0.00000001; MyNetwork.trainParam.epochs = 1000; MyNetwork.trainParam.lr = 0.4; MyNetwork.trainParam.max_fail =20; where "trainFcn": defines the function used to train the network. It can be set to the name of any training function (LM ='trainlm'; %Levenberg-Marquardt back-propagation) "trainparam.min_grad": denotes the minimum performance gradient "trainParam.epochs": denotes the maximum number of epochs to train "trainParam.lr": denotes the learning rate "trainParam.max_fail": denotes the maximum validation failures The function "newrb" is used for iteratively creating an RBF network by including one neuron at a time. Neurons are added to the network until the sum squared error is found to be very small or the maximum numbers of neurons are reached. The call for this function is: MyNetwork= newrb(pn,tn,goal,spread, mn, df); where pn and tn are the input and target, respectively. The argument "goal" denotes the mean squared error goal, set here to be 0.01, and "spread" represents the spread of radial basis functions, changed between 1 and 60 and denoted here as "i". The argument "mn" is the maximum number of neurons, changed between 5 and 600 and denoted here "j', while "df" represents the number of neurons to add between displays and is set to 50. The MLP network is trained using the "trainFcn" and "trainParam" train functions. The trained network is then saved in MATLAB by calling the functions MyNetwork = train(MyNetwork,pn,tn); save(NetworkName,'MyNetwork'); "NetworkName" is a variable name which can be changed according to the network train function and configuration in order to yield a meaningful name.
When the training is complete, the network performance should be checked. Therefore, unseen data (testing) will be exposed to the network. The testing simulation process is called with the statement: y = sim(MyNetwork, testn); % simulate network Fig. 8 and Fig. 9 show, respectively, screen captions of the MLP and RBF ANN training windows obtained using the "nntraintool" GUI toolbox in MATLAB.

Fig. 8. MLP network Training Window
The output from the network (daily GSR) is denormalized in order to compare it with the measured data. After the network has been trained, one should use these settings to transform any future inputs that are applied to the network. y_again = mapstd('reverse',y, targets) % denormlized The performance function is then called to calculate and store the performance error statistics as follows Daily_Result = performance(y,t,'all', 'v') % calculate statstics Daily measured and predicted data are processed to compute and store the daily mean values along with corresponding error statistics. Afterwards, the daily mean of measured and predicted data are processed to produce monthly mean of measured as well as predicted data. This process is followed by using a MATLAB script to calculate the statistical results. The last step concludes with writing the mean daily and monthly test results along with corresponding statistical data to an Excel sheet. These steps are performed repeatedly where in MLP the control loop is a number of hidden layers and a number of neurons, while in RBF, the loop is controlled by spread and number of neurons. The stored results are checked and compared for all tested models in order to find the optimal network structure which has highest R 2 and lowest RMSE and MBE.

Results and discussion
This section presents the best achieved results for both the MLP and RBF ANN models. Tables 3 and 4 show the computed values of R 2 , RMSE and MBE for the developed ANN models (MLP and RBF) considering different network structures. For the network structure identification used in the second column of Tables 3-4, the first number indicates number of neurons in the input layer, the last number represents neurons in the output layer, and the numbers in between represent neurons in the hidden layers. From Table 3 we note that model one is the best among all the investigated MLP models for long performance prediction as it yields the lowest values of MBE, RMSE and a 92 % coefficient of determination. The input parameters used in the selected model are the maximum temperature, daily sunshine hours, and the mean relative humidity. Table 4 on the other hand, shows that model four is the best among all the investigated RBF models; the input parameters for this model are again the maximum temperature, sunshine hours, and mean relative humidity. In the seventh, eighth and eleventh models, the MLP technique has better accuracy for predicting the average monthly GSR compared to RBF. For these models, the computed MBE values of 0.00376, 0.06900 and 0.00193, respectively, are promising and provide good accuracy for long term prediction. On the other hand, some RBF models perform better in terms of low MBE values.  Fig. 10 shows the comparison between predicted ANN models and the measured GSR data for all the eleven MLP and RBF-based networks models. This validation is done using measured GSR data for years [2005][2006][2007]. The predicted ANN models provide a very good prediction of monthly GSR behavior in Al-Ain, city.

Conclusion
In this work, MATLAB tools are used to predict monthly average global solar radiation in Al Ain city -UAE. Weather data between 1995 and 2004 are used for training the neural network, while data between 2005 and 2007 are used for testing. Eleven models with different input combinations are modeled with MLP and RBF ANN techniques. The obtained results confirm the superiority of the RBF technique over the MLP technique in most of the cases, namely, models 2-6 and 9-10, with deterministic coefficients near 90 % and low MBE, MAPE and RMSE values. Moreover, ANN models have in general good performance even if one or more input parameters are unavailable. Currently, our focus is on modeling the GSR for other UAE cities and comparing the optimal ANN models with classical empirical regression and time-series regression models being investigated by this chapter's co-authors.