Main Content

evalfis

Evaluate fuzzy inference system

Description

output = evalfis(fis,input) evaluates the fuzzy inference system fis for the input values in input and returns the resulting output values in output.

example

output = evalfis(fis,input,options) evaluates the fuzzy inference system using specified evaluation options.

example

[output,fuzzifiedIn,ruleOut,aggregatedOut,ruleFiring] = evalfis(___) returns intermediate results from the fuzzy inference process. This syntax is not supported when fis is a fistree object.

example

Examples

collapse all

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')

Figure contains an axes object. The axes object with xlabel Tip, ylabel Output Membership contains 2 objects of type line. These objects represent 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.

Input Arguments

collapse all

Fuzzy inference system to be evaluated, specified as one of the following:

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.

Evaluation options, specified as an evalfisOptions object.

Output Arguments

collapse all

Output values, returned as an M-by-NY array, where NY is the number of output variables in fis. evalfis evaluates fis for each row of input and returns the resulting defuzzified outputs in the corresponding row of output.

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.

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.

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.

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

Version History

Introduced before R2006a

expand all