問題呈述
在模糊控制這門課程中,學到了與模糊數學及模糊推理相關的內容,但是並不太清楚我們在選擇模糊規則時應該如何處理,是所有的規則都需要由人手工選擇,還是僅需要選擇其中的一部分就可以了。因此,在課程示例的基礎上做了如下的探究。
設計一個以E、EC作為輸入,U作為輸出的模糊推理系統,令E、EC、U的隸屬度函數為如下:
1 | 0.6 | 0.2 | 0 | 0 | 0 | 0 | 0 | 0 |
---|---|---|---|---|---|---|---|---|
0.2 | 0.6 | 1 | 0.6 | 0.2 | 0 | 0 | 0 | 0 |
0 | 0 | 0.2 | 0.6 | 1 | 0.6 | 0.2 | 0 | 0 |
0 | 0 | 0 | 0 | 0.2 | 0.6 | 1 | 0.6 | 0.2 |
0 | 0 | 0 | 0 | 0 | 0 | 0.2 | 0.6 | 1 |
分別給定“中心十字規則”以及“最強對角線規則”作為初始規則,觀察由此推導出的結果,以驗證初始模糊規則庫應該如何選擇。
結果
中心十字規則
其中,列索引代表E,行索引代表EC,中間的數據區域代表U。1代表負大(NB),2代表負中(NM),3代表零(Z),4代表正中(PB),5代表正大(PB)。
最強對角線
結果分析
從上面的結果可以分析得出:
- 當提供部分規則時,其它規則可由這些規則導出;
- 強對角線規則作為初始規則時,推導效果較好;
- 在強對角線中,左下角和右上角的隸屬度為零,這與人的主觀判斷相同,即“誤差正大,但是誤差速度為負大,即誤差減小(趨於零)的速度最大”,此時不應有主觀判斷,即維持原態即可。
Additional
tight_subplot.m
function ha = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
% tight_subplot creates "subplot" axes with adjustable gaps and margins
%
% ha = tight_subplot(Nh, Nw, gap, marg_h, marg_w)
%
% in: Nh number of axes in hight (vertical direction)
% Nw number of axes in width (horizontaldirection)
% gap gaps between the axes in normalized units (0...1)
% or [gap_h gap_w] for different gaps in height and width
% marg_h margins in height in normalized units (0...1)
% or [lower upper] for different lower and upper margins
% marg_w margins in width in normalized units (0...1)
% or [left right] for different left and right margins
%
% out: ha array of handles of the axes objects
% starting from upper left corner, going row-wise as in
% going row-wise as in
%
% Example: ha = tight_subplot(3,2,[.01 .03],[.1 .01],[.01 .01])
% for ii = 1:6; axes(ha(ii)); plot(randn(10,ii)); end
% set(ha(1:4),'XTickLabel',''); set(ha,'YTickLabel','')
% Pekka Kumpulainen 20.6.2010 @tut.fi
% Tampere University of Technology / Automation Science and Engineering
if nargin<3; gap = .02; end
if nargin<4 || isempty(marg_h); marg_h = .05; end
if nargin<5; marg_w = .05; end
if numel(gap)==1;
gap = [gap gap];
end
if numel(marg_w)==1;
marg_w = [marg_w marg_w];
end
if numel(marg_h)==1;
marg_h = [marg_h marg_h];
end
axh = (1-sum(marg_h)-(Nh-1)*gap(1))/Nh;
axw = (1-sum(marg_w)-(Nw-1)*gap(2))/Nw;
py = 1-marg_h(2)-axh;
ha = zeros(Nh*Nw,1);
ii = 0;
for ih = 1:Nh
px = marg_w(1);
for ix = 1:Nw
ii = ii+1;
ha(ii) = axes('Units','normalized', ...
'Position',[px py axw axh], ...
'XTickLabel','', ...
'YTickLabel','');
px = px+axw+gap(2);
end
py = py-axh-gap(1);
end
中心十字規則
clc;
E = [1,0.6,0,0,0,0,0,0,0;0.2,0.6,1,0.6,0.2,0,0,0,0;0,0,0.2,0.6,1,0.6,0.2,0,0;0,0,0,0,0.2,0.6,1,0.6,0.2;0,0,0,0,0,0,0.2,0.6,1];
EC = E;
U = E;
% ----------------------------------------------------------------------------------
% Calculate R
% Deduct relationship
% ----------------------------------------------------------------------------------
R = zeros(81,9);
for i = 1:5
A = E(i,:)';
B = EC(3,:);
C = U(i,:);
AB = min(repmat(A,1,9), repmat(B,9,1));
AB = reshape(AB, [81,1]);
RC = min(repmat(AB,1,9), repmat(C, 81,1));
R = max(R,RC);
end
for i = [1,2,4,5]
A = E(3,:)';
B = EC(i,:);
C = U(i,:);
AB = min(repmat(A,1,9), repmat(B,9,1));
AB = reshape(AB, [81,1]);
RC = min(repmat(AB,1,9), repmat(C, 81,1));
R = max(R,RC);
end
% ----------------------------------------------------------------------------------
% Calculate C
% Relationship induction
% ----------------------------------------------------------------------------------
C = zeros(9,5,5);
for i = 1:5
for j = 1:5
A = E(i,:)';
B = EC(j,:);
AB = min(repmat(A,1,9), repmat(B,9,1));
AB = reshape(AB, [81,1]);
C(:,i,j) = max(min(repmat(AB, 1, 9), R));
end
end
% ----------------------------------------------------------------------------------
% Plot
% ----------------------------------------------------------------------------------
figure(2);clf;
x = (1:9)/9;
ha = tight_subplot(5,5,[.0 .0],[.0 .0],[.0 .0]);
for i = 1:5
for j = 1:5
axes(ha(i*5-5+j));
h = plot(x, C(:,i,j));
ylim([0,1.2]);
xlim([min(x), max(x)]);
set(gca,'XTick',[])
set(gca,'YTick',[])
end
end
最強對角線規則
clc;
E = [1,0.6,0,0,0,0,0,0,0;0.2,0.6,1,0.6,0.2,0,0,0,0;0,0,0.2,0.6,1,0.6,0.2,0,0;0,0,0,0,0.2,0.6,1,0.6,0.2;0,0,0,0,0,0,0.2,0.6,1];
EC = E;
U = E;
% ----------------------------------------------------------------------------------
% Calculate R
% Deduct relationship
% ----------------------------------------------------------------------------------
R = zeros(81,9);
for i = 1:5
A = E(i,:)';
B = EC(i,:);
C = U(i,:);
AB = min(repmat(A,1,9), repmat(B,9,1));
AB = reshape(AB, [81,1]);
RC = min(repmat(AB,1,9), repmat(C, 81,1));
R = max(R,RC);
end
% ----------------------------------------------------------------------------------
% Calculate C
% Relationship induction
% ----------------------------------------------------------------------------------
C = zeros(9,5,5);
for i = 1:5
for j = 1:5
A = E(i,:)';
B = EC(j,:);
AB = min(repmat(A,1,9), repmat(B,9,1));
AB = reshape(AB, [81,1]);
C(:,i,j) = max(min(repmat(AB, 1, 9), R));
end
end
% ----------------------------------------------------------------------------------
% Plot
% ----------------------------------------------------------------------------------
figure(2);clf;
x = (1:9)/9;
ha = tight_subplot(5,5,[.0 .0],[.0 .0],[.0 .0]);
for i = 1:5
for j = 1:5
axes(ha(i*5-5+j));
h = plot(x, C(:,i,j));
ylim([0,1.2]);
xlim([min(x), max(x)]);
set(gca,'XTick',[])
set(gca,'YTick',[])
end
end
模糊合成的定義
設\(P\)是\(U\times V\) 上的模糊關系,\(Q\)是\(V\times W\)上的模糊關系,則\(R\)是\(U\times W\)上的模糊關系,它是\(P\circ Q\)的合成,其隸屬函數被定義為
若式中牌子\(\wedge\)代表“取小–\(\min\)”,\(\vee\)代表“取大–\(\max\)”,這種合成關系即為最大值\(\cdot\)最小值合成,合成關系\(R=P\circ Q\)。
示例:
則\(A\circ B=\begin{bmatrix}0.5 & 0.6\\ 0.3 & 0.3 \end{bmatrix}\), \(B\circ A=\begin{bmatrix}{0.1} & {0.2} & {0.2}\\ {0.3} & {0.3} & {0.3}\\ {0.4} & {0.5} & {0.5} \end{bmatrix}\)。
有定義為
模糊推導示例
已知一個雙輸入單輸出的模糊系統,其輸入量為\(x\)和\(y\),輸出量為\(z\),其輸入輸出的關系可用如下兩條模糊規則描述:
-
\(R_{1}\):如果\(x\)是\(A_{1}\) and \(y\)是\(B_{1}\),則\(z\)是\(C_{1}\)
-
\(R_{2}\):如果\(x\)是\(A_{2}\) and \(y\)是\(B_{2}\),則\(z\)是\(C_{2}\)
(感覺被惡心到了,不知道為什么這兒的array環境始終出不來)
現已知輸入\(x\)為\(A'\), \(y\)為\(B’\),試求輸出量。
將其按行展開得(把矩陣壓扁為一行向量)
同理:
總的蘊含關系為
計算輸入量的模糊集合