evalfis
Evaluate fuzzy inference system
Syntax
Description
[
returns intermediate results from the fuzzy inference process. This syntax is not
supported when output
,fuzzifiedIn
,ruleOut
,aggregatedOut
,ruleFiring
] = evalfis(___)fis
is a fistree
object.
Examples
Evaluate Fuzzy Inference System
Load FIS.
fis = readfis('tipper');
Evaluate the FIS when the first input is 2
and the second input is 1
.
output = evalfis(fis,[2 1])
output = 7.0169
Evaluate FIS for Multiple Input Combinations
Load FIS.
fis = readfis('tipper');
Specify the input combinations to evaluate using an array with one row per input combination.
input = [2 1; 4 5; 7 8];
Evaluate the FIS for the specified input combinations.
output = evalfis(fis,input)
output = 3×1
7.0169
14.4585
20.3414
Each row of output
is the defuzzified output value for the corresponding row of input
.
Specify Number of Output Samples for FIS Evaluation
Load FIS.
fis = readfis('tipper');
Create an evalfisOptions
option set, specifying the number of samples in the output fuzzy sets.
options = evalfisOptions('NumSamplePoints',50);
Evaluate the FIS using this option set.
output = evalfis(fis,[2 1],options);
Evaluate Tree of Fuzzy Inference Systems
Create a pair of Mamdani fuzzy inference systems.
fis1 = mamfis('Name','fis1','NumInputs',2,'NumOutputs',1); fis2 = mamfis('Name','fis2','NumInputs',2,'NumOutputs',1);
Define the connection between the two.
con = ["fis1/output1" "fis2/input1"];
Create a tree of fuzzy inference systems.
tree = fistree([fis1 fis2],con);
Create an evalfisOptions
option set, specifying the number of samples in the output fuzzy sets.
options = evalfisOptions('NumSamplePoints',50);
Evaluate the fistree
object using a specified input combination and this option set.
y = evalfis(tree,[0.5 0.2 0.7],options)
y = 0.1553
Obtain Intermediate Fuzzy Inference Results
Load FIS.
fis = readfis('tipper');
Evaluate the FIS, and return the intermediate inference results.
[output,fuzzifiedIn,ruleOut,aggregatedOut,ruleFiring] = evalfis(fis,[2 1]);
You can examine the intermediate results to understand or visualize the fuzzy inference process. For example, view the aggregated output fuzzy set, which is the fuzzy set that evalfis
defuzzifies to find the output value. Also, plot the defuzzified output value.
outputRange = linspace(fis.output.range(1),fis.output.range(2),length(aggregatedOut))'; plot(outputRange,aggregatedOut,[output output],[0 1]) xlabel('Tip') ylabel('Output Membership') legend('Aggregated output fuzzy set','Defuzzified output')
The length of aggregatedOutput
corresponds to the number of sample points used to discretize output fuzzy sets.
Evaluate Type-2 Fuzzy Inference System
Create a type-2 Mamdani fuzzy inference system.
fis = mamfistype2('NumInputs',2,'NumOutputs',1);
Evaluate the FIS when the first input is 0.4
and the second input is 0.72
.
output = evalfis(fis,[0.4 0.72])
output = 0.1509
The output of a type-2 FIS is a crisp value.
When you obtain intermediate fuzzy inference results for a type-2 FIS, you obtain intermediate results generated using both upper and lower MF values. For example, obtain the intermediate fuzzified input values.
[output,fuzzifiedInput] = evalfis(fis,[0.5 0.75]);
View the fuzzified input values.
fuzzifiedInput
fuzzifiedInput = 9×4
0 0 0 0
1.0000 0 1.0000 0
0 0 0 0
0 0.4000 0 0.2500
1.0000 0.4000 1.0000 0.2500
0 0.4000 0 0.2500
0 0.4000 0 0.2500
1.0000 0.4000 1.0000 0.2500
0 0.4000 0 0.2500
The first two columns contain the fuzzified values of the first and second inputs based on the upper MF for each input. The second two columns contain the fuzzified values for based on the lower MF for each input.
Input Arguments
fis
— Fuzzy inference system
mamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object | fistree
object | homogeneous structure
Fuzzy inference system to be evaluated, 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 systemfistree
object — Tree of interconnected fuzzy inference systemsHomogeneous structure created using
getFISCodeGenerationData
. For an example, see Generate Code for Fuzzy System Using MATLAB Coder.
input
— Input values
M-by-NU
array
Input values, specified as an
M-by-NU
array, where NU is the number of
input variables in fis
and M is the
number of input combinations to evaluate.
evalfis
supports double-precision or single-precision
input values.
options
— Evaluation options
evalfisOptions
object
Evaluation options, specified as an evalfisOptions
object.
Output Arguments
fuzzifiedIn
— Fuzzified input values
array
Fuzzified input values, returned as an array.
When fis
is a type-1 fuzzy inference system,
fuzzifiedIn
is an
NR-by-NU
array, where NR is the number of
rules in fis
. Element (i,j) of
fuzzifiedIn
is the value of the input membership
function for the jth input in the ith rule.
When fis
is a type-2 fuzzy inference system,
fuzzifiedIn
is an
NR-by-(2*NU)
array. The first NU columns
contain the fuzzified values of the upper membership function for each rule,
and the last NU columns contain
the fuzzified values from the lower membership functions.
If input
specifies multiple input combinations, then
fuzzifiedIn
corresponds to the combination in the
last row of input
.
For more information on fuzzifying input values, see Fuzzify Inputs.
This output argument is not supported when fis
is a
fistree
object.
ruleOut
— Rule outputs
array
Rule outputs, returned as an array. To obtain the output for each rule,
evalfis
applies the firing strength from the rule
antecedent to the output membership function using the implication method
specified in fis
.
When fis
is a type-1 Mamdani system,
ruleOut
is an
NS-by-(NRNY)
array, where NR is the number of
rules, NY is the number of
outputs, and NS is the number of
sample points used for evaluating output variable ranges. Each column of
ruleOut
contains the output fuzzy set for one rule.
The first NR columns contain the
rule outputs for the first output variable, the next
NR columns correspond to
the second output variable, and so on.
When fis
is a type-2 Mamdani system,
ruleOut
is an
NS-by-(2*NR*NY)
array. The first
NR*NY
columns contain the rule outputs generated using upper membership functions,
and the last
NR*NY
columns contain the rule outputs generated using lower membership
functions.
When fis
is a type-1 Sugeno system, each rule output
is a scalar value. In this case, ruleOut
is an
NR-by-NY
array. Element (j,k) of
ruleOut
is the value of the kth
output variable for the jth rule.
When fis
is a type-2 Sugeno system,
ruleOut
is an
NR-by-(3*NY)
array. The first NY columns
contain the rule output levels. The next
NY columns contain the
corresponding rule firing strengths generated using upper membership
functions. The last NY columns
contain the rule firing strengths generated using lower membership
functions. For example, in a three-output system, columns 4 and 7 contain
the firing strengths for the output levels in column 1.
If input
specifies multiple input combinations, then
ruleOut
corresponds to the combination in the last
row of input
.
For more information on fuzzy implication, see Apply Implication Method.
This output argument is not supported when fis
is a
fistree
object.
aggregatedOut
— Aggregated output
array | row vector
Aggregated output for each output variable, returned as an
NS-by-NY
array or a row vector of length
NY. For each output variable,
evalfis
combines the corresponding outputs from all
the rules using the aggregation method specified in
fis
.
For a type-1 Mamdani system, the aggregate result for each output variable
is a fuzzy set. In this case, aggregatedOut
is as an
NS-by-NY
array, where NY is the number of
outputs and NS is the number of
sample points used for evaluating output variable ranges. Each column of
aggregatedOut
contains the aggregate fuzzy set for
one output variable.
For a type-2 Mamdani system, the aggregate result for each output variable
is a fuzzy set. In this case, aggregatedOut
is as an
NS-by-(2*NY)
array. The first NY columns
contain the aggregated outputs generated using upper membership functions,
and the last NY columns contain
the aggregated outputs generated using lower membership functions.
When fis
is a type-1 Sugeno system, the aggregate
result for each output variable is a scalar value. In this case,
aggregatedOut
is a row vector of length
NY, where element
k is the sum of the rule outputs for the
kth output variable.
When fis
is a type-2 Sugeno system,
aggregatedOut
is an
NR-by-(3*NY)
array. aggregatedOut
contains the same data as
ruleOut
with the columns sorted based on the output
levels. For example, in a three-output system, when the output levels in
column 1 are sorted, the corresponding firing strengths in columns 4 and 7
are adjusted accordingly.
If input
specifies multiple input combinations, then
aggregatedOut
corresponds to the combination in the
last row of input
.
For more information on fuzzy aggregation, see Aggregate All Outputs.
This output argument is not supported when fis
is a
fistree
object.
ruleFiring
— Rule firing strengths
column vector | array
Rule firing strength, returned as a column vector or array. To obtain the
firing strength for each rule, evalfis
evaluates the
rule antecedents; that is, it applies fuzzy operator to the values of the
fuzzified inputs.
For a type-1 fuzzy system, ruleFiring
is a column
vector of length NR, where
NR is the number of rules,
and element i is the firing strength of the
ith rule.
For a type-2 fuzzy system, ruleFiring
is an
NR-by-2 array. The first
column contains the rule firing strengths generated using upper membership
functions, and the second column contains the rule firing strengths
generated using lower membership functions.
If input
specifies multiple input combinations, then
ruleFiring
corresponds to the combination in the
last row of input
.
For more information on applying the fuzzy operator, see Apply Fuzzy Operator.
This output argument is not supported when fis
is a
fistree
object.
Alternative Functionality
App
You can interactively evaluate type-1 and type-2 fuzzy inference systems using the Fuzzy Logic Designer app. The app does not support FIS trees.
Simulink Block
You can evaluate FIS objects using the Fuzzy Logic Controller block. This block does not support evaluating
FIS trees. For more information on mapping the arguments of
evalfis
to the Fuzzy Logic Controller block,
see Simulate Fuzzy Inference Systems in Simulink.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
All
evalfis
syntaxes are supported for code generation. However,mamfis
,sugfis
,mamfistype2
,sugfistype2
, andfistree
objects are not supported. To useevalfis
for code generation, you must convert your FIS objects into homogeneous structures usinggetFISCodeGenerationData
.Unlike the Fuzzy Logic Controller block,
evalfis
does not support fixed-point data for simulation or code generation.When evaluating a fuzzy inference system in Simulink®, it is recommended to not use
evalfis
orevalfisOptions
within a MATLAB Function block. Instead, evaluate your fuzzy inference system using a Fuzzy Logic Controller block.
Version History
Introduced before R2006aR2024b: Fuzzy inference system structures not supported
evalfis
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.
R2022b: C and C++ code generation support for evaluating FIS trees
You can generate code for evaluating FIS trees using MATLAB® Coder™. For more information, see Generate Code for Fuzzy System Using MATLAB Coder.
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 evalfis
issues a warning starting in
R2019b.
R2018b: C and C++ code generation support
You can generate code for loading and evaluating the following types of fuzzy inference systems using MATLAB Coder.
Type-1 and type-2 Mamdani systems
Type-1 and type-2 Mamdani systems
For more information, see Generate Code for Fuzzy System Using MATLAB Coder.
R2018b: Input argument order changed
Previously, to evaluate a fuzzy inference system, fis
, you
specified the input variable values, input
, as the first input
argument. For example:
output = evalfis(input,fis); output = evalfis(input,fis,options);
Update your code to specify the fuzzy inference system as the first input argument. For example:
output = evalfis(fis,input); output = evalfis(fis,input,options);
R2018b: Obtain intermediate rule firing strengths
You can obtain intermediate rule firing strengths when evaluating a fuzzy
inference system using the ruleFiring
output argument.
R2018a: Specify number of sample points for output fuzzy sets using evalfisOptions
object
Previously, to specify the number of sample points, numPts
, to
use when evaluating output fuzzy sets of fuzzy inference system
fis
, you used an input argument. For example:
output = evalfis(input,fis,numPts);
Update your code to specify the number of sample points using an
evalfisOptions
object. For example:
opt = evalfisOptions('NumSamplePoints',numPts);
output = evalfis(input,fis,opt);
R2018a: Diagnostic message behavior changed
The diagnostic message behavior of the evalfis
function has
changed. Previously, the evalfis
function had the following
behaviors for diagnostic conditions.
Diagnostic Condition | Previous Behavior |
---|---|
Input values outside of their specified variable ranges | MATLAB warning |
No rules fired for a given output at the current input values | MATLAB Command Window message |
Empty output fuzzy sets | MATLAB Command Window message |
These diagnostic conditions are reported as MATLAB warnings by default. You can change this behavior by specifying the
corresponding options in an evalfisOptions
object.
To disable the default warning messages, update your code to use an
evalfisOptions
object, and specify the diagnostic message
options. For example, disable the empty output fuzzy set message.
opt = evalfisOptions('EmptyOutputFuzzySetMessage',"none"); output = evalfis(input,fis,opt);
R2018a: Intermediate fuzzy inference outputs for Sugeno systems analogous to outputs for Mamdani systems
When evaluating a Sugeno system using the following syntax, the intermediate fuzzy inference results are now analogous to the intermediate results for Mamdani systems.
[output,fuzzifiedInputs,ruleOutputs,aggregatedOutput] = evalfis(input,fis);
For a Sugeno system:
ruleOutputs
now returns an array that contains the scalar output value for each rule; that is, the product of the rule firing strength and the rule output level.aggregatedOutput
now returns the sum of all the rule output values for each output variable.
Previously, for a Sugeno fuzzy system:
ruleOutputs
returned an array that contained the output level for each rule.aggregatedOutput
returned an array that contained the firing strength for each rule.
Starting in R2018a, if your code returns intermediate fuzzy inference results when
evaluating a Sugeno system using evalfis
, modify your code to
use the new ruleOutputs
and aggregatedOutput
results.
R2017b: Smaller number of sample points supported for output variable ranges
Using the numPts
input argument, you can specify the number
of sample points for evaluating the output range of a Mamdani fuzzy inference system
as any value greater than 1
. Previously, the minimum value was
101
.
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)