-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfuzzyMain.py
141 lines (131 loc) · 3.73 KB
/
fuzzyMain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Fuzzy Inference System Mamdani
# Abdan Subekti 2010501038
# **********Requirements**********
# matplolib, numpy, fuzzy-expert
import matplotlib.pyplot as plt
import numpy as np
from fuzzy_expert.variable import FuzzyVariable
from fuzzy_expert.rule import FuzzyRule
from fuzzy_expert.inference import DecompositionalInference
# Input Himpunan Fuzzy
variables = {
# INPUT
"Pelayanan": FuzzyVariable(
universe_range=(0, 100), # Sumbu x
terms={
"Buruk": ("trapmf", 0, 0, 15, 40), # trapmf = Kurva Trapesium
"Biasa": ("trimf", 25, 50, 75), # trimf = Kurva Segitiga
"Bagus": ("trapmf", 60, 85, 100, 100),
},
),
"Kerapian": FuzzyVariable(
universe_range=(0, 100),
terms={
"Kurang": ("trapmf", 0, 0, 40, 60),
"Cukup": ("trimf", 40, 60, 80),
"Baik": ("trapmf", 60, 80, 100, 100),
},
),
"Terlambat": FuzzyVariable(
universe_range=(0, 30),
terms={
"Jarang": ("trapmf", 0, 0, 2.5, 7.5),
"Kadang": ("trimf", 2.5, 10, 17.5),
"Sering": ("trapmf", 12.5, 17.5, 30, 30),
},
),
"Produk_Terjual": FuzzyVariable(
universe_range=(0, 900),
terms={
"Sedikit": ("trapmf", 0, 0, 300, 500),
"Sedang": ("trimf", 350, 500, 650),
"Banyak": ("trapmf", 500, 700, 900, 900),
},
),
# OUTPUT
"Insentif": FuzzyVariable(
universe_range=(0, 1000),
terms={
"Rendah": ("trapmf", 0, 0, 100, 500),
"Menengah": ("trimf", 100, 500, 900),
"Tinggi": ("trapmf", 500, 900, 1000, 1000),
},
),
}
# Rules/Inferensi Fuzzy
rules = [
# 1
FuzzyRule(
premise=[
("Pelayanan", "Buruk"),
("AND", "Kerapian", "Kurang"),
("AND", "Terlambat", "Sering"),
("AND", "Produk_Terjual", "Sedikit"),
],
consequence=[("Insentif", "Rendah")],
),
# 2
FuzzyRule(
premise=[
("Pelayanan", "Biasa"),
("AND", "Kerapian", "Cukup"),
("AND", "Terlambat", "Kadang"),
("AND", "Produk_Terjual", "Sedang"),
],
consequence=[("Insentif", "Menengah")],
),
# 3
FuzzyRule(
premise=[
("Pelayanan", "Bagus"),
("AND", "Kerapian", "Baik"),
("AND", "Terlambat", "Jarang"),
("AND", "Produk_Terjual", "Banyak"),
],
consequence=[("Insentif", "Tinggi")],
),
]
# Defuzzyfikasi & Variabelnya
model = DecompositionalInference(
and_operator="min",
or_operator="max",
implication_operator="Rc",
composition_operator="max-min",
production_link="max",
defuzzification_operator="cog", # Metode Defuzzyfikasi (cog, bisektor, mom, som, lom)
)
# Input data dan visualisasi Fuzzy
"""plt.figure(figsize=(10, 6)) # Ukuran window (Inch)
model.plot(
variables=variables,
rules=rules,
Pelayanan=20, # Input Variabel
Kerapian=10,
Terlambat=18,
Produk_Terjual=230,
)
plt.show()"""
# visualisasi input crisp fuzzy
plt.figure(figsize=(6, 2.5))
plt.grid(True)
plt.title("Pelayanan")
variables["Pelayanan"].plot()
plt.figure(figsize=(6, 2.5))
plt.grid(True)
plt.title("Kerapian")
variables["Kerapian"].plot()
plt.figure(figsize=(6, 2.5))
plt.grid(True)
plt.title("Keterlambatan dalam sebulan")
plt.xlabel("Akumulasi waktu (Jam)")
variables["Terlambat"].plot()
plt.figure(figsize=(6, 2.5))
plt.grid(True)
plt.title("Produk Terjual (Unit)")
plt.xlabel("Jumlah Barang")
variables["Produk_Terjual"].plot()
plt.figure(figsize=(6, 2.5))
plt.grid(True)
plt.title("Insentif (Rupiah)")
variables["Insentif"].plot()
plt.show()