You are on page 1of 32

ANFIS

(Adaptive Neuro-Fuzzy Inference System)

Fuzzy system

Knowledge base Input Fuzzification Output

Inference

Defuzzification

Fuzzy system Sugeno type


Parameterized nonlinear map
f FS (x) =

y (
l l =1 m

(
l =1 i =1
m

i =1 n

Ail

( xi ))

x = [ x1 , x2 , , xn ]

Ail

( xi ))

which can be written as


f FS (x) = wi bi (x)
i =1

where

b j ( x) =

i =1 m

Ail

( xi )

n ( x ) l Ai i l =1 i =1

wi = y i

Fuzzy system
Parameterized nonlinear map If F is a real continuous map on a compact set (e.g. closed interval), then there exists a fuzzy system f which can approximate F to any desired accuracy, i.e.

F f FS

Approximation theory results


Theorem 1.
Let F be a bounded function on [ a, b ] and E = { x1 , , xk } a set of points in [ a, b ] . Then there exists the least squares k p polynomial of degree n , n ,which minimizes

F ( x ) p( x )
i =1 i i

over all polynomials of degree

n.

Approximation theory results


Theorem 2. If F C [ a, b] , then for any
approximating polynomial n of degree n such that
n 0 , there exists a best

F n

Fp

over all polynomials p of degree n .

Approximation theory results


Theorem 3. Stone-Weierstrass If F C [ a, b] , then there exists a sequence of polynomials
Pn such that

lim Pn ( x) = F ( x)
n

uniformly on [ a, b ] .

REMARK The message of Theorem 2 is that polynomials are dense in the space of continuous functions in Hilbert space. The same can also be said of trigonometric functions.

ANFIS STRUCTURE - Example


1. If x is A1 and y is B1, then f1=p1x+q1y+r1 2. If x is A2 and y is B2, then f2=p2x+q2y+r2

Let the membership functions of fuzzy sets Ai, Bi, i=1,2, be A , . B


i i

Evaluating the rules


1. Evaluating the rule premises (T-norm: product) results in
wi = A ( x) B ( y ), i = 1, 2
i i

2. Evaluating the implication:


Rule 1: A ( x) B ( y ) f1 ( x, y ) = w1 ( x, y ) f1 ( x, y )
1 1

Rule 2:

A ( x) B ( y ) f 2 ( x, y ) = w2 ( x, y ) f 2 ( x, y )
2 2

Evaluating the rules


3. Evaluating the rule consequences and aggregating
w1 ( x, y ) f1 ( x, y ) + w2 ( x, y ) f 2 ( x, y ) f ( x, y ) = . w1 ( x, y ) + w2 ( x, y )
or
f = w1 f1 + w2 f 2 . w1 + w2

Evaluating the rules


4. Separate computation into two phases with notation

wi wi = w1 + w2
5. Then

f = w1 f1 + .w2 f 2

Neural network of fuzzy rule base


A1 ( x )
x

w1 ( x, y)

A2 ( x )

w1 =

w1 w1 + w2

f1 ( x, y)

w1 f1

f ( x, y)

B ( y)
1

f 2 ( x, y)

w2 f 2

B ( y)
2

w2 =

w2 ( x, y )

w2 w1 + w2

I n it ia l iz e th e fu z z y s y s te m

ANFIS procedure

U s e g e n fi s 1 o r g e n fi s2 c o m m a n d s

G iv e o t h e r p a r a m e t e r s f o r l e a r n i n g
I m p o rta n t a r e : N u m b e r o f i te r a ti o n s ( e p o c h s ) T o ler a n c e ( er r o r)

S t a r t l e a r n in g p r o c e s s
U s e c o m m a n d a n f is S t o p w h e n t o le r a n c e is a c h ie v e d .

V a l id a te W i th in d e p e n d e n t d a ta

EXERCISE 1.
Let y = f(x) = -2x - x2. a) Form a fuzzy system, which approximates function f, for x [ 10,10]. Repeat the same by adding random, normally distributed noise with zero mean and unit variance. b) Simulate the output when the input is sin(t). Observe what happens to the signal shape at the output.

Solution Generate input-output data


x=[-10:.5:10]'; y=-2*x-x.*x; plot(x,y)

Store data for genfis1 and anfis and plot it


data=[x y]; trndata=data(1:2:size(x),:); chkdata=data(2:2:size(x),:); plot(trndata(:,1),trndata(:,2),'o',chkdata(:,1),chkdata(:,2),'x')

Initialize the fuzzy system


Command genfis1.
GENFIS1 Generates an initial Sugeno-type FIS for ANFIS training using a grid partition. FIS = GENFIS1(DATA, NUMMFS, INPUTMF, OUTPUTMF) explicitly specifies: * NUMMFS number of membership functions per input. A scalar value, specifies the same number for all inputs and a vector value specifies the number for each input individually. * INPUTMF type of membership function for each input. A single string specifies the same type for all inputs, a string array specifies the type for each input individually. * OUTPUTMF output membership function type, either 'linear' or 'constant'

Initialize the fuzzy system


Command genfis1. Use 5 bellshaped membership functions nu=5; mftype='gbellmf'; fismat=genfis1(trndata, nu, mftype);

Iterate to find the best fuzzy system


Use anfis-command
[FIS,ERROR,STEPSIZE] = ANFIS(TRNDATA,INITFIS,TRNOPT,DISPOPT,[],OPTMETHOD) uses the vector TRNOPT to specify training options: TRNOPT(1): training epoch number (default: 10) TRNOPT(2): training error goal (default: 0) TRNOPT(3): initial step size (default: 0.01) TRNOPT(4): step size decrease rate (default: 0.9) TRNOPT(5): step size increase rate (default: 1.1) OPTMETHOD selects the optimization method used in training. Select 1 to use the default hybrid method, which combines least squares estimation with backpropagation. Select 0 to use the backpropagation method.

Iterate to find the best fuzzy system


Use anfis-command Max number of iterations or epochs = 100 numep=100; [parab,trnerr,ss,parabcheck,chkerr]=anfis(trndata,fismat, numep,[],chkdata);

Evaluate the output of FIS system using input x


Use evalfis-command
Y = EVALFIS(U,FIS) simulates the Fuzzy Inference System FIS for the input data U and returns the output data Y. For a system with N input variables and L output variables, * U is a M-by-N matrix, each row being a particular input vector * Y is M-by-L matrix, each row being a particular output vector.

Evaluate the output of FIS system using input x


Use evalfis-command
anfi=evalfis(x,parab); plot(trndata(:,1),trndata(:,2),'o',chkdata(:,1),chkdata(:,2),'x', x,anfi,'-') grid xlabel('x');ylabel('output');title('Goodness of fit')

Same using GUI of Fuzzy TB


In MATLAB Type fuzzy Choose from File menu New Sugeno

Generate anfis display

Generate anfis display

Load training data

Load training data

Generate initial FIS matrix using Grid partition

Default membership function type (gaussmf) and their number (4).

Training when error tolerance is chosen to be 0.001 and number of epochs is limited to 100.

Testing the fuzzy system.

You might also like