This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

tunefis

Tune fuzzy inference system or tree of fuzzy inference systems

Syntax

fisout = tunefis(fisin,paramset,in,out)
fisout = tunefis(fisin,paramset,in,out,options)
fisout = tunefis(fisin,paramset,custcostfcn,options)
[fisout,optoutputs] = tunefis(___)

Description

example

fisout = tunefis(fisin,paramset,in,out) tunes the fuzzy system fisin using parameters identified by paramset and the training data specified by in and out.

example

fisout = tunefis(fisin,paramset,in,out,options) tunes the fuzzy system with additional options from the object options created using tunefisOptions.

fisout = tunefis(fisin,paramset,custcostfcn,options) tunes the fuzzy system using custcostfcn, a function handle to a custom cost function.

[fisout,optoutputs] = tunefis(___) tunes the fuzzy system and returns an additional output optoutputs with information about tuning algorithm.

Examples

collapse all

Create the initial fuzzy inference system using genfis.

x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);
options = genfisOptions('GridPartition');
options.NumMembershipFunctions = 5;
fisin = genfis(x,y,options);

Obtain the tunable settings of inputs, outputs, and rules of the fuzzy inference system.

[in,out,rule] = getTunableSettings(fisin);

Tune the membership function parameters with "anfis".

fisout = tunefis(fisin,[in;out],x,y,tunefisOptions("Method","anfis"));
ANFIS info: 
	Number of nodes: 24
	Number of linear parameters: 10
	Number of nonlinear parameters: 15
	Total number of parameters: 25
	Number of training data pairs: 101
	Number of checking data pairs: 0
	Number of fuzzy rules: 5


Start training ANFIS ...

   1 	 0.0694086
   2 	 0.0680259
   3 	 0.066663
   4 	 0.0653198
   5 	 0.0639961
Step size increases to 0.011000 after epoch 5.
   6 	 0.0626917
   7 	 0.0612787
   8 	 0.0598881
   9 	 0.0585193
Step size increases to 0.012100 after epoch 9.
  10 	 0.0571712

Designated epoch number reached --> ANFIS training completed at epoch 10.

Minimal training RMSE = 0.057171

Create the initial fuzzy inference system using genfis.

x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);
options = genfisOptions('GridPartition');
options.NumMembershipFunctions = 5;
fisin = genfis(x,y,options);            

Obtain the tunable settings of inputs, outputs, and rules of the fuzzy inference system.

[in,out,rule] = getTunableSettings(fisin);

Tune the rule parameter only. In this example, the pattern search method is used.

fisout = tunefis(fisin,rule,x,y,tunefisOptions("Method","patternsearch"));
Iter     Func-count       f(x)      MeshSize     Method
    0           1       0.346649             1      
    1          19       0.346649           0.5     Refine Mesh
    2          37       0.346649          0.25     Refine Mesh
    3          55       0.346649         0.125     Refine Mesh
    4          73       0.346649        0.0625     Refine Mesh
    5          91       0.346649       0.03125     Refine Mesh
    6         109       0.346649       0.01562     Refine Mesh
    7         127       0.346649      0.007812     Refine Mesh
    8         145       0.346649      0.003906     Refine Mesh
    9         163       0.346649      0.001953     Refine Mesh
   10         181       0.346649     0.0009766     Refine Mesh
   11         199       0.346649     0.0004883     Refine Mesh
   12         217       0.346649     0.0002441     Refine Mesh
   13         235       0.346649     0.0001221     Refine Mesh
   14         253       0.346649     6.104e-05     Refine Mesh
   15         271       0.346649     3.052e-05     Refine Mesh
   16         289       0.346649     1.526e-05     Refine Mesh
   17         307       0.346649     7.629e-06     Refine Mesh
   18         325       0.346649     3.815e-06     Refine Mesh
   19         343       0.346649     1.907e-06     Refine Mesh
   20         361       0.346649     9.537e-07     Refine Mesh
Optimization terminated: mesh size less than options.MeshTolerance.

Create the initial fuzzy inference system using genfis.

x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);
options = genfisOptions('GridPartition');
options.NumMembershipFunctions = 5;
fisin = genfis(x,y,options);

Obtain the tunable settings of inputs, outputs, and rules of the fuzzy inference system.

[in,out,rule] = getTunableSettings(fisin);

You can tune with custom parameter settings using setTunable or dot notation.

Do not tune input 1.

in(1) = setTunable(in(1),false);

For output 1:

  • do not tune membership functions 1 and 2,

  • do not tune membership function 3,

  • set the minimum parameter range of membership function 4 to -2,

  • and set the maximum parameter range of membership function 5 to 2.

out(1).MembershipFunctions(1:2) = setTunable(out(1).MembershipFunctions(1:2),false);
out(1).MembershipFunctions(3).Parameters.Free = false;
out(1).MembershipFunctions(4).Parameters.Minimum = -2;
out(1).MembershipFunctions(5).Parameters.Maximum = 2;

For the rule settings,

  • do not tune rules 1 and 2,

  • set the antecedent of rule 3 to non-tunable,

  • allow NOT logic in the antecedent of rule 4,

  • and do not ignore any outputs in rule 3.

rule(1:2) = setTunable(rule(1:2),false);
rule(3).Antecedent.Free = false;
rule(4).Antecedent.AllowNot = true;
rule(3).Consequent.AllowEmpty = false;

Set the maximum number of iterations to 20 and tune the fuzzy inference system.

opt = tunefisOptions("Method","particleswarm");
opt.MethodOptions.MaxIterations = 20;
fisout = tunefis(fisin,[in;out;rule],x,y,opt);
                                 Best            Mean     Stall
Iteration     f-count            f(x)            f(x)    Iterations
    0              90          0.3265           1.857        0
    1             180          0.3265           4.172        0
    2             270          0.3265           3.065        1
    3             360          0.3265           3.839        2
    4             450          0.3265           3.386        3
    5             540          0.3265           3.249        4
    6             630          0.3265           3.311        5
    7             720          0.3265           2.901        6
    8             810          0.3265           2.868        7
    9             900          0.3181            2.71        0
   10             990          0.3181           2.068        1
   11            1080          0.3181           2.692        2
   12            1170          0.3165           2.146        0
   13            1260          0.3165           1.869        1
   14            1350          0.3165           2.364        2
   15            1440          0.3165            2.07        0
   16            1530          0.3164           1.678        0
   17            1620          0.2978           1.592        0
   18            1710          0.2977           1.847        0
   19            1800          0.2954           1.666        0
   20            1890          0.2947           1.608        0
Optimization ended: number of iterations exceeded OPTIONS.MaxIterations.

Input Arguments

collapse all

Fuzzy system, specified as a mamfis, sugfis, or fistree object. The fuzzy system can be a fuzzy inference system or network of interconnected fuzzy inference systems. It is created using mamfis, sugfis, genfis, or fistree.

Tunable parameter settings, specified as an array of input, output, and rule parameter settings of the input fuzzy system fisin. To obtain these parameter settings, use getTunableSettings with the input fuzzy system fisin. paramset can be the input parameter, the output parameter, the rule parameter, or some combination of these parameters as an array. The contents of the array depend on which parameters you would like to tune.

Input training data, specified as an m-by-n matrix, where m is the total number of input datasets and n is the number of inputs. The number of input and output datasets must be the same.

Output training data, specified as an m-by-n matrix, where m is the total number of output datasets and n is the number of outputs. The number of input and output datasets must be the same.

FIS tuning options, specified as a tunefisOptions object. You can specify the tuning algorithm method and other options for the tuning process.

Custom cost function, specified as a function handle. The custom cost function evaluates fisout to calculate its cost with respect to an evaluation criterion, such as input/output data. custcostfcn must accept at least one input argument for fisout and returns a cost value. You can provide an anonymous function handle to attach additional data for cost calculation, as described in this example:

function fitness = custcost(cost,trainingData)
  ...
end
custcostfcn = @(fis)custcost(fis,trainingData);

Output Arguments

collapse all

Fuzzy system, specified as a mamfis, sugfis, or fistree object. The fuzzy system can be a fuzzy inference system or network of interconnected fuzzy inference systems. It is created using mamfis, sugfis, genfis, or fistree. fisout is the tuned FIS.

Tuning algorithm summary, specified as a structure containing the following fields:

  • tuningOutputs

  • errorMessage

tuningOutputs is a structure with information about the tuning algorithm method specified by tunefisOptions in the options input argument. The specific outputs differ for each tuning algorithm. See the specific tuning method for details about its outputs:

  • 'ga' — genetic algorithm

  • 'particleswarm' — particle swarm

  • 'patternsearch' — pattern search

  • 'simulannealbnd' — simulated annealing algorithm

  • 'anfis' — adaptive neuro-fuzzy

errorMessage is the message generated when updating fisin with new parameter values.

Introduced in R2019a