fisrule

Description

Use fisrule objects to represent fuzzy if-then rules that relate input membership function conditions to corresponding output membership functions. The if portion of a fuzzy rule is the antecedent, which specifies the membership function for each input variable. The then portion of a fuzzy rule is the consequent, which specifies the membership function for each output variable. For more information on membership functions and fuzzy rules, see Foundations of Fuzzy Logic.

Creation

To create fuzzy rule objects, use the fisrule function. Using this function, you can create a single fuzzy rule or a vector of multiple fuzzy rules.

Syntax

rule = fisrule
rule = fisrule(ruleText)
rule = fisrule(ruleValues,numInputs)

Description

example

rule = fisrule creates a single fuzzy rule with the default description "input1==mf1 => output1=mf1".

example

rule = fisrule(ruleText) creates one or more fuzzy rules using the text descriptions in ruleText.

example

rule = fisrule(ruleValues,numInputs) creates one or more fuzzy rules using the numeric rule values in ruleValues. Specify the number of rule input variables using numInputs.

Input Arguments

expand all

Text rule description, specified as one of the following:

  • String or character vector specifying a single rule

    rule = "If service is poor or food is rancid then tip is cheap";
  • String array, where each element corresponds to a rule. For example:

    ruleList = ["If service is poor or food is rancid then tip is cheap";
                "If service is good then tip is average";
                "If service is excellent or food is delicious then tip is generous"];
  • Character array where each row corresponds to a rule. For example:

    rule1 = 'If service is poor or food is rancid then tip is cheap';
    rule2 = 'If service is good then tip is average';
    rule3 = 'If service is excellent or food is delicious then tip is generous';
    ruleList = char(rule1,rule2,rule3);

For each rule, use one of the following rule text formats:

  • Verbose — Linguistic expression in the following format, using the IF and THEN keywords:

    "IF <antecedent> THEN <consequent> (<weight>)"

    In <antecedent>, specify the membership function for each input variable using the IS or IS NOT keyword. Connect these conditions using the AND or OR keywords. If a rule does not use a given input variable, omit it from the antecedent.

    In <consequent>, specify the condition for each output variable using the IS or IS NOT keyword, and separate these conditions using commas. The IS NOT keyword is not supported for Sugeno outputs. If a rule does not use a given output variable, omit it from the consequent.

    Specify the weight using a positive numerical value.

    For example:

    "IF A IS a AND B IS NOT b THEN X IS x, Y IS NOT y (1)"
  • Symbolic — Expression that uses the symbols in the following table instead of keywords. There is no symbol for the IF keyword.

    SymbolKeyword
    ==IS (in rule antecedent)
    ~=IS NOT
    &AND
    |OR
    =>THEN
    =IS (in rule consequent)

    For example, the following symbolic rule is equivalent to the previous verbose rule.

    "A==a & B~=b => X=x, Y~=y (1)"

When you specify a rule using a text description, fisrule sets the Description, Weight, and Connection properties of the rule based on the description.

Numeric rule description, specified as one of the following:

  • Row vector to specify a single fuzzy rule

  • Array, where each row of ruleValues specifies one rule

For each row, the numeric rule description has M+N+2 columns, where M is the number of input variables and N is the number of output variables. Each column contains the following information:

  • The first M columns specify input membership function indices and correspond to the Antecedent property of the rule. To indicate a NOT condition, specify a negative value. If a rule does not use a given input, set the corresponding index to 0. For each rule, at least one input membership function index must be nonzero.

  • The next N columns specify output membership function indices and correspond to the Consequent property of the rule. To indicate a NOT condition for Mamdani systems, specify a negative value. NOT conditions are not supported for Sugeno outputs. If a rule does not use a given output, set the corresponding index to 0. For each rule, at least one output membership function index must be nonzero.

  • Column M+N+1 specifies the rule weight and corresponds to the Weight property of the rule.

  • The final column specifies the antecedent fuzzy operator and corresponds to the Connection property of the rule.

When you specify a rule using ruleVlaues, fisrule sets the Description property using default variable and membership function names.

Number of input variables for the rule, specified as a positive integer. If you specify the rule description using ruleValues, you must also specify the number of input variables. fisrule parses the rule antecedent values into the membership function indices for the input and output variables using numInputs.

Properties

expand all

Text rule description, specified as a string or character vector. The rule description is stored as a symbolic expression no matter how you specify the rule. For example, if you specify the following verbose rule using ruleText:

"IF A IS a AND B IS NOT b THEN X IS x, Y IS NOT y (1)"

The stored rule is:

"A==a & B~=b => X=x, Y~=y (1)"

For more information on the verbose and symbolic rule formats, see the ruleText input argument.

When you specify a rule using ruleVlaues, fisrule sets the Description property using default variable and membership function names. Before using the rule in a fuzzy system, you must update the description to use the variable and membership function names from that fuzzy system using the update function.

Rule antecedent, specified as a numeric vector of length M, where M is the number of input variables. Each element of Antecedent contains one of the following values:

  • Positive integer — The index of an input membership function, which represents an IS condition

  • Negative integer — The negative of an input membership function, which represents an IS NOT condition

  • 0 — A don't care condition, which means that the rule does not use the corresponding input variable

This value is set when you create a fuzzy rule using ruleValues. If you create a fuzzy rule using ruleText, before using the rule in a fuzzy system, you must populate the Antecedent property using the update function.

If you update the indices in the rule antecedent using dot notation, the Description property is not updated to reflect the changes. To update the rule description, use the update function.

Rule consequent, specified as a numeric vector of length N, where N is the number of output variables. Each element of Consequent contains one of the following values:

  • Positive integer — The index of an output membership function, which represents an IS condition

  • Negative integer — The negative of an output membership function, which represents an IS NOT condition

  • 0 — A don't care condition, which means that the rule does not use the corresponding output variable

This value is set when you create a fuzzy rule using ruleValues. If you create a fuzzy rule using ruleText, before using the rule in a fuzzy system, you must populate the Consequent property using the update function.

If you update the indices in the rule consequent using dot notation, the Description property is not updated to reflect the changes. To update the rule description, use the update function.

Rule weight, specified as a positive numeric scalar in the range [0 1].

If you update the rule weight using dot notation, the weight value in the Description property text is also updated.

Rule antecedent connection, specified as one of the following:

  • 1 — Evaluate rule antecedents using the AND operator.

  • 2 — Evaluate rule antecedents using the OR operator.

If you update the rule connection using dot notation, the antecedent operators in the Description property text are also updated.

Object Functions

updateUpdate fuzzy rule using fuzzy inference system

Examples

collapse all

Create a default fuzzy rule.

rule = fisrule
rule = 
  fisrule with properties:

    Description: "input1==mf1 => output1=mf1 (1)"
     Antecedent: 1
     Consequent: 1
         Weight: 1
     Connection: 1

To modify the rule properties, use dot notation. For example, specify a rule weight of 0.5.

rule.Weight = 0.5;

Create a fuzzy rule using a verbose text description.

rule = fisrule("if service is poor and food is delicious then tip is average (1)");

Alternatively, you can specify the same rule using a symbolic text description.

rule = fisrule("service==poor & food==delicious => tip=average")
rule = 
  fisrule with properties:

    Description: "service==poor & food==delicious => tip=average (1)"
     Antecedent: []
     Consequent: []
         Weight: 1
     Connection: 1

Before using rule with a fuzzy system, update the rule Antecedent and Consequent properties using the update function.

fis = readfis("tipper");
rule = update(rule,fis)
rule = 
  fisrule with properties:

    Description: "service==poor & food==delicious => tip=average (1)"
     Antecedent: [1 2]
     Consequent: 2
         Weight: 1
     Connection: 1

Create a fuzzy rule using a numeric description. Specify that the rule has two input variables.

rule = fisrule([1 2 2 0.5 1],2)
rule = 
  fisrule with properties:

    Description: "input1==mf1 & input2==mf2 => output1=mf2 (0.5)"
     Antecedent: [1 2]
     Consequent: 2
         Weight: 0.5000
     Connection: 1

Before using rule with a fuzzy system, update the rule Description property using the update function.

fis = readfis("tipper");
rule = update(rule,fis)
rule = 
  fisrule with properties:

    Description: "service==poor & food==delicious => tip=average (0.5)"
     Antecedent: [1 2]
     Consequent: 2
         Weight: 0.5000
     Connection: 1

Create a string array of text rule descriptions.

rules1 = ["if service is poor or food is rancid then tip is cheap (0.5)"...
          "if service is excellent and food is not rancid then tip is generous (0.75)"];

Create an array of fuzzy rules using these descriptions.

fuzzyRules1 = fisrule(rules1)
fuzzyRules1 = 
  1x2 fisrule array with properties:

    Description
    Antecedent
    Consequent
    Weight
    Connection

  Details:
                                Description                        
         __________________________________________________________

    1    "service==poor | food==rancid => tip=cheap (0.5)"         
    2    "service==excellent & food~=rancid => tip=generous (0.75)"

Alternatively, you can specify multiple rules using an array of numeric rule descriptions.

rules2 = [1 1 1 0.5 2;
          2 -1 3 0.75 1];
fuzzyRules2 = fisrule(rules2,2)
fuzzyRules2 = 
  1x2 fisrule array with properties:

    Description
    Antecedent
    Consequent
    Weight
    Connection

  Details:
                            Description                   
         _________________________________________________

    1    "input1==mf1 | input2==mf1 => output1=mf1 (0.5)" 
    2    "input1==mf2 & input2~=mf1 => output1=mf3 (0.75)"

Introduced in R2018b