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:
Load Training Data
Training and validating systems using the Neuro-Fuzzy Designer app
requires data. Import the training data (
validation data (
fuzex1chkData) to the MATLAB® workspace.
load fuzex1trnData.dat load fuzex1chkData.dat
Open the Neuro-Fuzzy Designer app.
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
Click OK. Neuro-Fuzzy Designer displays the training data in the plot as a set of circles.
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
fuzex1chkData. Neuro-Fuzzy Designer
displays the checking data using plus signs superimposed on the training
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
4membership functions for all input variables.
In MF Type, select
gbellmfas the input membership function type.
In the Output section, in MF Type, select
linearas the 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:
Weighted average defuzzification
First or zeroth order system; that is, all output membership functions must be the same type, either
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.
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.
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
hybridmethod, which uses a combination of backpropagation and least-squares regression to tune the FIS parameters.
Epochs — Number of training epochs. For this example, specify
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.
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.
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.
At the MATLAB command line, load the training and checking data.
load fuzex2trnData.dat load fuzex2chkData.dat
Clear the previously loaded training and checking data. In the Load data section, select each data type, click Clear Data.
Load the training data (
fuzex2trnData) and checking data (
fuzex2chkData), as you did previously.
Generate a FIS structure and train the FIS as you did previously, except now
60 training epochs.
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.
As expected, there are significant differences between the checking data output values and the FIS output.