# 使用AForge.NET进行模糊运算

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

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

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

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

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

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

4.逻辑非

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

# 子句判断（Clause）

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

TrapezoidalFunction function1 = new TrapezoidalFunction( 10, 15, TrapezoidalFunction.EdgeType.Right);
FuzzySet fsCold = new FuzzySet( " Cold ", function1);
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25);
FuzzySet fsCool = new FuzzySet( " Cool ", function2);
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35);
FuzzySet fsWarm = new FuzzySet( " Warm ", function3);
TrapezoidalFunction function4 = new TrapezoidalFunction( 30, 35, TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHot = new FuzzySet( " Hot ", function4);

Clause fuzzyClause1 = new Clause(lvTemperature, fsHot);
lvTemperature.NumericInput = 35;
float result1 = fuzzyClause1.Evaluate();
Console.WriteLine( " temperature is hot ====> {0} ", result1.ToString());

Clause fuzzyClause2 = new Clause(lvTemperature, fsCold);
lvTemperature.NumericInput = 35;
float result2 = fuzzyClause2.Evaluate();
Console.WriteLine( " temperature is cold ====> {0} ", result2.ToString());

# 启动强度（Firing Strength）

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

TrapezoidalFunction function1 = new TrapezoidalFunction(
10, 15, TrapezoidalFunction.EdgeType.Right);
FuzzySet fsCold = new FuzzySet( " Cold ", function1);
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25);
FuzzySet fsCool = new FuzzySet( " Cool ", function2);
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35);
FuzzySet fsWarm = new FuzzySet( " Warm ", function3);
TrapezoidalFunction function4 = new TrapezoidalFunction(
30, 35, TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHot = new FuzzySet( " Hot ", function4);

LinguisticVariable lvSteel = new LinguisticVariable( " Steel ", 0, 80);

LinguisticVariable lvStove = new LinguisticVariable( " Stove ", 0, 80);

TrapezoidalFunction function5 = new TrapezoidalFunction(
20, 40, TrapezoidalFunction.EdgeType.Right);
FuzzySet fsLow = new FuzzySet( " Low ", function5);
TrapezoidalFunction function6 = new TrapezoidalFunction( 20, 40, 60, 80);
FuzzySet fsMedium = new FuzzySet( " Medium ", function6);
TrapezoidalFunction function7 = new TrapezoidalFunction(
60, 80, TrapezoidalFunction.EdgeType.Left);
FuzzySet fsHigh = new FuzzySet( " High ", function7);

LinguisticVariable lvPressure = new LinguisticVariable( " Pressure ", 0, 100);

Database db = new Database();

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 = 12;
lvStove.NumericInput = 32;

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.GetRPNExssion());
Console.WriteLine( " firing strength of R1 ===> {0} ",result3);
float result4 = r2.EvaluateFiringStrength();
Console.WriteLine(r2.GetRPNExssion());
Console.WriteLine( " firing strength of R2 ===> {0} ", result4);

# 去模糊化（defuzzification ）

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

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

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

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

http://www.ctdisk.com/file/4496068