Evaluate fuzzy inference system
[
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.
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
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
.
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);
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
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.
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.
fis
— Fuzzy inference systemmamfis
object | sugfis
object | mamfistype2
object | sugfistype2
object | fistree
objectFuzzy inference system to be evaluated, specified as one of the following:
mamfis
object — Mamdani fuzzy inference system
sugfis
object — Sugeno fuzzy inference system
mamfistype2
object — Type-2 Mamdani fuzzy inference
system
sugfistype2
object — Type-2 Sugeno fuzzy inference
system
fistree
object -
Tree of interconnected fuzzy inference systems
Homogeneous structure created using getFISCodeGenerationData
. For an example, see Generate Code for Fuzzy System Using MATLAB Coder.
input
— Input valuesInput 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 optionsevalfisOptions
objectEvaluation options, specified as an evalfisOptions
object.
fuzzifiedIn
— Fuzzified input valuesFuzzified 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 outputsRule 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 outputAggregated output for each output variable, returned as an array.
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 strengthsRule 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.
You can evaluate type-1 fuzzy inference systems using the Rule Viewer in the Fuzzy Logic Designer app.
You can evaluate fuzzy inference systems using the Fuzzy Logic Controller block. For more information on mapping the
arguments of evalfis
to the Fuzzy Logic
Controller block, see Simulate Fuzzy Inference Systems in Simulink.
evalfis
input argument order has changedBehavior changed in R2018b
The order of input arguments for evalfis
has changed, which
requires updates to your code.
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);
evalfisOptions
objectBehavior changed in R2018a
To specify the number of sample points for output fuzzy sets, you now us an
evalfisOptions
object, which requires updates to your
code.
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);
evalfis
diagnostic message behavior has changedBehavior changed in R2018a
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 |
Starting in R2018a, 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);
Behavior changed in R2018a
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.
Usage notes and limitations:
All evalfis
syntaxes are supported for code
generation. However, mamfis
,
sugfis
, and fistree
objects
are not supported. To use evalfis
for code generation,
you must convert your FIS objects into homogeneous structures using
getFISCodeGenerationData
.
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
or
evalfisOptions
within a MATLAB
Function block. Instead, evaluate your fuzzy inference system
using a Fuzzy Logic Controller block.
You have a modified version of this example. Do you want to open this example with your edits?