current position:Home>Analysis of 43 cases of MATLAB neural network: Chapter 33 prediction algorithm of fuzzy neural network -- water quality evaluation of Jialing River

Analysis of 43 cases of MATLAB neural network: Chapter 33 prediction algorithm of fuzzy neural network -- water quality evaluation of Jialing River

2022-06-24 09:43:52mozun2020

《MATLAB neural network 43 A case study 》: The first 33 Chapter Prediction algorithm of fuzzy neural network —— Water quality assessment of Jialing River

1. Preface

《MATLAB neural network 43 A case study 》 yes MATLAB Technology Forum (www.matlabsky.com) planning , Led by teacher wangxiaochuan ,2013 Beijing University of Aeronautics and Astronautics Press MATLAB A book for tools MATLAB Example teaching books , Is in 《MATLAB neural network 30 A case study 》 On the basis of modification 、 Complementary , Adhering to “ Theoretical explanation — case analysis — Application extension ” This feature , Help readers to be more intuitive 、 Learn neural networks vividly .

《MATLAB neural network 43 A case study 》 share 43 Chapter , The content covers common neural networks (BP、RBF、SOM、Hopfield、Elman、LVQ、Kohonen、GRNN、NARX etc. ) And related intelligent algorithms (SVM、 Decision tree 、 Random forests 、 Extreme learning machine, etc ). meanwhile , Some chapters also cover common optimization algorithms ( Genetic algorithm (ga) 、 Ant colony algorithm, etc ) And neural network . Besides ,《MATLAB neural network 43 A case study 》 It also introduces MATLAB R2012b New functions and features of neural network toolbox in , Such as neural network parallel computing 、 Custom neural networks 、 Efficient programming of neural network, etc .

In recent years, with the rise of artificial intelligence research , The related direction of neural network has also ushered in another upsurge of research , Because of its outstanding performance in the field of signal processing , The neural network method is also being applied to various applications in the direction of speech and image , This paper combines the cases in the book , It is simulated and realized , It's a relearning , I hope I can review the old and know the new , Strengthen and improve my understanding and practice of the application of neural network in various fields . I just started this book on catching more fish , Let's start the simulation example , Mainly to introduce the source code application examples in each chapter , This paper is mainly based on MATLAB2015b(32 position ) Platform simulation implementation , This is an example of the prediction algorithm of fuzzy neural network in Chapter 33 of this book , Don't talk much , Start !

2. MATLAB Simulation example

open MATLAB, Click on “ Home page ”, Click on “ open ”, Find the sample file
 Insert picture description here
Choose FuzzyNet.m, Click on “ open ”

FuzzyNet.m Source code is as follows :

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function :  This code is a water quality evaluation code based on fuzzy neural network 
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-20
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%  This code is a water quality evaluation code based on fuzzy neural network 
%
% <html>
% <table border="0" width="600px" id="table1">	<tr>		<td><b><font size="2"> The author of the case states that :</font></b></td>	</tr>	<tr><td><span class="comment"><font size="2">1: I have been stationed here for a long time <a target="_blank" href="http://www.ilovematlab.cn/forum-158-1.html"><font color="#0000FF"> plate </font></a> in , Ask questions about the case , Answer every question . The official website of this set of books is :<a href="http://video.ourmatlab.com">video.ourmatlab.com</a></font></span></td></tr><tr>		<td><font size="2">2: Click here <a href="http://union.dangdang.com/transfer/transfer.aspx?from=P-284318&backurl=http://www.dangdang.com/"> Book from Dangdang </a><a href="http://union.dangdang.com/transfer/transfer.aspx?from=P-284318&backurl=http://www.dangdang.com/">《Matlab neural network 30 A case study 》</a>.</td></tr><tr>	<td><p class="comment"></font><font size="2">3</font><font size="2">: This case has a supporting teaching video , Video download method <a href="http://video.ourmatlab.com/vbuy.html">video.ourmatlab.com/vbuy.html</a></font><font size="2">. </font></p></td>	</tr>			<tr>		<td><span class="comment"><font size="2">		4: This case is an original case , Reprint please indicate the source (《Matlab neural network 30 A case study 》).</font></span></td>	</tr>		<tr>		<td><span class="comment"><font size="2">		5: If this case happens to be relevant to your research , We welcome your comments , Requirement etc. , After we consider it, we can add it to the case .</font></span></td>	</tr>		</table>
% </html>
%%  Clear environment variables 
clc
clear
tic
%%  Parameter initialization 
xite=0.001;
alfa=0.05;

% Network nodes 
I=6;   % Enter the number of nodes 
M=12;  % Number of hidden nodes 
O=1;   % Number of output nodes 

% Coefficient initialization 
p0=0.3*ones(M,1);p0_1=p0;p0_2=p0_1;
p1=0.3*ones(M,1);p1_1=p1;p1_2=p1_1;
p2=0.3*ones(M,1);p2_1=p2;p2_2=p2_1;
p3=0.3*ones(M,1);p3_1=p3;p3_2=p3_1;
p4=0.3*ones(M,1);p4_1=p4;p4_2=p4_1;
p5=0.3*ones(M,1);p5_1=p5;p5_2=p5_1;
p6=0.3*ones(M,1);p6_1=p6;p6_2=p6_1;

% Parameter initialization 
c=1+rands(M,I);c_1=c;c_2=c_1;
b=1+rands(M,I);b_1=b;b_2=b_1;

maxgen=100; % Number of evolutions 

% Network test data , And normalize the data 
load data1 input_train output_train input_test output_test

% Select and connect the sample input and output data 
[inputn,inputps]=mapminmax(input_train);
[outputn,outputps]=mapminmax(output_train);
[n,m]=size(input_train);

%%  Network training 
% Loop start , Evolutionary networks 
for iii=1:maxgen
    iii;
    for k=1:m        
        x=inputn(:,k);
        
        % Output layer settlement 
        for i=1:I
            for j=1:M
                u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
            end
        end
        
        % Fuzzy rule calculation 
        for i=1:M
            w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i);
        end    
        addw=sum(w);
        
        for i=1:M
            yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6);
        end
        
        addyw=yi*w';
        % Network prediction calculation 
        yn(k)=addyw/addw;
        e(k)=outputn(k)-yn(k);
        
        % Calculation p The change value of 
        d_p=zeros(M,1);
        d_p=xite*e(k)*w./addw;
        d_p=d_p';
        
        % Calculation b Change value 
        d_b=0*b_1;
        for i=1:M
            for j=1:I
                d_b(i,j)=xite*e(k)*(yi(i)*addw-addyw)*(x(j)-c(i,j))^2*w(i)/(b(i,j)^2*addw^2);
            end
        end  
        
        % to update c Change value 
        for i=1:M
            for j=1:I
                d_c(i,j)=xite*e(k)*(yi(i)*addw-addyw)*2*(x(j)-c(i,j))*w(i)/(b(i,j)*addw^2);
            end
        end
        
        p0=p0_1+ d_p+alfa*(p0_1-p0_2);
        p1=p1_1+ d_p*x(1)+alfa*(p1_1-p1_2);
        p2=p2_1+ d_p*x(2)+alfa*(p2_1-p2_2);
        p3=p3_1+ d_p*x(3)+alfa*(p3_1-p3_2);
        p4=p4_1+ d_p*x(4)+alfa*(p4_1-p4_2);
        p5=p5_1+ d_p*x(5)+alfa*(p5_1-p5_2);
        p6=p6_1+ d_p*x(6)+alfa*(p6_1-p6_2);
            
        b=b_1+d_b+alfa*(b_1-b_2);      
        c=c_1+d_c+alfa*(c_1-c_2);
   
        p0_2=p0_1;p0_1=p0;
        p1_2=p1_1;p1_1=p1;
        p2_2=p2_1;p2_1=p2;
        p3_2=p3_1;p3_1=p3;
        p4_2=p4_1;p4_1=p4;
        p5_2=p5_1;p5_1=p5;
        p6_2=p6_1;p6_1=p6;

        c_2=c_1;c_1=c;   
        b_2=b_1;b_1=b;
        
    end   
    E(iii)=sum(abs(e));

end

figure(1);
plot(outputn,'r')
hold on
plot(yn,'b')
hold on
plot(outputn-yn,'g');
legend(' The actual output ',' Forecast output ',' error ','fontsize',12)
title(' Training data prediction ','fontsize',12)
xlabel(' Sample number ','fontsize',12)
ylabel(' Water quality grade ','fontsize',12)

%%  Network prediction 
% Data normalization 
inputn_test=mapminmax('apply',input_test,inputps);
[n,m]=size(inputn_test)
for k=1:m
    x=inputn_test(:,k);
         
     % Calculate the output middle layer 
     for i=1:I
         for j=1:M
             u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
         end
     end
     
     for i=1:M
         w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i);
     end
                 
     addw=0;
     for i=1:M  
         addw=addw+w(i);
     end
         
     for i=1:M  
         yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6);        
     end
         
     addyw=0;        
     for i=1:M    
         addyw=addyw+yi(i)*w(i);        
     end
         
     % Calculate the output 
     yc(k)=addyw/addw;
end

% Inverse normalization of prediction results 
test_simu=mapminmax('reverse',yc,outputps);
% Make a picture 
figure(2)
plot(output_test,'r')
hold on
plot(test_simu,'b')
hold on
plot(test_simu-output_test,'g')
legend(' The actual output ',' Forecast output ',' error ','fontsize',12)
title(' Test data prediction ','fontsize',12)
xlabel(' Sample number ','fontsize',12)
ylabel(' Water quality grade ','fontsize',12)

%%  The actual water quality forecast of Jialing River 
load  data2 hgsc gjhy dxg
%----------------------------------- Honggong water plant -----------------------------------
zssz=hgsc;
% Data normalization 
inputn_test =mapminmax('apply',zssz,inputps);
[n,m]=size(zssz);

for k=1:1:m
    x=inputn_test(:,k);
        
    % Calculate the output middle layer 
    for i=1:I
        for j=1:M
            u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
        end
    end
    
    for i=1:M
        w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i);
    end
                
    addw=0;
        
    for i=1:M   
        addw=addw+w(i);
    end
        
    for i=1:M   
        yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6);        
    end
        
    addyw=0;        
    for i=1:M    
        addyw=addyw+yi(i)*w(i);        
    end
        
    % Calculate the output 
    szzb(k)=addyw/addw;
end
szzbz1=mapminmax('reverse',szzb,outputps);

for i=1:m
    if szzbz1(i)<=1.5
        szpj1(i)=1;
    elseif szzbz1(i)>1.5&&szzbz1(i)<=2.5
        szpj1(i)=2;
    elseif szzbz1(i)>2.5&&szzbz1(i)<=3.5
        szpj1(i)=3;
    elseif szzbz1(i)>3.5&&szzbz1(i)<=4.5
        szpj1(i)=4;
    else
        szpj1(i)=5;
    end
end
% %----------------------------------- Gaojia Garden -----------------------------------
zssz=gjhy;
inputn_test =mapminmax('apply',zssz,inputps);
[n,m]=size(zssz);

for k=1:1:m
    x=inputn_test(:,k);
        
    % Calculate the output middle layer 
    for i=1:I
        for j=1:M
            u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
        end
    end
    
    for i=1:M
        w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i);
    end
                
    addw=0;
        
    for i=1:M   
        addw=addw+w(i);
    end
        
    for i=1:M   
        yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6);        
    end
        
    addyw=0;        
    for i=1:M    
        addyw=addyw+yi(i)*w(i);        
    end
        
    % Calculate the output 
    szzb(k)=addyw/addw;
end
szzbz2=mapminmax('reverse',szzb,outputps);

for i=1:m
    if szzbz2(i)<=1.5
        szpj2(i)=1;
    elseif szzbz2(i)>1.5&&szzbz2(i)<=2.5
        szpj2(i)=2;
    elseif szzbz2(i)>2.5&&szzbz2(i)<=3.5
        szpj2(i)=3;
    elseif szzbz2(i)>3.5&&szzbz2(i)<=4.5
        szpj2(i)=4;
    else
        szpj2(i)=5;
    end
end
% %----------------------------------- Daxigou water plant -----------------------------------
zssz=dxg;
inputn_test =mapminmax('apply',zssz,inputps);
[n,m]=size(zssz);

for k=1:1:m
    x=inputn_test(:,k);
        
    % Calculate the output middle layer 
    for i=1:I
        for j=1:M
            u(i,j)=exp(-(x(i)-c(j,i))^2/b(j,i));
        end
    end
    
    for i=1:M
        w(i)=u(1,i)*u(2,i)*u(3,i)*u(4,i)*u(5,i)*u(6,i);
    end
                
    addw=0;
        
    for i=1:M   
        addw=addw+w(i);
    end
        
    for i=1:M   
        yi(i)=p0_1(i)+p1_1(i)*x(1)+p2_1(i)*x(2)+p3_1(i)*x(3)+p4_1(i)*x(4)+p5_1(i)*x(5)+p6_1(i)*x(6);        
    end
        
    addyw=0;        
    for i=1:M    
        addyw=addyw+yi(i)*w(i);        
    end
        
    % Calculate the output 
    szzb(k)=addyw/addw;
end
szzbz3=mapminmax('reverse',szzb,outputps);

for i=1:m
    if szzbz3(i)<=1.5
        szpj3(i)=1;
    elseif szzbz3(i)>1.5&&szzbz3(i)<=2.5
        szpj3(i)=2;
    elseif szzbz3(i)>2.5&&szzbz3(i)<=3.5
        szpj3(i)=3;
    elseif szzbz3(i)>3.5&&szzbz3(i)<=4.5
        szpj3(i)=4;
    else
        szpj3(i)=5;
    end
end

figure(3)
plot(szzbz1,'o-r')
hold on
plot(szzbz2,'*-g')
hold on
plot(szzbz3,'*:b')
xlabel(' Time ','fontsize',12)
ylabel(' Predict water quality ','fontsize',12)
legend(' Honggong water plant ',' Gaojia garden water plant ',' Daxigou water plant ','fontsize',12)
toc
% web browser www.matlabsky.com
%%
% <html>
% <table width="656" align="left" >	<tr><td align="center"><p><font size="2"><a href="http://video.ourmatlab.com/">Matlab neural network 30 A case study </a></font></p><p align="left"><font size="2"> Related forums :</font></p><p align="left"><font size="2">《Matlab neural network 30 A case study 》 Official website :<a href="http://video.ourmatlab.com">video.ourmatlab.com</a></font></p><p align="left"><font size="2">Matlab Technology Forum :<a href="http://www.matlabsky.com">www.matlabsky.com</a></font></p><p align="left"><font size="2">M</font><font size="2">atlab Encyclopedia of functions :<a href="http://www.mfun.la">www.mfun.la</a></font></p><p align="left"><font size="2">Matlab Chinese Forum :<a href="http://www.ilovematlab.com">www.ilovematlab.com</a></font></p></td>	</tr></table>
% </html>

Add completed , Click on “ function ”, Start emulating , The output simulation results are as follows :


n =

     6


m =

    50

 Time has passed  2.248055  second .

 Insert picture description here

 Insert picture description here
 Insert picture description here

3. Summary

Fuzzy neural network is the combination of fuzzy theory and neural network , It combines the advantages of neural network and fuzzy theory , Set learning 、 lenovo 、 distinguish 、 Information processing in one . There is a sharp contradiction between the complexity of the system and the required accuracy , So , By simulating human learning and adaptive ability , People put forward the idea of intelligent control . Control theory expert Austrom(1991) stay IFAC It was pointed out at the meeting that : Fuzzy logic control 、 Neural network and expert control are three typical intelligent control methods . Usually, expert systems are based on expert experience , It is not based on the operating data generated by industrial processes , And the imprecision of general complex systems 、 Uncertainty is difficult for even experts in the field to grasp , This makes it very difficult to build an expert system . Fuzzy logic and neural network are two typical intelligent control methods , Each has its advantages and disadvantages , The fusion of fuzzy logic and neural network ——— Fuzzy neural network (Fuzzy Neural Network) It absorbs the advantages of fuzzy logic and neural network , It partly avoids the disadvantages of both , It has become one of the hotspots of intelligent control research .

The fuzzy logic (FL)、 Neural network theory (NN)、 Genetic algorithm (ga) (GA)、 Random reasoning (PR), And the confidence network 、 Chaos theory and partial learning theory are integrated , Formed a collaboration , This fusion is not a disorderly integration of fuzzy logic 、 Neural network and genetic algorithm , Instead, it solves problems in this field through various methods and learns from each other's strong points , Thus, the cooperation of various methods is formed . In this sense , The various methods are complementary , Not competitive . In the collaboration , Various methods play different roles . Through this collaboration , A hybrid intelligent system . Both fuzzy logic and neural network are important intelligent control methods , Fuzzy logic and neural network are two soft computing methods , Learn from others' strong points and close the gap , Form a collaboration ——— Fuzzy neural network . In the same way , Fuzzy PID It is one of the development and extension of fuzzy theory , Interested in the content of this chapter or want to fully learn and understand , It is suggested to study the contents of chapter 33 in the book . Some of these knowledge points will be supplemented on the basis of their own understanding in the later stage , Welcome to study and exchange together .

copyright notice
author[mozun2020],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/175/202206240824251761.html

Random recommended