Main Content

Save Training Error Data to MATLAB Workspace

When using Neuro-Fuzzy Designer, you can export your initial FIS structure to the MATLAB® workspace and then generate ANFIS training error values. Since exporting the training and validation error profiles from the Neuro-Fuzzy Designer app is not supported, use this method to generate such error plots.

The following example shows how to save the training error generated during ANFIS training to the MATLAB workspace.

  1. Load your training data (fuzex1trnData) and validation data (fuzex1chkData) to the MATLAB workspace.

    load fuzex1trnData.dat
    load fuzex1chkData.dat
    
  2. Open the Neuro-Fuzzy Designer app.

    neuroFuzzyDesigner

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

  3. Load the training data from the MATLAB workspace into Neuro-Fuzzy Designer.

    1. In the Load data section, select Training.

    2. Select worksp.

    3. 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

    4. 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

  4. 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

  5. Generate an initial FIS.

    1. In the Generate FIS section, select Grid partition.

    2. Click Generate FIS.

    3. 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 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.

    4. Click OK.

  6. Export the initial FIS to the MATLAB workspace.

    1. In Neuro-Fuzzy Designer, select File > Export > To Workspace.

      This action opens a dialog box where you specify the MATLAB variable name.

    2. In the Export To Workspace dialog box, in the Workspace variable field, enter initfis as the variable name.

      Dialog box with a field for entering the MATLAB workspace variable name

    3. Click OK. The app exports the FIS object to the MATLAB workspace.

  7. Train the FIS for 40 epochs. Instead of using a single call to the anfis function, call the function inside a loop using 2 epochs for each call. This training method replicates the training process used by the Neuro-Fuzzy Designer app.

    At each training epoch, save the training and validation errors.

    fis = initfis;
    opt = anfisOptions('EpochNumber',2,'ValidationData',fuzex1chkData);
    trainError = zeros(1,40);
    checkError = zeros(1,40);
    for ct = 1:40
        opt.InitialFIS = fis;
        [fis,error,~,~,chkError] = anfis(fuzex1trnData,opt);
        trainError(ct) = error(1);
        checkError(ct) = chkError(1);
    end
    
  8. Plot the training and validation errors over the training process. These error values are the root mean squared errors at each training epoch.

    epochNum = 1:40;
    plot(epochNum,trainError,'b*',epochNum,checkError,'ro')
    xlabel('Epoch Number')
    ylabel('Error')
    legend('Training Error','Validation Error')

    Training error decreases from 0.24 to 0.15 over 40 training epochs. Validation error decreases in a similar fashion, increasing slightly in the final five epochs.

    These error profiles are similar to the error profiles when the same initial FIS structure is trained in the Neuro-Fuzzy Designer app.

See Also

Related Topics