Main Content

parsrule

(Removed) Parse fuzzy rules

parsrule has been removed. Use addRule instead. For more information, see Version History.

Description

outFIS = parsrule(inFIS,ruleList) returns a fuzzy inference system, outFIS, that is equivalent to the input fuzzy system, inFIS, but with fuzzy rules replaced by the rules specified in ruleList.

example

outFIS = parsrule(inFIS,ruleList,Name,Value) parses the rules in ruleList using options specified by one or more Name,Value pair arguments.

example

Examples

collapse all

Load a fuzzy inference system (FIS).

fis = readfis('tipper');

Specify if-then rules using the default 'verbose' format.

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 = parsrule(fis,rules);

fis2 is equivalent to fis, except that the rule base is replaced with the specified rules.

Load a fuzzy inference system (FIS).

fis = readfis('tipper');

Specify the following rules using symbols:

  • 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 using the 'symbolic' format.

fis2 = parsrule(fis,rules,'Format','symbolic');

Load fuzzy inference system (FIS).

fis = readfis('mam22.fis');

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 rules to FIS using the 'indexed' format.

fis2 = parsrule(fis,rules,'Format','indexed');

Load a fuzzy inference system (FIS).

fis = readfis('tipper');

Specify if-then rules using French keywords.

rule1 = "Si service est poor ou food est rancid alors tip est cheap";
rule2 = "Si service est excellent et food n''est_pas rancid alors tip est generous";
rules = [rule1 rule2];

Add the rules to the FIS.

fis2 = parsrule(fis,rules,'Language','francais');

Load a fuzzy inference system (FIS).

a = readfis('tipper');

Add a rule to the FIS.

ruleTxt = 'If service is poor then tip is cheap';
a2 = parsrule(a,ruleTxt,'verbose');

Input Arguments

collapse all

Input fuzzy inference system, specified as a FIS structure. parsrule does not modify inFIS.

Fuzzy rules, specified as one of the following:

  • 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);
  • 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 vector or string to specify a single rule.

You can change the rule format and language using the Format and Language options.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Format','symbolic' sets the rule format to symbolic expressions.

Rule format, specified as the comma-separated pair consisting 'Format' and one of the following:

  • 'verbose' — Use linguistic expressions.

    'If service is poor or food is rancid then tip is cheap 1'

    Specify the rule weight at the end of the rule text. If you omit the weight, a default value of 1 is used.

    You can specify the rule language using the Language option.

  • 'symbolic' — Use language-neutral symbolic expressions.

    'service==poor | food==rancid => tip=cheap 1'

    Specify symbolic expressions using the following symbols.

    Rule ComponentSymbol
    AND&
    OR|
    IS (in antecedent)==
    IS (in consequent)=
    IS NOT~=
    Implication (then)=>

    Specify the rule weight at the end of the rule text. If you omit the weight, a default value of 1 is used.

  • 'indexed' — Use input and output membership function (MF) indices.

    Specify indexed rules in the following format:

    '<input MFs>, <output MFs>, (<weight>) : <logical operator - 1(AND), 2(OR)>'

    For example:

    '1 1, 1 (1) : 2'

    To indicate NOT operations for input and output membership functions, use negative indices. For example, to specify "not the second membership function," use -2.

    To indicate a don’t care condition for an input or output membership function, use 0.

Rule language for 'verbose' format, specified as one of the following:

  • 'english' — Specify rules in English.

    'If service is poor or food is rancid then tip is cheap'
  • 'francais' — Specify rules in French.

    'Si service est poor ou food est rancid alors tip est cheap'
  • 'deutsch' — Specify rules in German.

    'Wenn service ist poor oder food ist rancid dann tip ist cheap'

The software parses the rules in ruleList using the following keywords.

Rule ComponentEnglishFrenchGerman
Start of antecedentifsiwenn
ANDandetund
ORorouoder
Start of consequent (implication)thenalorsdann
ISisestist
IS NOTis notn''est_pasist nicht

Output Arguments

collapse all

Fuzzy inference system, returned as a FIS structure. outFIS is the same as inFIS, except that the rule list contains only the rules specified in ruleList.

Version History

Introduced before R2006a

expand all

R2024b: Removed

parsrule has been removed. Use addRule instead.

If you previously added rules using linguistic or symbolic expressions with parsrule, you can specify rules using the same expressions with addrule. addRule automatically detects the format of the strings or character vectors in your rule list. Therefore, it is no longer necessary to specify the rule format. To add a rule list using addRule, use the following command:

fis = addRule(fis,rules);

Previously, you could add rules using indexed expressions with parsrule.

rule1 = "1 2, 1 4 (1) : 1";
rule2 = "-1 1, 3 2 (1) : 1";
rules = [rule1 rule2];
fis = parsrule(fis,rules,'Format','indexed');

Now, specify these rules using arrays of indices.

rule1 = [1 2 1 4 1 1];
rule2 = [-1 1 3 2 1 1];
rules = [rule1; rule2];
fis = addRule(fis,rules);

If you previously specified rules using the 'Language' name-value argument with parsrule, this functionality has been removed and there is no replacement. Specify your rules using addRule with a different rule format.

Previously, parsrule replaced the entire rule list in your fuzzy system. addRule appends your specified rules to the rule list.