fisrule
Fuzzy rule
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.
Description
rule = fisrule returns a single fuzzy rule with the default
description "input1==mf1 => output1=mf1".
returns one or more fuzzy rules using the text descriptions in
rule = fisrule(ruleText)ruleText.
returns one or more fuzzy rules using the numeric rule values in
rule = fisrule(ruleValues,numInputs)ruleValues. Specify the number of rule input variables using
numInputs.
Input Arguments
Text rule description, specified as one of these values:
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
IFandTHENkeywords:"IF <antecedent> THEN <consequent> (<weight>)"
In
<antecedent>, specify the membership function for each input variable using theISorIS NOTkeyword. Connect these conditions using theANDorORkeywords. 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 theISorIS NOTkeyword, and separate these conditions using commas. TheIS NOTkeyword 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
IFkeyword.Symbol Keyword ==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
ruleValuesspecifies 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
Antecedentproperty of the rule. To indicate aNOTcondition, specify a negative value. If a rule does not use a given input, set the corresponding index to0. 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
Consequentproperty of the rule. To indicate aNOTcondition for Mamdani systems, specify a negative value.NOTconditions are not supported for Sugeno outputs. If a rule does not use a given output, set the corresponding index to0. 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
Weightproperty of the rule.The final column specifies the antecedent fuzzy operator and corresponds to the
Connectionproperty 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
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
ISconditionNegative integer — The negative of an input membership function, which represents an
IS NOTcondition0— 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
IScondition.Negative integer — The negative of an output membership function, which represents an
IS NOTcondition. Sugeno systems do not support rules with NOT logic in the consequent.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 these values:
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
update | Update fuzzy rule using fuzzy inference system |
Examples
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 =
1×2 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 =
1×2 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)"
Version History
Introduced in R2018b
See Also
mamfis | sugfis | mamfistype2 | sugfistype2 | fisvar | fismf
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)