fuzzyanfis
TRANSCRIPT
![Page 1: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/1.jpg)
FUZZY & ANFISUse MATLAB
![Page 2: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/2.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 3: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/3.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 4: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/4.jpg)
FUZZY LOGIC TOOLBOX
附檔名: XXX.fis
包含 System 、 Input 、 Output 及 Rule 四個部分
歸屬函數種類:常用包含三角形 (trimf) 、梯形(trapmf) 、通用鐘形 (gbellmf) 、高斯 (gaussmf) 、高斯 2(gauss2mf) ,不常用包含 sigmf 、 dsigmf 、psigmf 、 pimf 、 smf 、 zmf 等。
模糊規則 (Rule) :由 if……then…… 組成。
![Page 5: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/5.jpg)
歸屬函數種類 Trimf
Trapmf
Gbellmf
Gaussmf
Gauss2mf
Sigmf
Dsigmf
Psigmf
Pimf
Smf
Zmf
![Page 6: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/6.jpg)
模糊規則 (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 輸出有 α β 兩個歸屬函數
![Page 7: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/7.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 8: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/8.jpg)
EXAMPLE:TIPPER
![Page 9: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/9.jpg)
開啟 MATLAB 並新增一個 M-file
![Page 10: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/10.jpg)
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';
![Page 11: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/11.jpg)
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]; % 第三歸屬函數定義
![Page 12: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/12.jpg)
INPUT1
![Page 13: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/13.jpg)
INPUT2
[Input2] % 定義第二輸入變數Name='food';
Range=[0 10];
NumMFs=2;
MF1='rancid':'trapmf',[0 0 1 3];
MF2='delicious':'trapmf',[7 9 10 10];
![Page 14: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/14.jpg)
INPUT2
![Page 15: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/15.jpg)
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];
![Page 16: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/16.jpg)
OUTPUT1
![Page 17: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/17.jpg)
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)
![Page 18: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/18.jpg)
RULES
[Rules] % 定義三條規則,用指標方式定義
1 1, 1 (1) : 2;2 0, 2 (1) : 2;3 2, 3 (1) : 2;
![Page 19: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/19.jpg)
儲存成 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
![Page 20: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/20.jpg)
其他指令 畫出歸屬函數:plotmf(tipper,'input',1)
顯示模糊規則:showrule(tipper) % 語意表
示法showrule(tipper,[1 3],'symbolic') %
符號表示法
畫出輸入輸出對照圖:surfview(tipper)
![Page 21: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/21.jpg)
輸入輸出對照圖
![Page 22: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/22.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 23: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/23.jpg)
開啟 FUZZY LOGIC TOOLBOX GUI
在 MATLAB command window 輸入 fuzzy
![Page 24: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/24.jpg)
![Page 25: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/25.jpg)
增加 INPUT/OUTPUT
![Page 26: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/26.jpg)
更改變數名稱
![Page 27: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/27.jpg)
設定歸屬函數
![Page 28: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/28.jpg)
設定範圍與名稱
![Page 29: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/29.jpg)
設定歸屬函數種類
![Page 30: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/30.jpg)
設定歸屬函數分布
![Page 31: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/31.jpg)
增加 / 減少歸屬函數
![Page 32: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/32.jpg)
SERVICE
![Page 33: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/33.jpg)
FOOD
![Page 34: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/34.jpg)
TIP
![Page 35: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/35.jpg)
設定模糊規則
![Page 36: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/36.jpg)
設定模糊規則
![Page 37: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/37.jpg)
測試 TIPPER
![Page 38: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/38.jpg)
測試 TIPPER
![Page 39: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/39.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 40: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/40.jpg)
讀入 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, :);
![Page 41: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/41.jpg)
MGDATA
![Page 42: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/42.jpg)
初始化並產生 FIS
fismat = genfis1(trnData);
%fismat=genfis1(inputData,2,'gauss2mf','constant');
![Page 43: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/43.jpg)
訓練 ANFIS
[fismat1,error1,ss,fismat2,error2] = anfis(trnData,fismat,[],[],chkData);
![Page 44: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/44.jpg)
測試 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');
![Page 45: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/45.jpg)
![Page 46: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/46.jpg)
OUTLINE
Fuzzy logic toolbox
Fuzzy: use command line
Fuzzy: use GUI
ANFIS: use command line
ANFIS: use GUI
![Page 47: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/47.jpg)
開啟 ANFIS EDIT GUI
在 MATLAB command window 輸入 anfisedit
![Page 48: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/48.jpg)
讀入 DEMO 資料 在 MATLAB command window 輸入下列指令:load fuzex1trnData.datload fuzex2trnData.datload fuzex1chkData.datload fuzex2chkData.dat
![Page 49: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/49.jpg)
從 WORKSPACE 讀入資料
![Page 50: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/50.jpg)
![Page 51: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/51.jpg)
![Page 52: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/52.jpg)
![Page 53: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/53.jpg)
初始化並產生 FIS
![Page 54: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/54.jpg)
![Page 55: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/55.jpg)
瀏覽 FIS 結構
![Page 56: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/56.jpg)
訓練 ANFIS
![Page 57: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/57.jpg)
對訓練好的 ANFIS 進行測試
![Page 58: FuzzyANFIS](https://reader035.vdocument.in/reader035/viewer/2022062614/54783ed4b4af9fe61b8b45c0/html5/thumbnails/58.jpg)
Thanks!!