如何利用matlab将模糊逻辑转化为查询表

如何利用matlab将模糊逻辑转化为查询表,第1张

第一步:利用matlab模糊控制工具箱设计模糊控制器。

1、在matlab命令窗口中输入 fuzzy ,产生如下窗口。

2、确定模糊控制器结构,即根据具体的系统确定输入、输出量。

这里我们可以选取标准的二维控制结构,即输入为误差e和误差变化ec,输出为控制量u。输入变量的添加通过 Edit ->Add Variable ->Input 实现。

3、语言值及隶属函数的确定。

首先我们要确定描述输入输出变量语言值的模糊子集,如{NB,NM,NS,ZE,PS,PM,PB},并设置输入输出变量的论域,例如我们设置误差E、误差变化EC的论域为[-6 6],控制量U的论域为[-10 10];然后为模糊语言变量选取相应的隶属度函数。通过 Edit ->Membership Functions 打开隶属度函数编辑器,然后分别对输入输出变量定义论域范围,添加隶属函数,以E为例,设置论域范围为[-6 6],添加隶属函数的个数为7。(注:隶属度函数编辑器初始时已为每个变量定义了3个隶属函数,再通过 Edit ->Add MFs 添加隶属函数时,个数选择4即可)

4、模糊控制规则的制定。

对于我们这个二维控制结构以及相应的输入模糊集,我们可以制定49条模糊控制规则。

5、解模糊。

模糊控制器的输出量是一个模糊集合,通过解模糊化方法判决出一个确切的精确量,解模糊化方法很多,我们这里选取重心法。

6、保存建立的模糊控制器。

File ->Export ->To File,文件名为 fuzzy_control。

第二步:建立Simulink模型。

1、在matlab命令窗口中输入simulink,产生如下窗口。

2、新建模糊控制器模型,样式如下。

3、在matlab命令窗口下输入 fuzzy = readfis('fuzzy_control') ,将之前建立的模糊控制器加载到工作空间,并将Fuzzy Logic Contrtoller的参数设置为fuzzy。

4、保存该模型,命名为 fuzzy_model

第三步:系统测试界面的设置。

1、通过 Tools ->System Test ->Launch System Test 进入系统测试界面。

2、添加测试模型。

鼠标选中Main Test ,菜单栏 Insert ->Test Element ->Simulink ,选择第二步中建立的模型 fuzzy_model 。

3、变量定义。

在Test Vectors 项里定义两个测试向量,变量名分别为 input1、input2,input1 = [-6:1:6], input2 = [-6:1:6];在Test Variables 里定义测试变量,变量名为output。

4、变量映射。

把测试向量input1、input2分别映射到模糊控制器的输入口 in1、in2,做为输入测试信号。把测试变量 output 映射到模糊控制器输出口out1。设置后的界面如下:

输入测试向量到模糊模型输入口映射:

5、测试数据保存。

在测试界面点Save Results项,设置如下:

6、运行测试,注意在Main Test(169 Iterations)(169次迭代,运算代价),等待测试结束。

第四步:模糊控制查询表的生成

1、系统测试结果保存在 stresults.ResultsDataSet.output 中,为169*1 cell的单元数组。(注:单元cell为 [n*1 double] 结构,表示系统被测试了n次)。

2、在matlab命令窗口下输入 test_data = stresults.ResultsDataSet.output ,将测试结果另存在变量 test_data 中。

3、测试结果格式转换。

由于所建的二维查询表为13行13列,所需的数据应该为13*13 double数组,但因为test_data为 169*1 cell 的单元数组,无法直接作为表格数据输入,因此需先进行格式转换。

在matlab命令窗口下输入 table_data = Cell2Array( test_data , 1 , 13 , 13 ) ,调用Cell2Array函数,取每个单元数组中的第一行元素,即第一次测试数据,返回结果保存在 table_data 中。

源码如下:

4、新建二维查询表模型,样式如下:

5、点开二维查询表进行如下设置:

6、点 Edit 按钮,即可查看所生成的表格。

1、首先在电脑上点击打开Matlab软件,如下图所示。

2、然后在页面中新建一个脚本文件,在新建脚本文件中输入下图所示程序,利用fplot函数画带参数的函数图像。

3、点击左上角的“保存”。

4、接着点击编辑器菜单中的“运行”菜单。

5、最后在d出的figure页面中,就能看到所画出的图像了。

答案是不可以,隶属度虽然也在[0,1]内,但和概率不是一码事。

一个很好的 reddit blog 解释如下:

Fuzzy logic and probability address different forms of uncertainty. While both fuzzy logic and probability theory can represent degrees of certain kinds of subjective belief, fuzzy set theory uses the concept of fuzzy set membership, i.e., how much a variable is in a set (there is not necessarily any uncertainty about this degree), and probability theory uses the concept of subjective probability , i.e., how probable is it that a variable is in a set (it either entirely is or entirely is not in the set in reality, but there is uncertainty around whether it is or is not). The technical consequence of this distinction is that fuzzy set theory relaxes the axioms of classical probability, which are themselves derived from adding uncertainty, but not degree, to the crisp true/false distinctions of classical Aristotelian logic.

也有人将probability(包括 Bayesian 和 frequentist)和fuzzy进行了比较:

From the readings above, I conclude that Fuzzy logic and probability (in general) are different ways to reason about different kinds of uncertainty, but Fuzzy and Bayesian logic share similar concepts, such as degree of belief/truthness. Bayesian probability seems more complete and consistent, but it seems that this is a matter of dispute.

On a practical note, if I have data, any kind of data, I will go with (Bayesian) probability. If I have vague or uncertain human procedures, I will go with Fuzzy logic. For example, if you have a process control problem where you have the knowledge of an operator who controls it manually but no system model (which would be highly nonlinear and multivariate), how would you solve this using Bayesian inference? With Fuzzy control it's really easy, and that is actually what the company I work for does.

以上内容简而言之,Fuzzy理论,概率论是从不同角度刻画不确定性的两种方法,数据多的情况下go with Bayesian probability,若涉及到人类的模糊性的时候go with Fuzzy logic。目前我了解的刻画不确定性的数学工具有三种:


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11335668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存