Fuzzy模糊推導(Matlab實現)


問題呈述

在模糊控制這門課程中,學到了與模糊數學及模糊推理相關的內容,但是並不太清楚我們在選擇模糊規則時應該如何處理,是所有的規則都需要由人手工選擇,還是僅需要選擇其中的一部分就可以了。因此,在課程示例的基礎上做了如下的探究。

設計一個以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)。

最強對角線

結果分析

從上面的結果可以分析得出:

  1. 當提供部分規則時,其它規則可由這些規則導出;
  2. 強對角線規則作為初始規則時,推導效果較好;
  3. 在強對角線中,左下角和右上角的隸屬度為零,這與人的主觀判斷相同,即“誤差正大,但是誤差速度為負大,即誤差減小(趨於零)的速度最大”,此時不應有主觀判斷,即維持原態即可。

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\)的合成,其隸屬函數被定義為

\[\mu_{R}\left(u,w\right)\Leftrightarrow\mu_{P,Q}\left(u,w\right)=\vee_{v\in V}\left\{ \mu_{P}\left(u,v\right)\wedge\mu_{Q}\left(v,w\right)\right\} \]

若式中牌子\(\wedge\)代表“取小–\(\min\)”,\(\vee\)代表“取大–\(\max\)”,這種合成關系即為最大值\(\cdot\)最小值合成,合成關系\(R=P\circ Q\)

示例:

\[A=\begin{bmatrix}{0.4} & {0.5} & {0.6}\\ {0.1} & {0.2} & {0.3} \end{bmatrix},B=\begin{bmatrix}0.1 & 0.2\\ 0.3 & 0.4\\ 0.5 & 0.6 \end{bmatrix}. \]

\(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}\)

有定義為

\[A\times B = A^\mathrm{T}\circ B. \]

模糊推導示例

已知一個雙輸入單輸出的模糊系統,其輸入量為\(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}\)

\[\begin{array}{ccc} {A_{1}}=\frac{1}{{a_{1}}}+\frac{{0.5}}{{a_{2}}}+\frac{0}{{a_{3}}} & {B_{1}}=\frac{1}{{b_{1}}}+\frac{{0.6}}{{b_{2}}}+\frac{{0.2}}{{b_{3}}} & {C_{1}}=\frac{1}{{c_{1}}}+\frac{{0.4}}{{c_{2}}}+\frac{0}{{c_{3}}}\\ {A_{2}}=\frac{0}{{a_{1}}}+\frac{{0.5}}{{a_{2}}}+\frac{1}{{a_{3}}} & {B_{2}}=\frac{{0.2}}{{b_{1}}}+\frac{{0.6}}{{b_{2}}}+\frac{1}{{b_{3}}} & {C_{2}}=\frac{0}{{c_{1}}}+\frac{{0.4}}{{c_{2}}}+\frac{1}{{c_{3}}} \end{array} \]


(感覺被惡心到了,不知道為什么這兒的array環境始終出不來)

現已知輸入\(x\)\(A'\), \(y\)\(B’\),試求輸出量。

\[\begin{array}{cc} A'=\frac{{0.5}}{{a_{1}}}+\frac{1}{{a_{2}}}+\frac{{0.5}}{{a_{3}}} & B'=\frac{{0.6}}{{b_{1}}}+\frac{1}{{b_{2}}}+\frac{{0.6}}{{b_{3}}}\\ \end{array} \]


\[\begin{aligned} {A_{1}}\times{B_{1}} & =A_{1}^{T}\circ{B_{1}}={\left[{\begin{array}{ccc} 1 & {0.5} & 0\end{array}}\right]^{T}}\left[{\begin{array}{ccc} 1 & {0.6} & {0.2}\end{array}}\right]\\ & =\left[{\begin{array}{ccc} 1 & {0.6} & {0.2}\\ {0.5} & {0.5} & {0.2}\\ 0 & 0 & 0 \end{array}}\right] \end{aligned} \]

將其按行展開得(把矩陣壓扁為一行向量)

\[{R_{1}}=\bar{R}_{{A_{1}}\times{B_{1}}}^{T}\wedge{C_{1}}=\left[{\begin{array}{c} 1\\ {0.6}\\ {0.2}\\ {0.5}\\ {0.5}\\ {0.2}\\ 0\\ 0\\ 0 \end{array}}\right]\wedge\left[{\begin{array}{ccc} 1 & {0.4} & 0\end{array}}\right]=\left[{\begin{array}{ccc} 1 & {0.4} & 0\\ 1 & {0.4} & 0\\ {0.2} & {0.2} & 0\\ {0.5} & {0.4} & 0\\ {0.5} & {0.4} & 0\\ {0.2} & {0.2} & 0\\ 0 & 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0 \end{array}}\right] \]

同理:

\[{R_{2}}=\bar{R}_{{A_{2}}\times{B_{2}}}^{T}\wedge{C_{2}}=\left[{\begin{array}{ccc} 0 & 0 & 0\\ 0 & 0 & 0\\ 0 & 0 & 0\\ 0 & {0.2} & {0.2}\\ 0 & {0.4} & {0.5}\\ 0 & {0.4} & {0.5}\\ 0 & {0.2} & {0.2}\\ 0 & {0.4} & {0.6}\\ 0 & {0.4} & 1 \end{array}}\right] \]

總的蘊含關系為

\[R={R_{1}}\cup{R_{2}}=\left[{\begin{array}{ccc} 1 & {0.4} & 0\\ {0.6} & {0.4} & 0\\ {0.2} & {0.2} & 0\\ {0.5} & {0.4} & {0.2}\\ {0.5} & {0.4} & {0.5}\\ {0.2} & {0.4} & {0.5}\\ 0 & {0.2} & {0.2}\\ 0 & {0.4} & {0.6}\\ 0 & {0.4} & 1 \end{array}}\right] \]

計算輸入量的模糊集合

\[A'\text{ and }B'=A'\times B'=\left[{\begin{array}{c} {0.5}\\ 1\\ {0.5} \end{array}}\right]\wedge\left[{\begin{array}{ccc} {0.6} & 1 & {0.6}\end{array}}\right]=\left[{\begin{array}{ccc} {0.5} & {0.5} & {0.5}\\ {0.6} & 1 & {0.6}\\ {0.5} & {0.5} & {0.5} \end{array}}\right] \]

\[\bar{R}_{A'\times B'}^{T}=\left[{\begin{array}{ccccccccc} {0.5} & {0.5} & {0.5} & {0.6} & 1 & {0.6} & {0.5} & {0.5} & {0.5}\end{array}}\right] \]

\[C'=\bar{R}_{A'\times B'}\circ R=\left[{\begin{array}{ccc} {0.5} & {0.4} & {0.5}\end{array}}\right] \]

\[C'=\frac{{0.5}}{{c_{1}}}+\frac{{0.4}}{{c_{2}}}+\frac{{0.5}}{{c_{3}}} \]


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM