22. Wavelet neural network time series forecasting traffic flow (with matlab program)

1. Brief description

    Learning Objective: Time Series Prediction of Traffic Flow with Wavelet Neural Networks  

WNN (Wavelet Neural Network) : It is a network developed on the basis of the topology of the error backpropagation neural network, which has a certain similarity with the structure of the neural network. In the wavelet neural network, when the overall signal propagates forward, the error propagates backwards, but different from the neural network, the transfer function of the hidden layer nodes of the wavelet neural network is the wavelet basis function.

         With the rapid development of cities, the number of cars has increased sharply, and traffic congestion has become increasingly serious. The traditional fixed-time traffic light system with unreasonable timing is the main reason for this situation. The wavelet neural network algorithm is used to carry out the research on the forecasting of future traffic flow, and at the same time, the virtual simulation is carried out through the MATLAB software platform combined with the microscopic simulation software VISSIM4.30. The experimental results show that the wavelet neural network can be used to predict short-term traffic flow, and the overall accuracy can reach 90% or higher. Compared with the fixed time length and BP neural network algorithm, this algorithm can greatly improve the vehicle traffic volume. With the development of the economy, the rapid expansion of cities and the sharp increase in the number of motor vehicles, the problem of urban traffic congestion is becoming increasingly serious. In addition to the limited road capacity, the untimely distribution of traditional fixed-time traffic lights has also increased the congestion of urban roads, resulting in unnecessary waste of motor vehicle energy and increased vehicle exhaust emissions. Intelligent Traffic System (ITS for short) is one of the most effective ways to alleviate urban traffic congestion, reduce vehicle exhaust pollution, and improve travel efficiency. The main goal of ITS is to realize the intelligent traffic management and control of the city, and the real-time grasp of the real-time status of traffic information and the prediction of the development trend are the prerequisites for realizing the intelligent management of urban traffic. Short-term traffic flow is one of the basic parameters of short-term traffic, and it is the key basis for intelligent transportation system to make traffic decisions. Short-term traffic forecasting is the basis for predictive and proactive dynamic traffic management. The inner product of the input vector and the wavelet basis are used for weighting to realize the feature extraction of the input layer, and the wavelet basis is used as the feature function of pattern recognition, combining the adaptive function of the neural network and the advantages of time-frequency localization to optimize the network parameters and The way of error space is to use wavelet basis function instead of wavelet neural network algorithm of Sigmoid function. It has been proved by experiments that its nonlinear fitting ability and convergence speed are relatively ideal, and it can predict the short-term traffic flow.

BP (back propagation) neural network is a concept proposed by scientists headed by Ru-melhart and McClelland in 1986. It is a feedforward neural network, which consists of three layers of input layer, hidden layer and output layer to form a one-way neural network. Each neuron starts input from the input layer, the middle layer receives the input from the upper level, and outputs to the next level until the end of the output layer. There is no connection between neurons in the same layer, and the transmission of information between layers only advances in one direction. Therefore, the feedforward of the feedforward neural network is only used to calculate the output of the network, and does not adjust the parameter matrix of the network. A simple BP neural network can only perform data processing by adjusting weights and thresholds, and it is easy to fall into problems such as local minima and low real-time performance. An optimization algorithm is needed to optimize its convergence speed and global optimization ability to improve its practical application ability.

 

2. Code


%% Learning Objective: Wavelet Neural Network Time Series Forecasting Traffic Flow
%% Clear the environment variable
clc
clear

%% Network parameter configuration
load traffic_flux input output input_test output_test

M=size(input,2); %Number of input nodesN
=size(output,2);%Number of output nodes

n=6; %Number of hidden layer nodes
lr1=0.01; %Learning probability
lr2=0.001; %Learning probability
maxgen=100; %Number of iterations

%% 权值初始化
Wjk=randn(n,M);Wjk_1=Wjk;Wjk_2=Wjk_1;
We=randn(N,n);We_1=We;We_2=We_1;
a=randn(1,n);a_1=a;a_2=a_1;
b=randn(1,n);b_1=b;b_2=b_1;

%% Node initialization
y=zeros(1,N);
net=zeros(1,n);
net_ab=zeros(1,n);

%% Weight learning incremental initialization
d_Wjk=zeros(n,M);
d_Wij=zeros(N,n);
d_a=zeros(1,n);
d_b=zeros(1,n);

%% Input and output data normalization
[inputn,inputps]=mapminmax(input');
[outputn,outputps]=mapminmax(output'); 
inputn=inputn';
​​outputn=outputn';

%% network training
for i=1:maxgen
    
    % error accumulation
    error(i)=0;
    
    % loop training
    for kk=1:size(input,1)
        x=inputn(kk,:);
        yqw=outputn(kk,: );
   
        for j=1:n
            for k=1:M
                net(j)=net(j)+Wjk(j,k)*x(k);
                net_ab(j)=(net(j)-b(j ))/a(j);
            end
            temp=mymorlet(net_ab(j));
            for k=1:N
                y=y+Wij(k,j)*temp; % wavelet function
            end
        end
        
        % calculation error and
        error(i )=error(i)+sum(abs(yqw-y));
        
        %weight adjustment
        for j=1:n
            %calculate d_Wij
            temp=mymorlet(net_ab(j));
            for k=1:N
                d_Wij(k,j)=d_Wij(k,j)-(yqw(k)-y(k))*temp;
            end
            % calculationd_Wjk
            temp=d_mymorlet(net_ab(j));
            for k=1:M
                for l=1:N
                    d_Wjk(j,k)=d_Wjk(j,k)+(yqw(l)-y(l))*Wij(l,j) ;
                end
                d_Wjk(j,k)=-d_Wjk(j,k)*temp*x(k)/a(j);
            end
            % calculated_b
            for k=1:N
                d_b(j)=d_b(j)+(yqw(k)-y(k))*Wij(k,j);
            end
            d_b(j)=d_b(j)*temp/a(j);
            % calculated_a
            for k=1:N
                d_a(j)=d_a(j)+(yqw(k)-y(k))*Wij(k,j);
            end
            d_a(j)=d_a(j)*temp*((net(j)-b(j))/b(j))/a(j);
        end
        
        %权值参数更新      
        Wij=Wij-lr1*d_Wij;
        Wjk=Wjk-lr1*d_Wjk;
        b=b-lr2*d_b;
        a=a-lr2*d_a;
    
        d_Wjk=zeros(n,M);
        d_Wij=zeros(N,n);
        d_a=zeros(1,n);
        d_b=zeros(1,n);

        y=zeros(1,N);
        net=zeros(1,n);
        net_ab=zeros(1,n);
        
        Wjk_1=Wjk;Wjk_2=Wjk_1;
        We_1=We;We_2=We_1;
        a_1=a;a_2=a_1;
        b_1=b;b_2=b_1;
    end
end

%% network prediction
% prediction input normalization
x=mapminmax('apply',input_test',inputps);
x=x';

% Network prediction
for i=1:92
    x_test=x(i,:);

    for j=1:1:n
        for k=1:1:M
            net(j)=net(j)+Wjk(j,k)*x_test(k);
            net_ab(j)=(net(j)-b(j))/a(j);
        end
        temp=mymorlet(net_ab(j));
        for k=1:N
            y(k)=y(k)+Wij(k,j)*temp ; 
        end
    end

    yuce(i)=y(k);
    y=zeros(1,N);
    net=zeros(1,n);
    net_ab=zeros(1,n);
end
% predicted output 反归一化
inn=mapminmax('reverse',yuce,outputps);

%% Results analysis
figure(1)
plot(ynn,'r*:')
hold on
plot(output_test,'bo--')
title('Predicted traffic flow','fontsize',12)
legend('Predicted traffic flow ','actual traffic flow')
xlabel('time point')
ylabel('traffic flow')

 

3. Running results

69a6ea0d14e44a9bad0dc96785065fa2.png

 

 

Guess you like

Origin blog.csdn.net/m0_57943157/article/details/130996347