Matlab Implementation of Fuzzy Neural Networks
In recent years, fuzzy neural networks have been widely used in various fields, such as pattern recognition, image processing, and control system design. In this article, we introduce the Matlab implementation of fuzzy neural networks, which is a powerful tool for building models that can handle uncertain, imprecise, and incomplete data. We first give an overview of fuzzy neural networks, then present the basic steps for building a fuzzy neural network in Matlab, and finally illustrate the use of fuzzy neural networks with an example.
Overview of Fuzzy Neural Networks
Fuzzy neural networks are a type of artificial neural network that combines the learning capabilities of neural networks with the fuzzy reasoning capabilities of fuzzy logic. Fuzzy neural networks can handle uncertain and incomplete data by representing input and output values as fuzzy sets, and using fuzzy rules to infer output values from input values. The architecture of fuzzy neural networks consists of three layers: the input layer, the fuzzy layer, and the output layer.
The input layer receives the input values and passes them on to the fuzzy layer, which applies a set of fuzzy membership functions to transform the input values into fuzzy sets. The fuzzy layer then generates a set of fuzzy rules that describe the relationship between the input fuzzy sets and the output fuzzy sets. The output layer applies a set of fuzzy inference rules to combine the input fuzzy sets and generate the output fuzzy sets.
Building a Fuzzy Neural Network in Matlab
The basic steps for building a fuzzy neural network in Matlab are as follows:
- Create an instance of a fuzzy system object using the
fuzzy
function. - Add input and output variables to the fuzzy system object using the
addInput
andaddOutput
methods. - Add membership functions to the input and output variables using the
addMF
method. - Create fuzzy rules using the
addrule
method. - Train the fuzzy neural network using the
anfis
function. - Evaluate the performance of the fuzzy neural network using the
evalfis
method.
Example: Prediction of Sine Function
To illustrate the use of fuzzy neural networks, we consider the problem of predicting the sine function. We generate a set of input-output pairs by taking the sine of a set of input values, and adding some random noise. We then use these input-output pairs to train a fuzzy neural network, and evaluate its performance by comparing its predicted output with the actual output.
The Matlab code for generating the input-output pairs is:
```matlab % Generate input-output pairs x = linspace(0,pi,100); y = sin(x) + 0.1*randn(size(x)); ```The Matlab code for building and training the fuzzy neural network is:
```matlab % Build fuzzy system object fis = fuzzy; % Add input and output variables fis = addInput(fis,[0 pi],'Name','input'); fis = addOutput(fis,[-1 1],'Name','output'); % Add membership functions fis = addMF(fis,'input','gbellmf',[0.5 1 0],'Name','mf1'); fis = addMF(fis,'input','gbellmf',[0.5 1 pi/2],'Name','mf2'); fis = addMF(fis,'input','gbellmf',[0.5 1 pi],'Name','mf3'); fis = addMF(fis,'output','linear',[1 0],'Name','mf4'); % Add fuzzy rules fis = addrule(fis,[1 0 0 1]); fis = addrule(fis,[0 1 0 2]); fis = addrule(fis,[0 0 1 3]); % Train fuzzy neural network anfis_data = [x' y]; opt = anfisOptions('InitialFis',fis,'EpochNumber',100,'ValidationData',anfis_data); fis_anfis = anfis(anfis_data,opt); % Evaluate fuzzy neural network y_pred = evalfis(x,fis_anfis); ```The Matlab code for plotting the predicted and actual output is:
```matlab % Plot results figure; plot(x,y,'b',x,y_pred,'r--'); legend('Actual Output','Predicted Output'); xlabel('Input'); ylabel('Output'); ```The resulting plot shows that the fuzzy neural network is able to predict the sine function accurately, even in the presence of noise: