F & ANFIS UZZY Use MATLAB
Download
Report
Transcript F & ANFIS UZZY Use MATLAB
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):由 if……then…… 組成。
歸屬函數種類
Trimf
Sigmf
Trapmf
Dsigmf
Psigmf
Pimf
Smf
Zmf
Gbellmf
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
開啟MATLAB並新增一個M-file
SYSTEM
[System]
%用中括弧[]包住四大區域,即System,Inputs,Outputs及Rules。
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.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!!