Пример #1
0
                  accumulation='MAX')
block.add_rules(rule1,
                rule2,
                rule3,
                rule4,
                rule5,
                rule7,
                rule8,
                rule9,
                rule10,
                rule11,
                scope=scope)

from fuzzython.systems.mamdani import MamdaniSystem

mamdani = MamdaniSystem('mamdani_model', block)

from mpl_toolkits.mplot3d import Axes3D  # Required for 3D plotting

# przygotowanie siatki
sampledX = np.linspace(10, 200, 50)
sampledY = np.linspace(0.05, 4, 50)
x, y = np.meshgrid(sampledX, sampledY)
z = np.zeros((len(sampledX), len(sampledY)))

for i in range(len(sampledX)):
    for j in range(len(sampledY)):
        inputs = {'speed': x[i, j], 'visibility': y[i, j]}
        res = mamdani.compute(inputs)
        z[i, j] = res['rb_mamdani']['accident']
Пример #2
0
scope = locals()

rule1 = 'if Temperature is t_low or Humidity is h_low then Klimatyzacja is k_low'
rule2 = 'if Temperature is t_medium or Humidity is h_lower_medium or Humidity is h_higher_medium then Klimatyzacja is k_medium'
rule3 = 'if Temperature is t_medium and Humidity is h_high then Klimatyzacja is k_medium'
rule4 = 'if Temperature is t_high or Humidity is h_high then Klimatyzacja is k_high'

block = RuleBlock('first',
                  operators=('MIN', 'MAX', 'ZADEH'),
                  activation='MIN',
                  accumulation='MAX')
block.add_rules(rule1, rule2, rule3, rule4, scope=scope)

# Stworzenie sterownika rozmytego typu Mamdani
from fuzzython.systems.mamdani import MamdaniSystem
mamdani = MamdaniSystem('ms1', block)

sampled = np.linspace(20, 40, 25)
sampled2 = np.linspace(0, 100, 25)
x, y = np.meshgrid(sampled, sampled2)
z = np.zeros((len(sampled), len(sampled2)))

for i in range(len(sampled)):
    for j in range(len(sampled2)):
        inputs = {'Temperature': x[i, j], 'Humidity': y[i, j]}
        res = mamdani.compute(inputs)
        z[i, j] = res['first']['Klimatyzacja']

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D  # Required for 3D plotting
rule2 = 'if temp is normal then time is usual'
rule3 = 'if temp is hot then time is large'

rule4 = 'if temp is cold then z = temp*0.1'
rule5 = 'if temp is normal then z=temp*0.3 + 1'
rule6 = 'if temp is hot then z=temp*0.6 + 2'

inputs = {'temp': 33}

block = RuleBlock('first',
                  operators=('MIN', 'MAX', 'ZADEH'),
                  activation='MIN',
                  accumulation='MAX')
block.add_rules(rule1, rule2, rule3, scope=scope)

mamdani = MamdaniSystem('ms1', block)
res = mamdani.compute(inputs)
print(res)
mamdani.dump('example_mamdani.txt')

# system = mamdani
# for t in (15, 17.5, 20, 30, 30.5, 31, 31.5, 32, 32.5, 33, 33.5, 34, 34.1, 34.2, 35):
#     print('--- TEMPERATURE input: {0} ---'.format(t))
#     inputs['temp'] = t
#     r = system.compute(inputs)
#     print('output:', r)

block = RuleBlock('second',
                  operators=('MIN', 'MAX', 'ZADEH'),
                  activation='MIN')
block.add_rules(rule4, rule5, rule6, scope=scope)