Computational intelligence fuzzy set algorithm

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/WWQ0726/article/details/102683444

BACKGROUND Title: The controller determines the operation time of the device according to the indoor temperature and humidity. Humidity and temperature as input variables, output variables of operation time.

1. Establish a system of fuzzy sets

(1) Code Display

Fuzzy Controller%
a = newfis ( 'fuzzf') ;% create a new fuzzy inference system

Input%. 1
F1 =. 1; 
A = addvar (A, 'INPUT', 'e', [- 2 * F1 * F1,2]);                   
 % e added fuzzy linguistic variables
a = addmf (a, 'input ', . 1, 'NB', 'ZMF', [- 2 * F1, F1 * -1]);          
 % e added fuzzy membership functions of linguistic variables (z type)
% addmf a = (a, 'INPUT',. 1 , 'the NM', 'trimf', [-. 3 * F1, f1,0 -2 *]);      
  % triangular membership function
a = addmf (a, 'input ', 1, 'NS', 'trimf', [F1 * -2, -1 * f1,0]); 
A = addmf (A, 'INPUT',. 1, 'the Z', 'trimf', [- 2 * F1 * f1,0,2]); 
A addmf = (A, 'INPUT',. 1, 'the PS', 'trimf', [F1 * 0,1 * F1,2]);
% addmf A = (A, 'INPUT',. 1, 'the PM', ' trimf ', [0,2 f1,3 * F1 *]);
A = addmf (A,' INPUT ',. 1,' PB ',' SMF ', [F1,2 * F1 *. 1]); 

%输入2
f2=1;
a=addvar(a,'input','ec',[-2*f2,2*f2]);                   
 %添加 ec 的模糊语言变量
a=addmf(a,'input',2,'NB','zmf',[-2*f2,-1*f2]); 
%a=addmf(a,'input',2,'NM','trimf',[-3*f2,-2*f2,0]);
a=addmf(a,'input',2,'NS','trimf',[-2*f2,-1*f2,0*f2]);
a=addmf(a,'input',2,'Z','trimf',[-1*f2,0,1*f2]);
a=addmf(a,'input',2,'PS','trimf',[-1*f2,0,2*f2]);
%a=addmf(a,'input',2,'PM','trimf',[0,2*f2,3*f2]);
a=addmf(a,'input',2,'PB','smf',[1*f2,2*f2]); 
%输出
f3=1.5;
a=addvar(a,'output','u',[-2*f3,2*f3]);                 % addmf A = (A, 'Output' , 1, 'NM', 'A = addmf (A, 'Output',. 1, 'NB', 'ZMF', [- 2 * F3, F3 * -1]); 
   % Addition of fuzzy linguistic variables u


a=addmf(a,'output',1,'NS','trimf',[-2*f3,-1*f3,1*f3]);
a=addmf(a,'output',1,'Z','trimf',[-1*f3,0,1*f3]);
a=addmf(a,'output',1,'PS','trimf',[-1*f3,0,2*f3]);
%a=addmf(a,'output',1,'PM','trimf',[0,2*f3,3*f3]);
a=addmf(a,'output',1,'PB','smf',[1*f3,2*f3]);
(2)运行结果

 

The membership function e

 

ec membership function

2. Define the fuzzy set rules

(1) Code Display

%规则库
rulelist=[1 1 1 1 1;             %编辑模糊规则,后俩个数分别是规则权重和AND OR选项
               1 2 1 1 1;
               1 3 2 1 1;
               1 4 3 1 1;
               1 5 3 1 1;
             
               2 1 1 1 1;
               2 2 2 1 1;
               2 3 3 1 1;
               2 4 4 1 1;
               2 5 5 1 1;
             
               3 1 1 1 1
               3 2 1 1 1
               3 3 3 1 1
               3 4 3 1 1
               3 5 4 1 1
               4 1 4 1 1
               4 2 2 1 1
               4 3 4 1 1
               4 4 4 1 1
               4 5 5 1 1
               5 1 1 1 1
               5 2 3 1 1
               5 3 4 1 1
               5 4 4 1 1
               5 5 5 1 1;];
           
a=addrule(a,rulelist);                %添加模糊规则函数
showrule(a)                             %显示模糊规则函数
a1=setfis(a,'DefuzzMethod','centroid');                  %设置解模糊方法
writefis(a1,'fuzzf');                       %保存模糊系统
a2=readfis('fuzzf');   %从磁盘读出保存的模糊系统
disp('fuzzy Controller table:e=[-3,+3],ec=[-3,+3]');%显示矩阵和数组内容

%推理
Ulist=zeros(5,5);                                   %全零矩阵
for i=1:5
       for j=1:5
           e(i)=-3+i;
           ec(j)=-3+j;
           Ulist(i,j)=evalfis([e(i),ec(j)],a2);    %完成模糊推理计算
       end
   end
%   Ulist=ceil(Ulist)                               %朝正无穷方向取整
   Ulist                               %朝正无穷方向取整
   
%画出模糊系统
figure(1); plotfis(a2);  
figure(2);plotmf(a,'input',1);
figure(3);plotmf(a,'input',2);
figure(4);plotmf(a,'output',1);

(2)运行结果

输出u

模糊集经处理后的变成的集合

 

 

 

 

模糊集语句

3.分析与结论

(1)输入量和输出量的模糊化
将湿度e分为五个模糊集:负大(NB),负小(NS),零(Z),正小(PS),正大(PB),将温度分为五个模糊集:负大(NB),负小(NS),零(Z),正小(PS),正大(PB)。
u为设备运转时间,将其分为五个模糊集:负大(NB),负小(NS),零(Z),正小(PS),正大(PB)
(2)模糊规则的描述
根据日常的经验,设计模糊规则:“若e负大,且ec负大,,则u负大”…
上述规则采用“IF A THEN B”形式来描述:“if e=NB and ec=NB,then u=NB” …

(3)求模糊关系
模糊控制规则是一个多条语句,它可以表示为ec×e上的模糊子集,即模糊关系R:
R=(NBe×NBu)∪(NSe×NSu)∪(Ze×Zu)∪(PSe×PSu)∪(PBe×PBu)
其中规则内的模糊集运算取交集,规则间的模糊集运算取并集。

(4)模糊决策
模糊控制器的输出为误差向量和模糊关系的合成:
u=e ○ R
2.实验分析
本次实验为两输入(e、ec)、一输出(u)模型。首先构造模糊集:
对e:将偏差e划分为5个模糊集,负大(NB)、负小(NS)、零(Z)、 正小(PS)、 正大(PB),设定e的取值范围为[-2,2]。
对ec:将偏差ec划分为5个模糊集,负大(NB)、负小(NS)、零(Z)、 正小(PS)、 正大(PB),设定ec的取值范围为[-2,2]。
对u:将u划分为5个模糊集,负大(NB)、负小(NS)、零(Z)、 正小(PS)、 正大(PB),设定u的取值范围为[-3,3]。
对于建立模糊规则:规则库rulelist中的5列分别表示:前两列(两个输入e和ec)、第3列(输出u)、第4列(信赖度)、第5列(AND、OR选项,AND用1表示,OR用0表示)。由于两输入、一输出都各有5个模糊集,因此总的应该有25种模糊规则。

结论:

 

 

Guess you like

Origin blog.csdn.net/WWQ0726/article/details/102683444