You are on page 1of 58

FUZZY & ANFIS

Use MATLAB

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

FUZZY LOGIC TOOLBOX


XXX.fis System Input Output Rule

(trimf) (trapmf) (gbellmf) (gaussmf) 2(gauss2mf) sigmf dsigmf psigmf pimf smf zmf (Rule) ifthen

Trimf Trapmf Gbellmf Gaussmf Gauss2mf

Sigmf Dsigmf Psigmf Pimf Smf Zmf

(RULE)

1. 2.

if (x is A) and (y is B) then (z is )(1) if (x is A) or (y is C) then (z is )(1)


1. 2.

(x == A) & (y == B) => (z == )(1) (x ==A) | (y == C) => (z == )(1)


1. 2.

1 2, 1(1):1 1 3, 2(1):2

ABC

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

EXAMPLE:TIPPER

MATLAB

M-file

SYSTEM
[System] % [] Name='tipper1'; Type='mamdani'; NumInputs=2; NumOutputs=1; NumRules=3; AndMethod='min'; OrMethod='max'; ImpMethod='min'; System,Inputs,Outputs Rules % tipper1.fis %Mamdani style % % % %

AggMethod='max'; DefuzzMethod='centroid';

INPUT1
[Input1] Name='service'; Range=[0 10]; NumMFs=3; MF1='poor':'gaussmf',[1.5 0]; MF2='good':'gaussmf',[1.5 5]; MF3='excellent':'gaussmf',[1.5 10]; % % % % % % %

INPUT1

INPUT2
[Input2] Name='food'; %

Range=[0 10]; NumMFs=2; MF1='rancid':'trapmf',[0 0 1 3]; MF2='delicious':'trapmf',[7 9 10 10];

INPUT2

OUTPUT1
[Output1]; Name='tip'; %

Range=[0 30]; NumMFs=3; MF1='cheap':'trimf',[0 5 10]; MF2='average':'trimf',[10 15 20]; MF3='generous':'trimf',[20 25 30];

OUTPUT1

RULES

If (service is poor) or (food is rancid) then (tip is cheap) (1) If (service is good) then (tip is average) (1) If (service is excellent) or (food is delicious) then (tip is generous) (1)

RULES
[Rules] 1 1, 1 (1) : 2; 2 0, 2 (1) : 2; 3 2, 3 (1) : 2; %

tipper1.fis

tipper1.fis MATLAB tipper=readfis('tipper1');


tipper evalfis([5 5],tipper) ans= 15.0000


evalfis([5 5;10 3;2 9],tipper) % ans = 15.0000 24.9220 16.8196

plotmf(tipper,'input',1)

showrule(tipper) showrule(tipper,[1 3],'symbolic')


% %

surfview(tipper)

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

FUZZY LOGIC TOOLBOX GUI


MATLAB command window

fuzzy

INPUT/OUTPUT

SERVICE

FOOD

TIP

TIPPER

TIPPER

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

DEMO
load mgdata.dat time = mgdata(:, 1); x = mgdata(:, 2); for t=118:1117, Data(t-117,:)=[x(t-18) x(t-12) x(t-6) x(t) x(t+6)]; end trnData=Data(1:500, :); chkData=Data(501:end, :);

MGDATA

FIS
fismat = genfis1(trnData); %fismat=genfis1(inputData,2,'gauss2mf','constant');

ANFIS
[fismat1,error1,ss,fismat2,error2] = anfis(trnData,fismat,[],[],chkData);

ANFIS
anfis_output = evalfis([trnData(:,1:4); chkData(:,1:4)],fismat2); index = 125:1124; subplot(211), plot(time(index), [x(index) anfis_output]); xlabel('Time (sec)'); title('MG Time Series and ANFIS Prediction'); subplot(212), plot(time(index), x(index) - anfis_output); xlabel('Time (sec)'); title('Prediction Errors');

OUTLINE

Fuzzy logic toolbox Fuzzy: use command line Fuzzy: use GUI ANFIS: use command line ANFIS: use GUI

ANFIS EDIT GUI


MATLAB command window

anfisedit

DEMO
MATLAB command window load fuzex1trnData.dat load fuzex2trnData.dat load fuzex1chkData.dat load fuzex2chkData.dat

WORKSPACE

FIS

FIS

ANFIS

ANFIS

Thanks!!

You might also like