範例:小費問題(Mamdani)
老師錄製的操作示範:用工具箱的圖形介面,從頭建立小費問題的 Mamdani 型 FIS。完成的檔案即附檔 tipper.fis。
▶ 在 Colab 開啟原課程的 MATLAB 程式已改寫成 Python 筆記本(第 2、6 節 tipper.fis),可以直接在瀏覽器執行、修改參數。⬇ 下載 Fuzzy_toolbox.ipynb
tipper.fis 的內容 What Is in the FIS
(以下整理自附檔,為補充)
| 變數 | 範圍 | 歸屬函數 |
|---|---|---|
| 輸入 service(服務) | 0~10 | poor 差 gaussmf [1.5 0]、good 好 gaussmf [1.5 5]、excellent 優 gaussmf [1.5 10] |
| 輸入 food(食物) | 0~10 | rancid 難吃 trapmf [0 0 1 3]、delicious 好吃 trapmf [7 9 10 10] |
| 輸出 tip(小費 %) | 0~30 | cheap 少 trimf [0 5 10]、average 普通 trimf [10 15 20]、generous 多 trimf [20 25 30] |
- If service is poor or food is rancid, then tip is cheap.
- If service is good, then tip is average.
- If service is excellent or food is delicious, then tip is generous.
運算方法:AND = min、OR = max、蘊含 min(截頂)、聚合 max、解模糊化 centroid(重心)。檔案中規則 1、3 的連接詞代碼是 2(OR),規則 2 的食物欄為 0(不使用)。
推論過程的逐步圖解與互動版本見 Mamdani 型模糊推論。服務 3、食物 8 時,小費為 18.0%。