1 / 58

FUZZY & ANFIS

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

lydie
Download Presentation

FUZZY & ANFIS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. FUZZY & ANFIS Use MATLAB

  2. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  3. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  4. FUZZY LOGIC TOOLBOX • 附檔名:XXX.fis • 包含System、Input、Output及Rule四個部分 • 歸屬函數種類:常用包含三角形(trimf)、梯形(trapmf)、通用鐘形(gbellmf)、高斯(gaussmf)、高斯2(gauss2mf),不常用包含sigmf、dsigmf、psigmf、pimf、smf、zmf等。 • 模糊規則(Rule):由 if……then…… 組成。

  5. 歸屬函數種類 • Sigmf • Dsigmf • Psigmf • Pimf • Smf • Zmf • Trimf • Trapmf • Gbellmf • Gaussmf • Gauss2mf

  6. 模糊規則(RULE) • 語意表示法: • 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 假設有輸入有ABC三個歸屬函數 • 1 3, 2(1):2 輸出有α β兩個歸屬函數

  7. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  8. EXAMPLE:TIPPER

  9. 開啟MATLAB並新增一個M-file

  10. 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';

  11. 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]; %第三歸屬函數定義

  12. INPUT1

  13. INPUT2 [Input2] %定義第二輸入變數 Name='food'; Range=[0 10]; NumMFs=2; MF1='rancid':'trapmf',[0 0 1 3]; MF2='delicious':'trapmf',[7 9 10 10];

  14. INPUT2

  15. 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];

  16. OUTPUT1

  17. 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)

  18. RULES [Rules] %定義三條規則,用指標方式定義 1 1, 1 (1) : 2; 2 0, 2 (1) : 2; 3 2, 3 (1) : 2;

  19. 儲存成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

  20. 其他指令 • 畫出歸屬函數: plotmf(tipper,'input',1) • 顯示模糊規則: showrule(tipper) %語意表示法 showrule(tipper,[1 3],'symbolic') %符號表示法 • 畫出輸入輸出對照圖: surfview(tipper)

  21. 輸入輸出對照圖

  22. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  23. 開啟FUZZYLOGICTOOLBOXGUI • 在MATLAB command window輸入fuzzy

  24. 增加INPUT/OUTPUT

  25. 更改變數名稱

  26. 設定歸屬函數

  27. 設定範圍與名稱

  28. 設定歸屬函數種類

  29. 設定歸屬函數分布

  30. 增加/減少歸屬函數

  31. SERVICE

  32. FOOD

  33. TIP

  34. 設定模糊規則

  35. 設定模糊規則

  36. 測試TIPPER

  37. 測試TIPPER

  38. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  39. 讀入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, :);

  40. MGDATA

  41. 初始化並產生FIS fismat = genfis1(trnData); %fismat=genfis1(inputData,2,'gauss2mf','constant');

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

  43. 測試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');

  44. OUTLINE • Fuzzy logic toolbox • Fuzzy: use command line • Fuzzy: use GUI • ANFIS: use command line • ANFIS: use GUI

  45. 開啟ANFISEDIT GUI • 在MATLAB command window輸入anfisedit

  46. 讀入DEMO資料 • 在MATLAB command window輸入下列指令: load fuzex1trnData.dat load fuzex2trnData.dat load fuzex1chkData.dat load fuzex2chkData.dat

  47. 從WORKSPACE讀入資料

More Related