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)。
最强对角线
结果分析
从上面的结果可以分析得出:
- 当提供部分规则时,其它规则可由这些规则导出;
- 强对角线规则作为初始规则时,推导效果较好;
- 在强对角线中,左下角和右上角的隶属度为零,这与人的主观判断相同,即“误差正大,但是误差速度为负大,即误差减小(趋于零)的速度最大”,此时不应有主观判断,即维持原态即可。
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\)。
示例:
{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}\)。
有定义为
\]
模糊推导示例
已知一个双输入单输出的模糊系统,其输入量为\(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}\)
{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’\),试求输出量。
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}
\]
{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}
\]
将其按行展开得(把矩阵压扁为一行向量)
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]
\]
同理:
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]
\]
总的蕴含关系为
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]
\]
计算输入量的模糊集合
{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]
\]
{0.5} & {0.5} & {0.5} & {0.6} & 1 & {0.6} & {0.5} & {0.5} & {0.5}\end{array}}\right]
\]
{0.5} & {0.4} & {0.5}\end{array}}\right]
\]
\]
Fuzzy模糊推导(Matlab实现)的更多相关文章
- java操作elasticsearch实现前缀查询、wildcard、fuzzy模糊查询、ids查询
1.前缀查询(prefix) //prefix前缀查询 @Test public void test15() throws UnknownHostException { //1.指定es集群 clus ...
- 维纳滤波和编码曝光PSF去除运动模糊【matlab】
编码曝光知识 - ostartech - 博客园 https://www.cnblogs.com/wxl845235800/p/8276362.html %%%%%%%%%%%%%%%%%%%%%%% ...
- 使用MATLAB生成模糊控制的离线查询表
1.打开模糊控制工具箱,编辑输入输出变量的隶属度函数和模糊控制规则,如下图所示,导出为fuzzy_control.fis文件. 2.打开Simulink模块,建立下图所示的系统框图,两输入,一输出,处 ...
- es 基于match_phrase的模糊匹配原理及使用
[版权声明]:本文章由danvid发布于http://danvid.cnblogs.com/,如需转载或部分使用请注明出处 在业务中经常会遇到类似数据库的"like"的模糊匹配需求 ...
- .NET平台机器学习资源汇总,有你想要的么?
接触机器学习1年多了,由于只会用C#堆代码,所以只关注.NET平台的资源,一边积累,一边收集,一边学习,所以在本站第101篇博客到来之际,分享给大家.部分用过的 ,会有稍微详细点的说明,其他没用过的, ...
- 17 Great Machine Learning Libraries
17 Great Machine Learning Libraries 08 October 2013 After wonderful feedback on my previous post on ...
- Lucene学习总结之八:Lucene的查询语法,JavaCC及QueryParser
一.Lucene的查询语法 Lucene所支持的查询语法可见http://lucene.apache.org/java/3_0_1/queryparsersyntax.html (1) 语法关键字 + ...
- .NET平台机器学习
.NET平台机器学习资源汇总,有你想要的么? 接触机器学习1年多了,由于只会用C#堆代码,所以只关注.NET平台的资源,一边积累,一边收集,一边学习,所以在本站第101篇博客到来之际,分享给大家.部分 ...
- Lucene的查询语法,JavaCC及QueryParser(1)
http://www.cnblogs.com/forfuture1978/archive/2010/05/08/1730200.html 一.Lucene的查询语法 Lucene所支持的查询语法可见h ...
随机推荐
- Service Cloud 零基础(一)Case 浅谈
本片参考:https://resources.docs.salesforce.com/222/latest/en-us/sfdc/pdf/salesforce_case_implementation_ ...
- Android Studio 1.5运行问题
Error:Unable to start the daemon process: could not reserve enough space for object heap.Please assi ...
- CSS Grid 网格布局教程
一.概述 网格布局(Grid)是最强大的 CSS 布局方案. 它将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局.以前,只能通过复杂的 CSS 框架达到的效果,现在浏览器内置了. 上 ...
- 详解AJAX工作原理以及实例讲解(通俗易懂)
什么是 AJAX ? AJAX = 异步 JavaScript 和 XML. AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味 ...
- go-go协程
package main import ( "fmt" "runtime" "time" ) func test() { defer fmt ...
- python使用input().split()接收多个用户输入
1.input() 接收多个用户输入需要与split()结合使用 host, port, username, passwd, dbname = input("请输入服务器地址,端口号,用户名 ...
- liunux中的标准输出。以及常用的 2>dev/null 命令的含义
了解Linux怎样处理输入和输出是非常重要的.一旦我们了解其原理以后,我们就可以正确熟练地使用脚本把内容输出到正确的位置.同样我们也可以更好地理解输入重定向和输出重定向. 首先我们来了解一下linux ...
- 小白终于弄懂了:c#从async/await到Task再到Thread
1. 为什么会有/怎么解决: async/await的无限嵌套 public async Task<int> myFuncAsync1() { //some code int num = ...
- The usage of Markdown---标题
更新时间:2019.09.14 目录: 1. 序言 2. 标题 2.1 类Atx形式 2.2 类Setext形式 3. 总结 1. 序言 Markdown是一种纯文本的标记语言,只要熟悉M ...
- The value for the useBean class attribute is invalied
JSP: The value for the useBean class attribute XXX is ...