Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

anfis

Tune Sugeno-type fuzzy inference system using training data

Syntax

fis = anfis(trainingData)
fis = anfis(trainingData,options)
[fis,trainError] = anfis(___)
[fis,trainError,stepSize] = anfis(___)
[fis,trainError,stepSize,chkFIS,chkError] = anfis(trainingData,options)

Description

example

fis = anfis(trainingData) generates a single-output Sugeno fuzzy inference system (FIS) and tunes the system parameters using the specified input/output training data. The FIS structure is automatically generated using grid partitioning.

The training algorithm uses a combination of the least-squares and backpropagation gradient descent methods to model the training data set.

example

fis = anfis(trainingData,options) tunes an FIS using the specified training data and options. Using this syntax, you can specify:

  • An initial FIS structure to tune.

  • Validation data for preventing overfitting to training data.

  • Training algorithm options.

  • Whether to display training progress information.

example

[fis,trainError] = anfis(___) returns the root mean square training error for each training epoch.

example

[fis,trainError,stepSize] = anfis(___) returns the training step size at each training epoch.

example

[fis,trainError,stepSize,chkFIS,chkError] = anfis(trainingData,options) returns the validation data error for each training epoch, chkError, and the tuned FIS structure for which the validation error is minimum, chkFIS. To use this syntax, you must specify validation data using options.ValidationData.

Examples

collapse all

Load training data. This data has a single input and a single output.

load fuzex1trnData.dat

Generate and train a fuzzy inference system. By default, the FIS structure is created using a grid partition of the input variable range with two membership functions.

fis = anfis(fuzex1trnData);
ANFIS info: 
	Number of nodes: 12
	Number of linear parameters: 4
	Number of nonlinear parameters: 6
	Total number of parameters: 10
	Number of training data pairs: 25
	Number of checking data pairs: 0
	Number of fuzzy rules: 2


Start training ANFIS ...

   1 	 0.229709
   2 	 0.22896
   3 	 0.228265
   4 	 0.227624
   5 	 0.227036
Step size increases to 0.011000 after epoch 5.
   6 	 0.2265
   7 	 0.225968
   8 	 0.225488
   9 	 0.225052
Step size increases to 0.012100 after epoch 9.
  10 	 0.22465

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

Minimal training RMSE = 0.224650

Plot the ANFIS output and training data.

x = fuzex1trnData(:,1);
anfisOutput = evalfis(x,fis);
plot(x,fuzex1trnData(:,2),'*r',x,anfisOutput,'.b')
legend('Training Data','ANFIS Output','Location','NorthWest')

The ANFIS data does not match the training data well. To improve the match:

  • Increase the number of membership functions in the FIS structure to 4. Doing so adds fuzzy rules and tunable parameters to the system.

  • Increase the number of training epochs.

opt = anfisOptions('InitialFIS',4,'EpochNumber',40);

Suppress the error and step size Command Window display.

opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;

Train the FIS.

fis = anfis(fuzex1trnData,opt);
ANFIS info: 
	Number of nodes: 20
	Number of linear parameters: 8
	Number of nonlinear parameters: 12
	Total number of parameters: 20
	Number of training data pairs: 25
	Number of checking data pairs: 0
	Number of fuzzy rules: 4

Minimal training RMSE = 0.083385

Plot the ANFIS output and training data.

figure
anfisOutput = evalfis(x,fis);
plot(x,fuzex1trnData(:,2),'*r',x,anfisOutput,'.b')
legend('Training Data','ANFIS Output','Location','NorthWest')

The match between the training data and ANFIS output has improved.

Create single-input, single-output training data.

x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);

Define an initial FIS structure with five Gaussian input membership functions.

genOpt = genfisOptions('GridPartition');
genOpt.NumMembershipFunctions = 5;
genOpt.InputMembershipFunctionType = 'gaussmf';
inFIS = genfis(x,y,genOpt);

Configure the ANFIS training options. Set the initial FIS, and suppress the training progress display.

opt = anfisOptions('InitialFIS',inFIS);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;

Train the FIS using the specified options.

outFIS = anfis([x y],opt);

Compare the ANFIS output with the training data.

plot(x,y,x,evalfis(x,outFIS))
legend('Training Data','ANFIS Output')

Load training data. This data has a single input and a single output.

load fuzex2trnData.dat

Specify the training options.

opt = anfisOptions('InitialFIS',4,'EpochNumber',40);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;

Train the FIS, and return the training error.

[fis,trainError] = anfis(fuzex2trnData,opt);

trainError contains the root mean square error for the training data at each training epoch. The training error for fis is the minimum value in trainError.

fisRMSE = min(trainError)
fisRMSE = 0.2572

Create single-input, single-output training data.

x = (0:0.1:10)';
y = sin(2*x)./exp(x/5);

Configure the ANFIS training options. Set the initial FIS, and suppress the training progress display.

opt = anfisOptions('InitialFIS',4,'EpochNumber',60);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;

A larger step size increase rate can make the training converge faster. However, increasing the step size increase rate too much can lead to poor convergence. For this example, try doubling the step size increase rate.

opt.StepSizeIncreaseRate = 2*opt.StepSizeIncreaseRate;

Train the FIS, and return the step size array.

[fis,~,stepSize] = anfis([x y],opt);

Plot the step size profile. An optimal step size profile should increase initially, reach a maximum, and then decrease for the rest of the training.

figure
plot(stepSize)

Load training data.

load fuzex1trnData.dat

Load validation data.

load fuzex1chkData.dat

Specify the following training options:

  • 4 input membership functions

  • 30 training epochs

  • Suppress training progress display

opt = anfisOptions('InitialFIS',4,'EpochNumber',30);
opt.DisplayANFISInformation = 0;
opt.DisplayErrorValues = 0;
opt.DisplayStepSize = 0;
opt.DisplayFinalResults = 0;

Add the validation data to the training options.

opt.ValidationData = fuzex1chkData;

Train the FIS, and return the validation results.

[fis,trainError,stepSize,chkFIS,chkError] = anfis(fuzex1trnData,opt);

The training error, trainError, and validation error, chkError, arrays each contain one error value per training epoch. Plot the training error and the validation error.

x = [1:30];
plot(x,trainError,'.b',x,chkError,'*r')

The minimum validation error occurs at epoch 17. The increase in validation error after this point indicates overfitting of the model parameters to the training data. Therefore, the tuned FIS at epoch 17, chkFIS, exhibits the best generalization performance.

Input Arguments

collapse all

Training data, specified as an array. For a fuzzy system with N inputs, specify trainingData as an array with N+1 columns. The first N columns contain input data, and the final column contains output data. Each row of trainingData contains one data point.

Generally, training data should fully represent the features of the data the FIS is intended to model.

Training options, specified as an anfisOptions option set. Using options, you can specify:

  • An initial FIS structure to tune, options.InitialFIS.

  • Validation data for preventing overfitting to training data, options.ValidationData.

  • Training algorithm options, such as the maximum number of training epochs, options.EpochNumber, or the training error goal, options.ErrorGoal.

  • Whether to display training progress information, such as the training error values for each training epoch, options.DisplayErrorValues.

Output Arguments

collapse all

Trained fuzzy inference system with membership function parameters tuned using the training data, returned as an FIS structure. This fuzzy system corresponds to the epoch for which the training error is smallest. If two epochs have the same minimum training error, the FIS from the earlier epoch is returned.

Root mean square training error for each training epoch, returned as an array. The minimum value in trainError is the training error for fuzzy system fis.

Training step size for each epoch, returned as an array. The anfis training algorithm tunes the FIS parameters using gradient descent optimization methods. The training step size is the magnitude of the gradient transitions in the parameter space.

Ideally, the step size increases at the start of training, reaches a maximum, and then decreases for the remainder of the training. To achieve this step size profile, adjust the initial step size (options.InitialStepSize), step size increase rate (options.StepSizeIncreaseRate), and step size decrease rate options.StepSizeDecreaseRate.

Tuned FIS for which the validation error is minimum, returned as an FIS structure. If two epochs have the same minimum validation error, the FIS from the earlier epoch is returned.

chkFIS is returned only when you specify validation data using options.ValidationData.

Root mean square training error, returned as an array with length equal to the number of training epochs. The minimum value in chkError is the training error for fuzzy system chkFIS.

chkError is returned only when you specify validation data using options.ValidationData.

References

[1] 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). July 1991, pp. 762-767.

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

Introduced before R2006a

Was this topic helpful?