addRule
Add rule to fuzzy inference system
Description
adds one or more fuzzy rules using the rule descriptions in
fisOut
= addRule(fisIn
,ruleDescription
)ruleDescription
.
Examples
Add Single Rule to Fuzzy Inference System
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
Add Rules to Fuzzy Inference System
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.
Add Rules Using Symbolic Expressions
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
ispoor
orfood
israncid
thentip
ischeap
.If
service
isexcellent
andfood
is notrancid
thentip
isgenerous
.
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)"
Add Rules Using Membership Function Indices
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
issmall
andvelocity
isbig
, thenforce
isnegBig
andforce2
isposBig2
.If
angle
is notsmall
andvelocity
issmall
, thenforce
isposSmall
andforce2
isnegSmall2
.
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
fisIn
— Fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object
Fuzzy inference system, specified as one of the following:
mamfis
object — Mamdani fuzzy inference systemsugfis
object — Sugeno fuzzy inference systemmamfistype2
object — Type-2 Mamdani fuzzy inference systemsugfistype2
object — Type-2 Sugeno fuzzy inference system
ruleDescription
— Rule description
string | character vector | numeric row vector | string array | character array | numeric array
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
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)"
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 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.
Output Arguments
fisOut
— Updated fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object
Updated fuzzy inference system, returned as one of the following objects.
mamfis
object — Mamdani fuzzy inference systemsugfis
object — Sugeno fuzzy inference systemmamfistype2
object — Type-2 Mamdani fuzzy inference systemsugfistype2
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 R2018bR2024b: Fuzzy inference system structures not supported
addRule
no longer supports fuzzy inference system structures.
Use mamfis
and sugfis
objects
instead. To convert existing fuzzy inference system structures to objects, use the convertfis
function.
R2019b: Fuzzy inference system structures will not be supported
Support for fuzzy inference systems structures will be removed in a future release. This
change was announced in R2018b. Using fuzzy inference system structures with
addRule
issues a warning starting in R2019b.
R2018b: Renamed to addRule
addrule
is now addRule
. To update your code,
change the function name from addrule
to addRule
.
The syntaxes are equivalent.
R2018b: Specify rules using linguistic and symbolic expressions
You can add rules to a fuzzy system using linguistic and symbolic expressions. This
addRule
functionality replaces the equivalent parsrule
functionality.
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
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)