Yapay sinir ağları ile trafik yoğunluğu tahmini
Prediction of traffic congestion by artificial neural networks
Yazar: MURAT NAS
Danışman: PROF. DR. NESLİHAN SERAP ŞENGÖR
İstanbul Teknik Üniversitesi / Fen Bilimleri Enstitüsü / Elektronik ve Haberleşme Mühendisliği Ana Bilim Dalı / Elektronik Mühendisliği Bilim Dalı
Derece: Yüksek Lisans, 2024
Konu: Elektrik ve Elektronik Mühendisliği = Electrical and Electronics Engineering

Özet:
Bu çalışmada ileri beslemeli ve yinelemeli sinir ağları kullanılarak İstanbul şehrine ait verilerle tek değişkenli ve çok değişkenli trafik yoğunluğu tahmini üzerine bir çalışma yapılmıştır. Trafik yoğunluğu tahmini bir zaman serisi tahmin problemi olmasına ve daha çok yinelemeli yapay sinir ağları ile çözülmesi tercih edilmesine rağmen, zaman gecikmesi ile tanımlanan girdilere sahip ileri beslemeli yapılar da kullanılmaktadır. 
 
Tez kapsamında kullanılan veriler İstanbul Büyükşehir Belediyesi'nden alınmıştır ve farklı yapay sinir ağlarında  kullanılmak üzere pencere kaydırma yöntemiyle yeniden düzenlenmiştir. 
 
Tez çalışması kapsamında ele alınan ve Python'da kodları yazılan ileri yol ağları Çok Katmanlı Algılayıcı (MLP) ve Radyal Temel Fonksiyon (RBF) ağlarıdır. Ayrıca bu iki ileri beslemeli yapıyı MLP - RBF ve RBF - MLP olarak birleştiren iki hibrit yapı da önerilmiştir. Kodların kendi bünyemizde geliştirilmesi, hibrit yapılar için sonuç almayı kolaylaştırmıştır.

Ayrıca, Keras kütüphanesi kullanılarak ileri yol ağlarından MLP, RBF, destek vektör makinası (SVM) ve yinelemeli yapay sinir ağlarından yaygın kullanımı olan uzun kısa süreli bellek (LSTM), geçitli yineleme birimi (GRU) modellerine ilişkin Python kodu
yazılarak farklı iterasyon ve veri setleri ile belirtilen ağlar eğitilmiştir.
 
Saatlik trafik verileri tam bir yılı kapsadığından her günün ve mevsimin özellikleri verilerde kapsanmaktadır. Böylece eğitim setinde hava durumu, günlük yoğun saatler, tatiller ve hafta sonları dikkate alınmış olmaktadır. 
 
Elde edilen sonuçlar farklı değerlendirme ölçütleri ele alınarak karşılaştırılmıştır. Model tahmin hatası ölçüm metodu olarak ortalama mutlak yüzdesel hata (MAPE), kök ortalama karesel hata (RMSE), simetrik ortalama mutlak yüzdesel hata (SMAPE), ortalama mutlak ölçeklenmiş hata (MASE) ve ortadeğer mutlak yüzdesel hata (MdAPE) kullanılmıştır.

Abstract:
In this study, a study on univariate and multivariate traffic density prediction with data from the city of Istanbul was conducted using feed-forward and recurrent neural networks. Although traffic density prediction is a time series prediction problem and is preferred to be solved with recursive artificial neural networks, feed-forward structures with inputs defined by time lag are also used.

The data, which were used within the scope of the thesis study, are obtained from Istanbul Metropolitan Municipality and reorganized with window sliding method to be used in various artificial neural networks.

Time series data can be structured as a supervised learning problem by using values from the previous time step to predict the value at the next time step. The sliding window method is a method that relies on using previous time steps to predict the next time step. The size of the sliding window is determined by the number of previous time steps. In this study, the sliding window size was chosen as 6.

Data sets are created with 6 past and 3 future values for multi-step forecasting with the window sliding method. Our goal is to estimate the average speed, for this purpose we want to predict the 3-hour future average speed for 3-hour using 6 hours of past data.

Time series that will be formed from data sets are of two types: univariate and multivariate. A multivariate time series data set includes the number of individual vehicles, the average speed, maximum speed and minimum speed of these vehicles while univariate data set includes only average speed.
While data preparation we create univariate time series data sets to predict the future average speed. If we use a multivariate time series data sets we create an input vector where four different variables oast values are considered together to predict the future average speed.

5-month, 7-month and 12-month data sets were created by combining monthly data from each of the three individual sensors. Each sensor data set was used independently and was not correlated with each other. The data sets are split into $60\%$ training data and $40\%$ test data.

Feed-forward networks, which were discussed within the scope of the thesis study and whose codes were written in Python, are Multi Layer Perceptron (MLP) and Radial Basis Function (RBF) networks. Two hybrid structure combining these two feed-forward structures are also proposed. The codes of these artificial neural network are developed in Python. Having codes developed in-house made it easier to get results for the hybrid structures.

The first type of our feed-forward networks; MLP is a feedforward artificial neural network with multiple layers, including an input layer, one or more hidden layers, and an output layer. Each layer is fully connected to the next layers. MLP Neural Network works only in the forward direction. Each node passes its value to the coming node only in the forward direction. The MLP neural network uses Backpropagation algorithm as training model. As, MLP is feedforward structure, we need to organize the inputs and outputs in such a way that the dynamic property of the process considered can be reflected on the network. To accomplish this, a number of sequential past values of speed obtained from the sensors are given as inputs and as outputs the subsecutive speed values are introduced to the network. 

We first determine our hyperparameters for our Multi Layer Perceptron model with the Python program. These are; the number of hidden layers, the number of neurons in the hidden layers, the learning rate and momentum values, and finally the randomly generated starting and bias values for the weights. As the activation function, we chose the Hyperbolic Tangent Function, which we experienced to be more successful in time series forecasting.

At the stage of entering data into our model, we calculate the hidden layer outputs by going forward layer by layer and looping as number of rows of training data set.
After the output layer is calculated, we calculate the error and calculate the local gradients, which is the first step of the backpropagation process, from the output layer backwards from the last hidden layer to the first hidden layer.
Then, we move on to the step of updating the weights with the learning rate and momentum parameters using the gradient descent method. Again, we update the weights from the output layer backwards, from the last hidden layer to the first hidden layer. We save instant errors as an array at the end of the operations. When the training loop of data set is completed, we calculate the average value of the instant errors, repeat these calculations in another loop as many as the number of iterations (epochs) and find the Average Error value for each iteration. Our goal here is to stop the training if the error function does not go as we want. We complete the training phase by defining early stopping criteria.

After our weights have been determined, we re-input the training data to our model with the weight values we obtained and make predictions. We calculate Training error values by comparing the prediction results with the actual network values.
We repeat the same process by giving the Test Data set that we have determined for testing, which the network has never seen before during the training phase, as input to our network and making predictions. We calculate Test error values by comparing the prediction results with the actual network values.

The second type of our feed-forward networks; Radial Basis Functions neural networks are a type of feed-forward neural networks that use radial basis functions as activation functions. Unlike traditional activation functions such as Sigmoid or ReLU functions, radial basis functions offer flexibility by enabling nonlinearity in network modeling. The basic idea behind RBF networks is to approximate the desired output by creating weighted combinations of radial basis functions centered on specific data points. Training an RBF neural network involves two main steps: center selection and weight determination. Center selection aims to identify representative data points that serve as centers for radial basis functions. The weight determination optimization process can be accomplished through techniques such as least squares regression or gradient descent.

At this stage, we configure RBF model adapted to the data set in this study. We create random starting values for the center and sigma parameters, and during the training of the network, we optimize these values by training them with the gradient descent method, like the weights.

At this context, we design a hybrid structure by combining the RBF Network and MLP Network. We want to observe the contributions of using the RBF network as the first layer of the network and giving the data in clustered form to be entered into the MLP network as the next layer. The network design was created by combining the networks connecting them one after the other. The RBF output layer is removed and connected as input to the first hidden layer of the MLP network after the activations are calculated using the Gaussian radial basis function in the first hidden layer of the RBF network .

As an alternative hybrid model, we use the MLP network as the first layer of the network and connect the RBF network to this network as the next layer. In our simulation trials, we observed that this hybrid network gives better results than the previous RBF-MLP hybrid network.

Also, using the Keras library, Python code was created using feed-forward neural networks MLP, RBF, Support Vector Machines (SVM) and Long-Short Term Memory (LSTM), Gated Recurrent Unit (GRU) models, which are widely used in recursive artificial neural networks. It was trained with different iterations and data sets.

The data includes one whole year with one-hour lap, so the properties of each day and season is covered with the data.Thus, the weather condition, daily rush hours, holidays and weekends are all considered in the training set. 
 
The results obtained are compared with different performance measures. Mean Absolute Percentage Error (MAPE), Root Mean Squared Error (RMSE), Symmetric Mean Absolute Percentage Error (SMAPE), Mean Absolute Scaled Error (MASE) and Median Absolute Percentage Error (MdAPE) were used as model prediction error measurement methods.