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( ) );
コード例 #1
0
ファイル: Rulebase.cs プロジェクト: accord-net/framework
 /// <summary>
 /// Adds a fuzzy rule to the database. 
 /// </summary>
 /// 
 /// <param name="rule">A fuzzy <see cref="Rule"/> to add to the database.</param>
 /// 
 /// <exception cref="NullReferenceException">The fuzzy rule was not initialized.</exception>
 /// <exception cref="ArgumentException">The fuzzy rule name already exists in the rulebase.</exception>
 /// 
 public void AddRule( Rule rule )
 {
     // checking for existing name
     if ( this.rules.ContainsKey( rule.Name ) )
         throw new ArgumentException( "The fuzzy rule name already exists in the rulebase." );
     
     // adding rule
     this.rules.Add( rule.Name, rule );
 }
コード例 #2
0
ファイル: Rulebase.cs プロジェクト: accord-net/framework
        /// <summary>
        /// Gets all the rules of the rulebase.
        /// </summary>
        /// 
        /// <returns>An array with all the rulebase rules.</returns>
        /// 
        public Rule[] GetRules( )
        {
            Rule[] r = new Rule[rules.Count];

            int i = 0;
            foreach ( KeyValuePair<string, Rule> kvp in rules )
                r[i++] = kvp.Value;

            return r;
        }
コード例 #3
0
 /// <summary>
 /// Creates a new <see cref="Rule"/> and add it to the <see cref="Rulebase"/> of the 
 /// <see cref="InferenceSystem"/>.
 /// </summary>
 /// 
 /// <param name="name">Name of the <see cref="Rule"/> to create.</param>
 /// <param name="rule">A string representing the fuzzy rule.</param>
 /// 
 /// <returns>The new <see cref="Rule"/> reference. </returns>
 /// 
 public Rule NewRule(string name, string rule)
 {
     Rule r = new Rule(database, name, rule, normOperator, conormOperator);
     this.rulebase.AddRule(r);
     return r;
 }