# import modułów import numpy as np import matplotlib.pyplot as plt from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable #Definicja zmiennych lingwistycznych #Dla każdej ze zmiennych definiujemy wartości lingwistyczne, trójkątne zbiory rozmyte # wartosci dla temperatury t_low = Triangular((19.9, 0), (20, 1), (30, 0)) t_medium = Triangular((20, 0), (30, 1), (40, 0)) t_high = Triangular((30, 0), (40, 1), (40.1, 0)) t_low = Adjective('t_low', t_low) t_medium = Adjective('t_medium', t_medium) t_high = Adjective('t_high', t_high) Temperature = Variable( 'Temperature', 'degree', t_low, t_medium, t_high) # Temperatura powietrza (20 stopni do 40 stopni) #wartosci dla wilgotnosci h_low = Triangular((-0.1, 0), (0, 1), (40, 0)) h_lower_medium = Triangular((0, 0), (40, 1), (60, 0)) h_higher_medium = Triangular((40, 0), (60, 1), (100, 0)) h_high = Triangular((60, 0), (100, 1), (100.1, 0)) h_low = Adjective('h_low', h_low) h_lower_medium = Adjective('h_lower_medium', h_lower_medium) h_higher_medium = Adjective('h_higher_medium', h_higher_medium)
ax.plot(x, y, *args, **kwargs) ax.set_ylim(-0.1, 1.1) ax.legend() # zmienna lingwistyczna `speed` opisująca prędkośc jazdy od 10 do 200 kmph # cztery wartości lingwistyczne, zbiory rozmyte: `s_low`, `s_medium`, `s_hight` ,`s_very_hight` # prędkość s_low = ZFunction((10, 0), 34, (60, 1)) s_medium = Gaussian(75, 20, 1) s_high = Gaussian(100, 20, 1) s_very_high = Trapezoid((120, 0), (130, 1), (199, 1), (200, 1)) a_s_low = Adjective('s_low', s_low) a_s_medium = Adjective('s_medium', s_medium) a_s_high = Adjective('s_high', s_high) a_s_very_high = Adjective('s_very_high', s_very_high) speed = Variable('speed', 'kmph', a_s_low, a_s_medium, a_s_high, a_s_very_high) # zmienna lingwistyczna `visibility` opisująca widoczność w km (0.05 − 4km # trzy wartości lingwistyczne, zbiory rozmyte: `v_low`, `v_medium`, `v_high` # widoczność v_low = Gaussian(0, 1, 1) v_medium = Gaussian(2, 1, 1) v_high = Triangular((2.5, 0), (3, 1), (4, 1)) a_v_low = Adjective('v_low', v_low) a_v_medium = Adjective('v_medium', v_medium)
from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable #Definicja zmiennych lingwistycznych #Dla każdej ze zmiennych definiujemy wartości lingwistyczne, trójkątne zbiory rozmyte q_poor = Triangular((0, 0), (3, 1), (5, 0)) q_average = Triangular((0, 0), (5, 1), (10, 0)) q_good = Triangular((5, 0), (10, 1), (10.1, 0)) q_poor = Adjective('q_poor', q_poor) q_average = Adjective('q_average', q_average) q_good = Adjective('q_good', q_good) quality = Variable('quality', 'star', q_poor, q_average, q_good) #jakość jedzenia w skali od 0 do 10 t_low = Triangular((-0.1, 0), (0, 1), (100, 0)) t_medium = Triangular((0, 0), (100, 1), (250, 0)) t_high = Triangular((100, 0), (250, 1), (250.1, 0)) t_low = Adjective('t_low', t_low) t_medium = Adjective('t_medium', t_medium) t_high = Adjective('t_high', t_high) tip = Variable('tip', '%', t_low, t_medium,
# pomocnicza funkcja do rysowania zbiorów rozmytych def plot_fuzzyset(ax, fuzzy_set, x, *args, **kwargs): y = np.array([fuzzy_set(e) for e in x]) ax.plot(x, y, *args, **kwargs) ax.set_ylim(-0.1, 1.1) ax.legend() s_slow = Triangular((9.99, 0), (10, 1), (73.33, 0)) s_medium = Triangular((10, 0), (73.33, 1), (136.66, 0)) s_fast = Triangular((73.34, 0), (136.66, 1), (200, 0)) s_very_fast = Triangular((136.66, 0), (200, 1), (200.1, 0)) a_s_slow = Adjective("s_slow", s_slow) a_s_medium = Adjective("s_medium", s_medium) a_s_fast = Adjective("s_fast", s_fast) a_s_very_fast = Adjective("s_very_fast", s_very_fast) speed = Variable("speed", "km/h", a_s_slow, a_s_medium, a_s_fast, a_s_very_fast) v_poor = Triangular((0.04, 0), (0.05, 1), (1.975, 0)) v_medium = Triangular((0.05, 0), (1.975, 1), (4, 0)) v_good = Triangular((1.975, 0), (4, 1), (4.1, 0)) a_v_poor = Adjective("v_poor", v_poor) a_v_medium = Adjective("v_medium", v_medium) a_v_good = Adjective("v_good", v_good)
from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable #Definicja zmiennych lingwistycznych #Dla każdej ze zmiennych definiujemy wartości lingwistyczne, trójkątne zbiory rozmyte #procesor p_poor = Triangular((-1, 0), (500, 1), (900, 0)) p_average = Triangular((500, 0), (900, 1), (1500, 0)) p_good = Triangular((900, 0), (1500, 1), (2500, 0)) p_poor = Adjective('p_poor', p_poor) p_average = Adjective('p_average', p_average) p_good = Adjective('p_good', p_good) procesor = Variable('procesor', 'star', p_poor, p_average, p_good) #karta graficzna k_poor = Triangular((-1, 0), (350, 1), (700, 0)) k_average = Triangular((350, 0), (700, 1), (1200, 0)) k_good = Triangular((700, 0), (1200, 1), (1900, 0)) k_poor = Adjective('k_poor', k_poor) k_average = Adjective('k_average', k_average) k_good = Adjective('k_good', k_good) karta = Variable('karta', 'star', k_poor, k_average, k_good) #moc komputera w %%%% m_low = Triangular((-1, 0), (1, 1), (50, 0))
from fuzzython.ruleblock import RuleBlock # prosty przykład z użyciem trójkątnych zbiorów rozmytych from fuzzython.fsets.triangular import Triangular # klasa Variable - zmienna lingwistyczna from fuzzython.variable import Variable # klasa Adjective - wartość zmiennej lingwistycznej from fuzzython.adjective import Adjective # zmienna lingwistyczna `quality` opisująca jakość jedenia w skali od 0 do 10 gwiazdek (star) # trzy wartości lingwistyczne, trójkątne zbiory rozmyte: `q_poor`, `q_average`, `q_good` q_poor = Triangular((-0.1, 0), (0, 1), (5, 0)) q_average = Triangular((0, 0), (5, 1), (10, 0)) q_good = Triangular((5, 0), (10, 1), (10.1, 0)) a_q_poor = Adjective('q_poor', q_poor) a_q_average = Adjective('q_average', q_average) a_q_good = Adjective('q_good', q_good) quality = Variable('quality', 'star', a_q_poor, a_q_average, a_q_good) # zmienna lingwistyczna `service` opisująca jakość obsługi w skali od 0 do 10 gwiazdek (star) # trzy wartości lingwistyczne, trójkątne zbiory rozmyte: `s_poor`, `s_average`, `s_good` s_poor = Triangular((-0.1, 0), (0, 1), (5, 0)) s_average = Triangular((0, 0), (5, 1), (10, 0)) s_good = Triangular((5, 0), (10, 1), (10.1, 0)) a_s_poor = Adjective('s_poor', s_poor) a_s_average = Adjective('s_average', s_average) a_s_good = Adjective('s_good', s_good) service = Variable('service', 'star', a_s_poor, a_s_average, a_s_good)
from fuzzython.fsets.trapezoid import Trapezoid from fuzzython.ruleblock import RuleBlock from fuzzython.systems.mamdani import MamdaniSystem from fuzzython.systems.sugeno import SugenoSystem from fuzzython.systems.tsukamoto import TsukamotoSystem from fuzzython.variable import Variable print('--- START ---') # --- Variables --- cold = Polygon((0, 1), (15, 1), (20, 0)) # Rect.build_from((15,1), (20,0)) normal = Trapezoid((15, 0), (20, 1), (30, 1), (35, 0)) hot = Polygon((30, 0), (35, 1), (40, 1)) # Rect.build_from((30,0), (35,1)) cold = Adjective('cold', cold) normal = Adjective('normal', normal) hot = Adjective('hot', hot) temp = Variable('temp', '°C', cold, normal, hot) #temp.value = 33 short = Polygon((0, 1), (10, 1), (15, 0)) usual = Trapezoid((10, 0), (15, 1), (25, 1), (30, 0)) large = Polygon((25, 0), (30, 1), (40, 1)) short = Adjective('short', short) usual = Adjective('usual', usual) large = Adjective('large', large) time = Variable('time',
from fuzzython.fsets.triangular import Triangular from fuzzython.adjective import Adjective from fuzzython.variable import Variable # ========================================================================= # ========================================================================= # ========================================================================= #Definicja zmiennych lingwistycznych #Dla każdej ze zmiennych definiujemy wartości lingwistyczne, trójkątne zbiory rozmyte # wartosci dla natężenia światła l_low = Triangular((19.9, 0), (20, 1), (60, 0)) l_medium = Triangular((20, 0), (60, 1), (100, 0)) l_high = Triangular((60, 0), (100, 1), (100.1, 0)) l_low = Adjective('l_low', l_low) l_medium = Adjective('l_medium', l_medium) l_high = Adjective('l_high', l_high) LightIntensity = Variable( 'LightIntensity', 'klx', l_low, l_medium, l_high) #natężenie światła w kilo luxach (20[klx] - 60[klx]- 100[klx]) #wartości dla pory dnia t_dawn = Triangular((5.9, 0), (6, 1), (6.5, 0)) t_morning = Triangular((6.0, 0), (6.5, 1), (11.1, 0)) t_afternoon = Triangular((6.5, 0), (11, 1), (17, 0)) t_evening = Triangular((11, 0), (17, 1), (21, 0)) t_dawn = Adjective('t_dawn', t_dawn) t_morning = Adjective('t_morning', t_morning) t_afternoon = Adjective('t_afternoon', t_afternoon) t_evening = Adjective('t_evening', t_evening)