Training routine for Sugeno-type Fuzzy Inference System (MEX only)


[fis,error,stepsize] = anfis(trnData)
[fis,error,stepsize] = anfis(trnData,initFis) 
[fis,error,stepsize] = anfis(trnData,numMFs) 
[fis,error,stepsize,chkFis,chkErr] = ...
[fis,error,stepsize,chkFis,chkErr] = ...


This syntax is the major training routine for Sugeno-type fuzzy inference systems. anfis uses a hybrid learning algorithm to identify parameters of Sugeno-type fuzzy inference systems. It applies a combination of the least-squares method and the backpropagation gradient descent method for training FIS membership function parameters to emulate a given training data set. anfis can also be invoked using an optional argument for model validation. The type of model validation that takes place with this option is a checking for model overfitting, and the argument is a data set called the checking data set.

anfis only supports Sugeno-type systems, and these must have the following properties:

  • Be first or zeroth order Sugeno-type systems.

  • Have a single output, obtained using weighted average defuzzification. All output membership functions must be the same type and either be linear or constant.

  • Have no rule sharing. Different rules cannot share the same output membership function, namely the number of output membership functions must be equal to the number of rules.

  • Have unity weight for each rule.

An error occurs if your FIS structure does not comply with these constraints.

Moreover, anfis cannot accept all the customization options that basic fuzzy inference allows. That is, you cannot make your own membership functions and defuzzification functions; you must use the ones provided.

The arguments in the description for anfis are as follows. Note that you can specify the arguments trnOpt, dispOpt, chkData, and optMethod as empty, [], when necessary:

  • trnData: the name of a training data set. This matrix contains data input in all but the last column. The last column contains a single vector of output data.

  • initFis: the name of a fuzzy inference system (FIS) used to provide anfis with an initial set of membership functions for training. Without this option, anfis uses genfis1 to implement a default initial FIS for training. This default FIS has two membership functions of the Gaussian type, when it is invoked with only one argument. If initFis is provided as a single number (or a vector), it is taken as the number of membership functions (or the vector) whose entries are the respective numbers of membership functions associated with each respective input when these numbers differ for each input). In this case, both arguments of anfis are passed to genfis1 to generate a valid FIS structure before starting the training process.

  • numMFs: the number of membership functions. Use numMFs, an integer scalar value, as the second argument to anfis when you do not already have a FIS to train and you want anfis to build a default initial FIS using your data. Each input and output to this FIS is characterized by one or more membership functions. Specify the number of membership functions in numMFs.

  • trnOpt: a vector of training options. When a training option is entered as NaN, the default options is in force. These options are as follows:

    • trnOpt(1): training epoch number (default: 10)

    • trnOpt(2): training error goal (default: 0)

    • trnOpt(3): initial step size (default: 0.01)

    • trnOpt(4): step size decrease rate (default: 0.9)

    • trnOpt(5): step size increase rate (default: 1.1)

  • dispOpt: a vector of display options that specify what message to display in the MATLAB® Command Window during training. The default value for a display option is 1, which means that the corresponding information is displayed. A 0 means the corresponding information is not displayed. When a display option is entered as NaN, the default options will be in force. These options are as follows:

    • dispOpt(1): ANFIS information, such as numbers of input and output membership functions, and so on (default: 1)

    • dispOpt(2): error (default: 1)

    • dispOpt(3): step size at each parameter update (default: 1)

    • dispOpt(4): final results (default: 1)

  • chkData: the name of an optional checking data set for overfitting model validation. This data set is a matrix in the same format as the training data set. When you supply chkData as an input argument, you must also supply chkFis and chkErr as output arguments.

  • optMethod: an optional optimization method used in membership function parameter training: either 1 for the hybrid method or 0 for the backpropagation method. The default method is the hybrid method, which is a combination of least-squares estimation with backpropagation. The default method is invoked whenever the entry for this argument is anything but 0.

The training process stops whenever the designated epoch number is reached or the training error goal is achieved.

    Note:   When anfis is invoked with two or more arguments, optional arguments take on their default values if they are entered as NaNs or empty matrices. Default values can be changed directly by modifying the file anfis.m. Either NaNs or empty matrices must be used as placeholders for variables if you do not want to specify them, but do want to specify succeeding arguments, for example, when you implement the checking data option of anfis.

The range variables in the previous description for anfis are as follows:

  • fis is the FIS structure whose parameters are set according to a minimum training error criterion.

  • error or chkErr is an array of root mean squared errors representing the training data error signal and the checking data error signal, respectively. The function only returns chkErr when you supply chkData as an input argument.

  • stepsize is an array of step sizes. The step size is decreased (by multiplying it with the component of the training option corresponding to the step size decrease rate) if the error measure undergoes two consecutive combinations of an increase followed by a decrease. The step size is increased (by multiplying it with the increase rate) if the error measure undergoes four consecutive decreases.

  • chkFis is the FIS structure whose parameters are set according to a minimum checking error criterion. The function only returns chkFis when you supply chkData as an input argument.


x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);
trnData = [x y];
numMFs = 5;
mfType = 'gbellmf';
epoch_n = 20;
in_fis = genfis1(trnData,numMFs,mfType);
out_fis = anfis(trnData,in_fis,20);
legend('Training Data','ANFIS Output');


Jang, J.-S. R., "Fuzzy Modeling Using Generalized Neural Networks and Kalman Filter Algorithm," Proc. of the Ninth National Conf. on Artificial Intelligence (AAAI-91), pp. 762-767, July 1991.

Jang, J.-S. R., "ANFIS: Adaptive-Network-based Fuzzy Inference Systems," IEEE Transactions on Systems, Man, and Cybernetics, Vol. 23, No. 3, pp. 665-685, May 1993.

See Also

Was this topic helpful?