Main Content

addRule

Add rule to fuzzy inference system

Description

fisOut = addRule(fisIn) adds a single fuzzy rule to fuzzy inference system fisIn with the default description "input1==mf1 => output1=mf1" and returns the resulting fuzzy system in fisOut.

example

fisOut = addRule(fisIn,ruleDescription) adds one or more fuzzy rules using the rule descriptions in ruleDescription.

Examples

collapse all

Load a fuzzy inference system (FIS), and clear the existing rules.

fis = readfis('tipper');
fis.Rules = [];

Add a rule to the FIS.

ruleTxt = 'If service is poor then tip is cheap';
fis2 = addRule(fis,ruleTxt);

fis2 is equivalent to fis, except that the specified rule is added to the rule base.

fis2.Rules
ans = 
  fisrule with properties:

    Description: "service==poor => tip=cheap (1)"
     Antecedent: [1 0]
     Consequent: 1
         Weight: 1
     Connection: 1

Load a fuzzy inference system (FIS).

fis = readfis('tipper');

Specify if-then rules using linguistic expressions.

rule1 = "If service is poor or food is rancid then tip is cheap";
rule2 = "If service is excellent and food is not rancid then tip is generous";
rules = [rule1 rule2];

Add the rules to the FIS.

fis2 = addRule(fis,rules);

fis2 is equivalent to fis, except that the specified rules are added to the rule base.

Load a fuzzy inference system (FIS), and clear the existing rules.

fis = readfis('tipper');
fis.Rules = [];

Specify the following rules using symbolic expressions:

  • If service is poor or food is rancid then tip is cheap.

  • If service is excellent and food is not rancid then tip is generous.

rule1 = "service==poor | food==rancid => tip=cheap";
rule2 = "service==excellent & food~=rancid => tip=generous";
rules = [rule1 rule2];

Add the rules to the FIS.

fis2 = addRule(fis,rules);

fis2 is equivalent to fis, except that the specified rules are added to the rule base.

fis2.Rules
ans = 
  1x2 fisrule array with properties:

    Description
    Antecedent
    Consequent
    Weight
    Connection

  Details:
                               Description                      
         _______________________________________________________

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

Load fuzzy inference system (FIS) and clear the existing rules.

fis = readfis('mam22.fis');
fis.Rules = [];

Specify the following rules using membership function indices:

  • If angle is small and velocity is big, then force is negBig and force2 is posBig2.

  • If angle is not small and velocity is small, then force is posSmall and force2 is negSmall2.

rule1 = [1 2 1 4 1 1];
rule2 = [-1 1 3 2 1 1];
rules = [rule1; rule2];

Add the rules to the FIS.

fis2 = addRule(fis,rules);

fis2 is equivalent to fis, except that the specified rules are added to the rule base.

fis2.Rules
ans = 
  1x2 fisrule array with properties:

    Description
    Antecedent
    Consequent
    Weight
    Connection

  Details:
                                       Description                               
         ________________________________________________________________________

    1    "angle==small & velocity==big => force=negBig, force2=posBig2 (1)"      
    2    "angle~=small & velocity==small => force=posSmall, force2=negSmall2 (1)"

Input Arguments

collapse all

Fuzzy inference system, specified as one of the following:

  • mamfis object — Mamdani fuzzy inference system

  • sugfis object — Sugeno fuzzy inference system

  • mamfistype2 object — Type-2 Mamdani fuzzy inference system (since R2019b)

  • sugfistype2 object — Type-2 Sugeno fuzzy inference system (since R2019b)

Rule description, specified using either a text or numeric rule definition.

Text Rule Description

For a text rule description, specify ruleDescription 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.

    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.

    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.

    "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)"

Numeric Rule Description

For a numeric rule description, specify ruleDescription 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.

Output Arguments

collapse all

Updated fuzzy inference system, returned as one of the following objects.

  • mamfis object — Mamdani fuzzy inference system

  • sugfis object — Sugeno fuzzy inference system

  • mamfistype2 object — Type-2 Mamdani fuzzy inference system

  • sugfistype2 object — Type-2 Sugeno fuzzy inference system

fisOut contains the added output rules, with all other properties matching the properties of fisIn.

Version History

Introduced in R2018b

expand all