C# Class Accord.Fuzzy.Rule

This class represents a Fuzzy Rule, a linguistic expression representing some behavioral aspect of a Fuzzy Inference System.

A Fuzzy Rule is a fuzzy linguistic instruction that can be executed by a fuzzy system. The format of the Fuzzy Rule is:

IF antecedent THEN consequent

The antecedent is composed by a set of fuzzy clauses (see Clause) connected by fuzzy operations, like AND or OR. The operator NOT can be used to negate expressions:

...Clause1 AND (Clause2 OR Clause3) AND NOT Clause4 ...

Fuzzy clauses are written in form Variable IS Value. The NOT operator can be used to negate linguistic values as well:
...Variable1 IS Value1 AND Variable2 IS NOT Value2 ...

The consequent is a single of fuzzy clauses (Clause). To perform the linguistic computing, the Rule evaluates the clauses and then applies the fuzzy operators. Once this is done a value representing the confidence in the antecedent being true is obtained, and this is called firing strength of the Rule.

The firing strength is used to discover with how much confidence the consequent of a rule is true.

Sample usage:

// create the linguistic labels (fuzzy sets) that compose the temperature 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 ); // create a linguistic variable to represent steel temperature LinguisticVariable lvSteel = new LinguisticVariable( "Steel", 0, 80 ); // adding labels to the variable lvSteel.AddLabel( fsCold ); lvSteel.AddLabel( fsCool ); lvSteel.AddLabel( fsWarm ); lvSteel.AddLabel( fsHot ); // create a linguistic variable to represent stove temperature LinguisticVariable lvStove = new LinguisticVariable( "Stove", 0, 80 ); // adding labels to the variable lvStove.AddLabel( fsCold ); lvStove.AddLabel( fsCool ); lvStove.AddLabel( fsWarm ); lvStove.AddLabel( fsHot ); // create the linguistic labels (fuzzy sets) that compose the pressure 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 ); // create a linguistic variable to represent pressure LinguisticVariable lvPressure = new LinguisticVariable( "Pressure", 0, 100 ); // adding labels to the variable lvPressure.AddLabel( fsLow ); lvPressure.AddLabel( fsMedium ); lvPressure.AddLabel( fsHigh ); // create a linguistic variable database Database db = new Database( ); db.AddVariable( lvSteel ); db.AddVariable( lvStove ); db.AddVariable( lvPressure ); // sample rules just to test the expression parsing Rule r1 = new Rule( db, "Test1", "IF Steel is not Cold and Stove is Hot then Pressure is Low" ); Rule r2 = new Rule( db, "Test2", "IF Steel is Cold and not (Stove is Warm or Stove is Hot) then Pressure is Medium" ); Rule r3 = new Rule( db, "Test3", "IF Steel is Cold and Stove is Warm or Stove is Hot then Pressure is High" ); // testing the firing strength lvSteel.NumericInput = 12; lvStove.NumericInput = 35; float result = r1.EvaluateFiringStrength( ); Console.WriteLine( result.ToString( ) );
Exibir arquivo Open project: accord-net/framework Class Usage Examples

Public Methods

Method Description
EvaluateFiringStrength ( ) : float

Evaluates the firing strength of the Rule, the degree of confidence that the consequent of this Rule must be executed.

GetRPNExpression ( ) : string

Converts the RPN fuzzy expression into a string representation.

Rule ( Database fuzzyDatabase, string name, string rule ) : System

Initializes a new instance of the Rule class using as CoNorm the MaximumCoNorm and as Norm the MinimumNorm.

Rule ( Database fuzzyDatabase, string name, string rule, INorm normOperator, ICoNorm coNormOperator ) : System

Initializes a new instance of the Rule class.

Private Methods

Method Description
GetRuleTokens ( string rule ) : string[]

Performs a preprocessing on the rule, placing unary operators in proper position and breaking the string space separated tokens.

ParseRule ( ) : void

Converts the Fuzzy Rule to RPN (Reverse Polish Notation). For debug proposes, the string representation of the RPN expression can be acessed by calling GetRPNExpression method.

Priority ( string Operator ) : int

Defines the priority of the fuzzy operators.

Method Details

EvaluateFiringStrength() public method

Evaluates the firing strength of the Rule, the degree of confidence that the consequent of this Rule must be executed.
public EvaluateFiringStrength ( ) : float
return float

GetRPNExpression() public method

Converts the RPN fuzzy expression into a string representation.
public GetRPNExpression ( ) : string
return string

Rule() public method

Initializes a new instance of the Rule class using as CoNorm the MaximumCoNorm and as Norm the MinimumNorm.
public Rule ( Database fuzzyDatabase, string name, string rule ) : System
fuzzyDatabase Database A fuzzy containig the linguistic variables /// (see ) that will be used in the .
name string Name of this .
rule string A string representing the . It must be a "IF..THEN" /// statement. For a more detailed description see class.
return System

Rule() public method

Initializes a new instance of the Rule class.
public Rule ( Database fuzzyDatabase, string name, string rule, INorm normOperator, ICoNorm coNormOperator ) : System
fuzzyDatabase Database A fuzzy containig the linguistic variables /// (see ) that will be used in the Rule.
name string Name of this .
rule string A string representing the . It must be a "IF..THEN" statement. /// For a more detailed description see class.
normOperator INorm A class that implements a interface to /// evaluate the AND operations of the Rule.
coNormOperator ICoNorm A class that implements a interface /// to evaluate the OR operations of the Rule.
return System