Main Content

Train Adaptive Neuro-Fuzzy Inference Systems

This example shows how to create, train, and test Sugeno-type fuzzy systems using the Neuro-Fuzzy Designer app. For more information on:

Add the example data files to the MATLAB® path.


Load Training Data

Training and validating systems using the Neuro-Fuzzy Designer app requires data. Import the training data (fuzex1trnData) and validation data (fuzex1chkData) to the MATLAB workspace.

load fuzex1trnData.dat
load fuzex1chkData.dat

Open the Neuro-Fuzzy Designer app.


Default Neuro-Fuzzy Designer app dialog with an empty plot and a load data section in the bottom left corner.

Load the training data set from the workspace. In the Load data section, select Training and worksp.

Click Load Data. In the Load from workspace dialog box, enter the variable name fuzex1trnData.

Load from workspace dialog box with fuzex1trdData entered as the input variable name

Click OK. Neuro-Fuzzy Designer displays the training data in the plot as a set of circles.

Neuro-Fuzzy Designer app showing a plot of the imported training data

Load the checking data from the MATLAB workspace into Neuro-Fuzzy Designer. In the Load data section, select Checking.

Load the checking data in the same manner as the training data, specifying the variable name fuzex1chkData. Neuro-Fuzzy Designer displays the checking data using plus signs superimposed on the training data.

Neuro-Fuzzy Designer app showing a plot with the imported checking data together with the training data

To clear a specific data set from the app, in the Load data area, select the data Type, and click Clear Data.

Generate or Load FIS Structure

Before you start the FIS training, you must specify an initial FIS model structure. To specify the model structure, you perform one of the following tasks:

  • Load a previously saved single-output Sugeno-type FIS object from a file or the MATLAB workspace.

  • Generate the initial FIS model using grid partitioning.

  • Generate the initial FIS model using subtractive clustering.

For this example, generate the initial FIS using grid partitioning. In Neuro-Fuzzy Designer, in the Generate FIS section, select Grid partition.

Click Generate FIS.

In the Add Membership Functions dialog box:

  • In the Input section, in Number of MFs, specify the number of input membership functions. For this example, use 4 membership functions for all input variables.

  • In MF Type, select gbellmf as the input membership function type.

  • In the Output section, in MF Type, select linear as the output membership function type.

Add membership functions dialog box showing the selected number and type of input membership functions and the selected output membership function type.

Interactively Specify FIS Structure

Alternatively, you can interactively specify your own FIS structure with specified membership functions and rules. The system you define must be a Sugeno system with the following properties:

  • Single output

  • Weighted average defuzzification

  • First or zeroth order system; that is, all output membership functions must be the same type, either 'linear' or 'constant'.

  • No rule sharing. Different rules cannot use the same output membership function; that is, the number of output membership functions must equal the number of rules.

  • Unity weight for each rule.

  • No custom membership functions or defuzzification methods.

To define the:

  • Membership functions for each variable, in Neuro-Fuzzy Designer, select Edit > Membership Functions. Then, in the Membership Function Editor window, define the membership functions.

  • Rules, in Neuro-Fuzzy Designer, select Edit > Rules. Then, in the Rule Editor window, define the rules.

These tools are the same as those used by the Fuzzy Logic Designer app. For more information, see Build Fuzzy Systems Using Fuzzy Logic Designer.

View FIS Structure

After you load or generate the FIS, you can view the model structure. To do so, in Neuro-Fuzzy Designer, click Structure.

Dialog box showing the structure of the ANFIS model

The branches in this graph are color coded. Color coding of branches characterize the rules and indicate whether or not AND, NOT, or OR are used in the rules. The input is represented by the left-most node and the output by the right-most node. The node represents a normalization factor for the rules. To view information about the structure, click on each node.

Also, to view the FIS:

  • Membership functions, in Neuro-Fuzzy Designer, select Edit > Membership Functions.

  • Rules, in Neuro-Fuzzy Designer, select Edit > Rules.

Train FIS

After loading the training data and generating the initial FIS structure, you can train your FIS. To do so, in Neuro-Fuzzy Designer, in the Train FIS section, specify the following parameters.

  • Optim. Method — Optimization method. For this example, select the hybrid method, which uses a combination of backpropagation and least-squares regression to tune the FIS parameters.

  • Epochs — Number of training epochs. For this example, specify 40 epochs.

  • Error Tolerance — Error tolerance stopping condition. For this example, specify a value of 0, which indicates that the training will stop when the number of training epochs is reached.

To train the FIS, click Train Now.

Neuro-Fuzzy Designer app showing a plot of the training error and testing error for the entire training session.

The app trains the FIS and plots the training error (as stars) and checking error (as dots) for each training epoch.

The checking error decreases up to a certain point in the training, and then it increases. This increase occurs at the point where the training starts overfitting the training data. The app selects the FIS associated with this overfitting point as the trained ANFIS model.

Validate Trained FIS

After the FIS is trained, validate the model using a Testing or Checking data set that differs from the training data. For this example, use the previously loaded checking data.

To test your FIS against the checking data, in the Test FIS section, select Checking data. Then, click Test Now.

Neuro-Fuzzy Designer app showing the checking output data together with the output generated by the ANFIS system for the checking input data

The app plots the output values of the testing data set (using blue +'s) and the output of the trained FIS for the corresponding testing data input values (using red *'s). The FIS output values correlate well with the expected output.

Importance of Checking Data

It is important to have checking data that fully represents the features of the data the FIS is intended to model. If your checking data is significantly different from your training data and does not cover the same data features to model as the training data, then the training results will be poor.

For example, load new training and checking data into Neuro-Fuzzy Designer. This data has significantly different training and checking sets.

  1. At the MATLAB command line, load the training and checking data.

    load fuzex2trnData.dat
    load fuzex2chkData.dat

  2. Clear the previously loaded training and checking data. In the Load data section, select each data type, click Clear Data.

  3. Load the training data (fuzex2trnData) and checking data (fuzex2chkData), as you did previously.

Neuro-Fuzzy Designer app showing training and checking data that is not well-correlated

Generate a FIS structure and train the FIS as you did previously, except now select 60 training epochs.

Neuro-Fuzzy Designer app showing large checking error

In this case, the checking error is large, with the minimum occurring in the first epoch. Since the app chooses the trained FIS parameters associated with the minimum checking error, the trained FIS does not sufficiently capture the features of this data set. It is important to know the features of your data set well when you select your training and checking data. When you do not know the features of your data, you can analyze the checking error plots to see whether or not the checking data performed sufficiently well with the trained model.

In this example, the checking error is sufficiently large to indicate that either you need to select more data for training or modify your membership function choices (both the number of membership functions and the type). Otherwise, if you think the training data sufficiently captures the features you are trying to represent, the system can be retrained without the checking data.

To verify the poor training results, test the trained FIS model against the checking data.

Neuro-Fuzzy Designer app showing that the output of the fuzzy system for the checking data does not match the expected output.

As expected, there are significant differences between the checking data output values and the FIS output.

Remove the example data files from the MATLAB path.


See Also

Related Topics