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
creates a single fuzzy rule with the default
description "input1==mf1 => output1=mf1"
.
creates one or more fuzzy rules using the text descriptions in
rule
= fisrule(ruleText
)ruleText
.
creates 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
ruleText
— Text rule description
string | character vector | string array | character array
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.
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
andTHEN
keywords:"IF <antecedent> THEN <consequent> (<weight>)"
In
<antecedent>
, specify the membership function for each input variable using theIS
orIS NOT
keyword. Connect these conditions using theAND
orOR
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 theIS
orIS NOT
keyword, and separate these conditions using commas. TheIS 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.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.
ruleValues
— Numeric rule description
row vector | numeric array
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 aNOT
condition, 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
Consequent
property of the rule. To indicate aNOT
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 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
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.
numInputs
— Number of input variables
positive integer
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
Description
— Text rule description
string | character vector
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.
Antecedent
— Rule antecedent
numeric vector
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
conditionNegative integer — The negative of an input membership function, which represents an
IS NOT
condition0
— 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.
Consequent
— Rule consequent
numeric vector
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. 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.
Weight
— Rule weight
1
(default) | positive numeric scalar
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.
Connection
— Rule antecedent connection
1
| 2
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
update | Update fuzzy rule using fuzzy inference system |
Examples
Create Fuzzy Rule
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 Fuzzy Rule Using Text Description
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 Fuzzy Rule Using Numeric Description
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 Multiple Fuzzy Rules
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)"
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)