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

SystemInputOutputRule

(trimf)
(trapmf)(gbellmf)(gaussmf)
2(gauss2mf)sigmfdsigmfpsigmf
pimfsmfzmf

(Rule) ifthen

Trimf

Trapmf

Gbellmf

Sigmf

Dsigmf

Psigmf

Pimf

Smf

Zmf

Gaussmf
Gauss2mf

(RULE)

1.
2.

1.
2.

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)

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


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

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

MATLABM-file

SYSTEM
[System]
%[]System,Inputs,OutputsRules
Name='tipper1';
%tipper1.fis
Type='mamdani';
NumInputs=2;
NumOutputs=1;
NumRules=3;
AndMethod='min';

%Mamdani style
%
%
%
%

OrMethod='max';
ImpMethod='min';
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.fisMATLAB
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 windowfuzzy

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 windowanfisedit

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