原文:子句判断、启动强度和去模糊化--AForge.NET框架的使用(三)

使用AForge.NET进行模糊运算

上一篇说来一些模糊运算的数学问题,用AForge.NET做相关运算就很简单了。

1.联集运算中的标准联集

数学:s (p,q) = max (p,q)

程序:

public class MaximumCoNorm : ICoNorm 
{
public float Evaluate( float membershipA, float membershipB )
{
return Math.Max( membershipA, membershipB );
}
}

2.交集运算中的标准交集

数学:t (p,q) = min (p,q)

程序:

public class MinimumNorm : INorm 
{
public float Evaluate( float membershipA, float membershipB )
{
return Math.Min( membershipA, membershipB );
}
}

3.交集运算中的代数乘积:

数学:t (p,q) = pq

程序:

public class ProductNorm : INorm 
{
public float Evaluate( float membershipA, float membershipB )
{
return membershipA * membershipB;
}
}

4.逻辑非

数学:t(p)=1-p

程序:

public class NotOperator : IUnaryOperator 
{
public float Evaluate( float membership )
{
return ( - membership );
}
}

我比较好奇AForge.NET没有实现彻底联集和彻底交集,只有自己补上了。

子句判断(Clause)

这个严格来说只是一个辅助用的类,它可以判断特定的子句是否可以构建。

依旧用温度举例,语意变量temperature的hot隶属度0.4,warm隶属度0.6。那么temperature is hot和temperature is warm都可以构建。

LinguisticVariable lvTemperature = new LinguisticVariable("Temperature", , );

TrapezoidalFunction function1 = new TrapezoidalFunction(, , TrapezoidalFunction.EdgeType.Right); 
FuzzySet fsCold = new FuzzySet("Cold", function1);
TrapezoidalFunction function2 = new TrapezoidalFunction(, , , );
FuzzySet fsCool = new FuzzySet("Cool", function2);
TrapezoidalFunction function3 = new TrapezoidalFunction(, , , );
FuzzySet fsWarm = new FuzzySet("Warm", function3);
TrapezoidalFunction function4 = new TrapezoidalFunction(, , TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHot = new FuzzySet("Hot", function4); lvTemperature.AddLabel(fsCold);
lvTemperature.AddLabel(fsCool);
lvTemperature.AddLabel(fsWarm);
lvTemperature.AddLabel(fsHot); Clause fuzzyClause1 = new Clause(lvTemperature, fsHot);
lvTemperature.NumericInput = ;
float result1 = fuzzyClause1.Evaluate();
Console.WriteLine("temperature is hot ====> {0}", result1.ToString()); Clause fuzzyClause2 = new Clause(lvTemperature, fsCold);
lvTemperature.NumericInput = ;
float result2 = fuzzyClause2.Evaluate();
Console.WriteLine("temperature is cold ====> {0}", result2.ToString());  

效果:

很明显在35度时,temperature is hot 可以构建,temperature is cold则不行。

这个类在自己写东西的时候一般用不上,但是如果要编写泛用性的或者拿给别人用的系统,那么最后每个子句都检查一下。

启动强度(Firing Strength)

启动强度(Firing Strength)是衡量规则和输入的匹配度的量。

举个例子,语意变量Steel为Cold 的隶属度是0.6,Stove为Hot的隶属度为0.4。

那么规则R1:IF Steel is Cold and Stove is Hot then Pressure is Low 的Firing Strength=min(x,y)=0.4

规则R2:IF Steel is Cold and not (Stove is Warm or Stove is Hot) then Pressure is Medium"的Firing Strength=0.4

(以上算法只是这里采用的而已,不同的运算规则会有不同结果,比如0.24之类的)

 TrapezoidalFunction function1 = new TrapezoidalFunction( 
, , TrapezoidalFunction.EdgeType.Right);
FuzzySet fsCold = new FuzzySet("Cold", function1);
TrapezoidalFunction function2 = new TrapezoidalFunction(, , , );
FuzzySet fsCool = new FuzzySet("Cool", function2);
TrapezoidalFunction function3 = new TrapezoidalFunction(, , , );
FuzzySet fsWarm = new FuzzySet("Warm", function3);
TrapezoidalFunction function4 = new TrapezoidalFunction(
, , TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHot = new FuzzySet("Hot", function4); LinguisticVariable lvSteel = new LinguisticVariable("Steel", , ); lvSteel.AddLabel(fsCold);
lvSteel.AddLabel(fsCool);
lvSteel.AddLabel(fsWarm);
lvSteel.AddLabel(fsHot); LinguisticVariable lvStove = new LinguisticVariable("Stove", , ); lvStove.AddLabel(fsCold);
lvStove.AddLabel(fsCool);
lvStove.AddLabel(fsWarm);
lvStove.AddLabel(fsHot); TrapezoidalFunction function5 = new TrapezoidalFunction(
, , TrapezoidalFunction.EdgeType.Right);
FuzzySet fsLow = new FuzzySet("Low", function5);
TrapezoidalFunction function6 = new TrapezoidalFunction(, , , );
FuzzySet fsMedium = new FuzzySet("Medium", function6);
TrapezoidalFunction function7 = new TrapezoidalFunction(
, , TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHigh = new FuzzySet("High", function7); LinguisticVariable lvPressure = new LinguisticVariable("Pressure", , ); lvPressure.AddLabel(fsLow);
lvPressure.AddLabel(fsMedium);
lvPressure.AddLabel(fsHigh); Database db = new Database();
db.AddVariable(lvSteel);
db.AddVariable(lvStove);
db.AddVariable(lvPressure); Rule r1 = new Rule(db, "R1", "IF Steel is Cold and Stove is Hot then Pressure is Low");
Rule r2 = new Rule(db, "R2", "IF Steel is Cold and not (Stove is Warm or Stove is Hot) then Pressure is Medium");
Rule r3 = new Rule(db, "R3", "IF Steel is Cold and Stove is Warm or Stove is Hot then Pressure is High"); lvSteel.NumericInput = ;
lvStove.NumericInput = ; float result1 = lvSteel.GetLabelMembership("Cold", lvSteel.NumericInput);
Console.WriteLine("membership of Cold ===> {0}", result1);
float result2 = lvStove.GetLabelMembership("Hot", lvStove.NumericInput);
Console.WriteLine("membership of Hot ===> {0}", result2);
float result3 = r1.EvaluateFiringStrength();
Console.WriteLine(r1.GetRPNExpression());
Console.WriteLine("firing strength of R1 ===> {0}",result3);
float result4 = r2.EvaluateFiringStrength();
Console.WriteLine(r2.GetRPNExpression());
Console.WriteLine("firing strength of R2 ===> {0}", result4);

去模糊化(defuzzification )

这可以说是模糊系统的最后一步,将经过模糊推理之后产生的结论,转换为一明确数值,称之为“去模糊化”。

至于这一步骤的必要性,一般有两个原因:

1.不同的模糊规则产生的结果不一致,有的是集合,有的是具体的数据,需要一个统一。

2.模糊系统一般不单独使用,它和其他系统(如神经网络)等搭配时,输出值必须是数值。

去模糊化常用方法有最大隶属度法、取中位数法和重心法。

AForge.Net的实现是CentroidDefuzzifier,即重心法。

当论域为连续时:

当论域为离散时:

InferenceSystem IS = new InferenceSystem( fuzzyDB, new CentroidDefuzzifier(  ) );

至此大部分知识准备就完成了,下一篇会给出一个完整一些的示例。

最后找到一个有关模糊集合的PPT,大家可以参考一下:
http://www.ctdisk.com/file/4496068

子句判断、启动强度和去模糊化--AForge.NET框架的使用(三)的更多相关文章

  1. Js判断密码强度并显示提示信息

    用javascipt实现的Ajax判断密码强弱的功能,大多数有用户注册功能的网站,都会有这么一个功能,作为WEB程序员,应该会写这种小模块哦,不懂的就看下这个例子,觉得挺简单,当初帮助了不少人学会了密 ...

  2. 【课上OJ】判断密码强度

    一个判断密码强度问题: 假设允许采用以下四类字符作为密码: (1)大写英文字母,(2)小写英文字母,(3)数字0-9,(4)特殊符号 @ - _ # ~ 对密码强度做以下规定: Best: 长度> ...

  3. js判断密码强度是否符合

    /** 判断密码强度是否符合 */ function check_passwd_intensity(password) { value = $.trim(password); if( value.le ...

  4. JavaScript判断密码强度

    以下是代码: <html> <head> <title>JS判断密码强度</title> <script language=javascript& ...

  5. 模糊系统架构和简单实现--AForge.NET框架的使用(四)

    原文:模糊系统架构和简单实现--AForge.NET框架的使用(四) 先说一下,为什么题目是简单实现,因为我实在没有弄出好的例子. 我原来用AForge.net做的项目中的模糊系统融入了神经网络和向量 ...

  6. 模糊语意变数、规则和模糊运算--AForge.NET框架的使用(二)

    原文:模糊语意变数.规则和模糊运算--AForge.NET框架的使用(二) 语意变数(Linguistic Variable) 语意变数存储了数个语意量(标签),每个语意量包含一个识别名和模糊集合.在 ...

  7. 模糊集合和隶属度函数--AForge.NET框架的使用(一)

    原文:模糊集合和隶属度函数--AForge.NET框架的使用(一) 什么是AForge.NET? AForge.NET是一个为开发人员和研究人员开发的框架,它可以用于计算机视觉,遗传算法,图像处理,神 ...

  8. 基于AForge.Net框架的扑克牌识别

    原文:基于AForge.Net框架的扑克牌识别 © 版权所有 野比 2012 原文地址:点击查看 作者:Nazmi Altun Nazmi Altun著,野比 译  下载源代码 - 148.61 KB ...

  9. 进化计算简介和遗传算法的实现--AForge.NET框架的使用(六)

    原文:进化计算简介和遗传算法的实现--AForge.NET框架的使用(六) 开学了,各种忙起来了… 上一篇介绍了AForge.NET在人工神经网络上的一点点使用,但是老觉不过瘾.matlab用着实在不 ...

随机推荐

  1. python用parammiko模块实现linux的远程操作

    parammiko  可以实现远程的带密码登录,解决ssh远程登陆需要交互的问题 (当然很多其他的,如tcl也可以).但这个用python做比较简单 1.parammiko 的安装 1.1.依赖模块 ...

  2. UVALive 6198 A Terribly Grimm Problem

    题目大意是 给出L,H      10^10范围 为[L, H]这个连续的整数区间寻找一个序列. 序列的长度要跟[L, H]一样 然后序列中的数都是素数,并且互不相同 并且序列中第i个数 要求是L + ...

  3. Duplicate headers received from server

    This ones a little old but was high in the google ranking so I thought I would throw in the answer I ...

  4. Facebook的手游出海之道

    对于不同的游戏公司,面临的同一个问题就是怎样让海外玩家能够一眼在App中发现你,成为你的新用户:不仅如此,怎样留住这些用户,让他们成为你游戏的忠实玩家也是让全部游戏开发商困扰的一个问题. w=580& ...

  5. Android(java)学习笔记259:JNI之NDK开发步骤

    1. NDK开发步骤(回忆一下HelloWorld案例): (1)创建工程 (2)定义native方法 (3)创建jni文件夹 (4)创建c源文件放到jni文件夹 (5)拷贝jni.h头文件到jni目 ...

  6. 使用exp&imp工具进行数据库备份及恢复

    使用exp&imp工具进行数据库备份及恢复1.exp/imp使用方法介绍exp/imp为一种数据库备份恢复工具,也可以作为不同数据库之间传递数据的工具,两个数据库所在的操作系统可以不同.exp ...

  7. MM32看门狗学习(兼容STM32)

    MM32看门狗学习(兼容STM32) IWDG独立看门狗 思维导图 IWDG框图与理解 1.独立看门狗分为两个部分,配置寄存器在1.8V供电区,计数器的核心部分在VDD供电区(即使停机/待机模式计数器 ...

  8. html图像入门

    在HTML中,图像由<img>标签定义. <img>是空标签,意思是说,它只包含属性,并且没有闭合标签. 要在页面上显示图像,需要使用源属性src, src指的是"s ...

  9. mySQL优化 my.ini 配置说明

    [mysqld] port = 3306 serverid = 1 socket = /tmp/mysql.sock skip-name-resolve #禁止MySQL对外部连接进行DNS解析,使用 ...

  10. PHP Socket编程起步

    让我们以一个简单的例子开始---一个接收输入字符串,处理并返回这个字符串到客户端的TCP服务.下面是相应的代码: PHP 代码: ) or die("Could not read input ...