fuzzyanfis
TRANSCRIPT
FUZZY & ANFISUse 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
Trapmf
Gbellmf
Gaussmf
Gauss2mf
Sigmf
Dsigmf
Psigmf
Pimf
Smf
Zmf
模糊規則 (RULE) 語意表示法:1. if (x is A) and (y is B) then (z is α)(1)2. if (x is A) or (y is C) then (z is β)(1)
符號表示法:1. (x == A) & (y == B) => (z == α)(1)2. (x ==A) | (y == C) => (z == β)(1)
指標表示法:1. 1 2, 1(1):1 假設有輸入有 ABC 三個歸屬函
數2. 1 3, 2(1):2 輸出有 α β 兩個歸屬函數
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'; %Mamdani style
NumInputs=2; % 有兩個輸入變數NumOutputs=1; % 有一個輸出變數NumRules=3; % 有三條規則AndMethod='min'; % 定義推論過程中所用之運算子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.dattime = 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)];
endtrnData=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.datload fuzex2trnData.datload fuzex1chkData.datload fuzex2chkData.dat
從 WORKSPACE 讀入資料
初始化並產生 FIS
瀏覽 FIS 結構
訓練 ANFIS
對訓練好的 ANFIS 進行測試
Thanks!!