示例#1
0
def test_fuzzy_not():
    x = np.r_[0:10.1:0.1]
    mfx = trimf(x, [0, 5, 10])
    expected = np.fmax(trimf(x, [0, 0, 5]), trimf(x, [5, 10, 10]))

    # Not exactly equal due to expected float error ~1e-16
    assert_allclose(fuzzy_not(mfx), expected)
示例#2
0
def _plot_mf_for(x):
    '''Given the x-values, plot a series of example membership functions'''
    tests = OrderedDict([
        # Gaussians:
        ('gauss', skmemb.gaussmf(x, 50, 10)),
        ('left gauss', leftgaussmf(x, 50, 10)),
        ('right gauss', rightgaussmf(x, 50, 10)),
        # Triangles:
        ('triangular', skmemb.trimf(x, [25, 50, 75])),
        ('left linear', leftlinearmf(x, 25, 75)),
        ('right linear', rightlinearmf(x, 25, 75)),
        # fuzzylite:
        ('cosine', cosinemf(x, 50, 50)),
        ('inc concave', concavemf(x, 50, 75)),
        ('dec concave', concavemf(x, 50, 25)),
        ('spike', spikemf(x, 50, 50)),
        ('inc ramp', rampmf(x, 25, 75)),
        ('dec ramp', rampmf(x, 75, 25)),
        # Rectangle-ish
        ('trapezoid', skmemb.trapmf(x, [20, 40, 60, 80])),
        ('rectangle', rectanglemf(x, 25, 75)),
        ('singleton', singletonmf(x, 50)),
    ])
    # Example point sets:
    ps_tests = [[(40, 0.5), (60, 1)],
                [(10, 0.5), (25, 0.25), (40, 0.75), (80, .5)],
                [(0, 1), (40, 0.25), (50, .5), (99, 0)]]
    # Now try some interpolation methods on these:
    for method in ['linear', 'lagrange', 'spline', 'cubic']:
        tests.update([('{} ex{}'.format(method, i), pointsetmf(x, ps, method))
                      for i, ps in enumerate(ps_tests)])
    return tests
示例#3
0
 def generate_mf_group(self, G, x):
     mf_group = {}
     for (k, v) in G.iteritems():
         shp = v['shp']
         mf = v['mf']
         if mf == 'trap':
             mf_group[k] = trapmf(x, shp)
         if mf == 'tri':
             mf_group[k] = trimf(x, shp)
         if mf == 'gbell':
             mf_group[k] = gbellmf(x, shp[0], shp[1], shp[2])
         if mf == 'gauss':
             mf_group[k] = gaussmf(x, shp[0], shp[1])
         if mf == 'gauss2':
             mf_group[k] = gauss2mf(x, shp[0], shp[1])
         if mf == 'sig':
             mf_group[k] = sigmf(x, shp[0], shp[1])
         if mf == 'psig':
             mf_group[k] = psigmf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'zmf':
             mf_group[k] = zmf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'smf':
             mf_group[k] = smf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'pimf':
             mf_group[k] = pimf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'piecemf':
             mf_group[k] = piecemf(x, shp[0], shp[1], shp[2], shp[3])
     return mf_group
示例#4
0
 def generate_mf_group(self, G, x):
     mf_group = {}
     for (k, v) in G.iteritems():
         shp = v['shp']
         mf = v['mf']
         if mf == 'trap':
             mf_group[k] = trapmf(x, shp)
         if mf == 'tri':
             mf_group[k] = trimf(x, shp)
         if mf == 'gbell':
             mf_group[k] = gbellmf(x, shp[0], shp[1], shp[2])
         if mf == 'gauss':
             mf_group[k] = gaussmf(x, shp[0], shp[1])
         if mf == 'gauss2':
             mf_group[k] = gauss2mf(x, shp[0], shp[1])
         if mf == 'sig':
             mf_group[k] = sigmf(x, shp[0], shp[1])
         if mf == 'psig':
             mf_group[k] = psigmf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'zmf':
             mf_group[k] = zmf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'smf':
             mf_group[k] = smf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'pimf':
             mf_group[k] = pimf(x, shp[0], shp[1], shp[2], shp[3])
         if mf == 'piecemf':
             mf_group[k] = piecemf(x, shp[0], shp[1], shp[2], shp[3])
     return mf_group
示例#5
0
def test_fuzzy_or():
    x = np.r_[0:10.1:0.1]
    mfx = trimf(x, [0, 5, 10])
    mfy = np.ones_like(mfx) - 0.5
    expected = np.fmax(mfy, mfx)
    z, mfz = fuzzy_or(x, mfx, x, mfy)

    # Not exactly equal due to expected float error ~1e-16
    assert_allclose(mfz, expected)
    assert_array_equal(z, x)
示例#6
0
def test_trimf():
    x = np.arange(-4, 4.1, 0.1)
    abc = (-np.pi, -np.e / 2., np.pi / 5.)
    expected = np.zeros_like(x)
    idx = np.logical_and(x > abc[0], x < abc[1])
    expected[idx] = np.interp(x[idx], np.r_[abc[0], abc[1]], np.r_[0, 1])
    expected[x == abc[1]] = 1
    idx = np.logical_and(x > abc[1], x < abc[2])
    expected[idx] = np.interp(x[idx], np.r_[abc[1], abc[2]], np.r_[1, 0])
    test = trimf(x, abc)
    assert_allclose(test, expected)
示例#7
0
def test_trimf():
    x = np.arange(-4, 4.1, 0.1)
    abc = (-np.pi, -np.e / 2., np.pi / 5.)
    expected = np.zeros_like(x)
    idx = np.logical_and(x > abc[0], x < abc[1])
    expected[idx] = np.interp(x[idx], np.r_[abc[0], abc[1]], np.r_[0, 1])
    expected[x == abc[1]] = 1
    idx = np.logical_and(x > abc[1], x < abc[2])
    expected[idx] = np.interp(x[idx], np.r_[abc[1], abc[2]], np.r_[1, 0])
    test = trimf(x, abc)
    assert_allclose(test, expected)
示例#8
0
def test_universe_resampling():
    x = np.r_[0:10.1:0.1]
    y = np.r_[-2:12.1:0.25]
    mfx = trimf(x, [0, 5, 10])
    mfy = trimf(y, [-2, 2, 12])

    # Tests for `fuzzy_and` resampling
    z, mfz = fuzzy_and(x, mfx, y, mfy)
    z_expected = np.r_[-2:12.1:0.1]
    assert_allclose(z, z_expected, atol=1e-14)
    mfz_expected = np.fmin(trimf(z_expected, [0, 5, 10]),
                           trimf(z_expected, [-2, 2, 12]))
    assert_allclose(mfz, mfz_expected, atol=1e-14)

    # Tests for `fuzzy_or` resampling
    z, mfz = fuzzy_or(x, mfx, y, mfy)
    z_expected = np.r_[-2:12.1:0.1]
    assert_allclose(z, z_expected, atol=1e-14)
    mfz_expected = np.fmax(trimf(z_expected, [0, 5, 10]),
                           trimf(z_expected, [-2, 2, 12]))
    assert_allclose(mfz, mfz_expected, atol=1e-14)
示例#9
0
        ax[2].set_title('Fuzzy logic control action u')
        fig.suptitle('Simulation.  Gain K = ' + str(K))

        plt.show()

    return xx1, xx2, uu, tt

if __name__ == '__main__':
    
    """
    These functions represent an inverted pendulum.
    """
    # Membership Matrices
    x1 = np.arange(-10, 10.1, 0.1)        # Angle range, 1d array, length N, Fuzzy state variable #1.
    N1 = trapmf(x1, [-10, -10, -2, 0])    # Negative membership function
    Z1 = trimf(x1, [-2, 0, 2])            # Zero membership function
    P1 = trapmf(x1, [0, 2, 10, 10])       # Positive membership function
    M1 = np.vstack((N1, Z1, P1))          # Input 1 membership matrix, 2d array, shape (Q1, N), Matrix with Q1 membership functions for x1.
    
    x2 = np.arange(-10, 10.1, 0.1)        # Angular velocity range, 1d array, length M, Fuzzy state variable #2.
    N2 = trapmf(x2, [-10, -10, -2, 0])    # Negative membership function
    Z2 = trimf(x2, [-2, 0, 2])            # Zero membership function
    P2 = trapmf(x2, [0, 2, 10, 10])       # Positive membership function
    M2 = np.vstack((N2, Z2, P2))          # Input 2 membership matrix, 2d array, shape (Q2, M), Matrix with Q2 membership functions for x2.

    # Fuzzy control (u) and member functions
    u = np.arange(-25, 25.25, 0.25)         # Fuzzy control output variable, 1d array, length U, Feedback control action variable.
    NBu = trapmf(u, [-25, -25, -16, -8])    # Big Negative` membership function
    Nu = trimf(u, [-16, -8, 0])             # Negative` membership function
    Zu = trimf(u, [-8, 0, 8])               # Zero` membership function
    Pu = trimf(u, [0, 8, 16])               # Positive` membership function
示例#10
0
import numpy as np
import skfuzzy as fuzz
import skfuzzy.membership as mf
import matplotlib.pyplot as plt

x_tempTest = np.arange(0, 101, 1)
x_firmTest = np.arange(0, 101, 1)
y_quality = np.arange(0, 101, 1)

temp_low = mf.trapmf(x_tempTest, [0, 0, 10, 40])
temp_med = mf.trimf(x_tempTest, [20, 50, 80])
temp_hig = mf.trapmf(x_tempTest, [60, 90, 100, 100])

firm_low = mf.trimf(x_firmTest, [0, 0, 40])
firm_med = mf.trimf(x_firmTest, [30, 50, 70])
firm_hig = mf.trimf(x_firmTest, [60, 100, 100])

#result_no = mf.trimf(y_quality, [0, 0, 100])
#result_ok = mf.trimf(y_quality, [0, 100, 100])

quality_verylow = mf.trimf(y_quality, [0, 0, 25])
quality_bitlow = mf.trimf(y_quality, [0, 25, 50])
quality_middle = mf.trimf(y_quality, [25, 50, 75])
quality_bithigh = mf.trimf(y_quality, [50, 75, 100])
quality_veryhig = mf.trimf(y_quality, [75, 100, 100])

fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(6, 10))

ax0.plot(x_tempTest, temp_low, 'r', linewidth=2, label='Düşük')
ax0.plot(x_tempTest, temp_med, 'g', linewidth=2, label='Orta')
ax0.plot(x_tempTest, temp_hig, 'b', linewidth=2, label='Yüksek')
示例#11
0
def fuzzy_calculate(input_ph, input_zf, input_ai, input_i, input_kc, input_pd,
                    input_ed, input_gb, input_gs):
    # zf kisminda kullanici tarafindan girilen zaman dilimi degerini alan
    # bu degeri araliktaki kismini bulan method yazilacak

    # Değişkenlerin oluşturulması
    # 1- ph(Proje Surecine hakimiyet)
    # 2- zf(Zaman Dilimi Farkliligi)
    # 3- ai(Adim Adim Ilerleme)
    # 4- i(iletisim)
    # 5- pd(Proje Deneyimi)
    # 6- ed(ekibin deneyimmli olmasi)
    # 7- gb(Gorevlerin Birbirine Bagliligi)
    # 8- gs(Gerekliliklerin Sabit Kalmasi)
    # 9- kc(Kaynak Cesitliligi),

    plt.close()

    ph = np.arange(0, 101, 1)
    zf = np.arange(0, 101, 1)
    ai = np.arange(0, 101, 1)
    i = np.arange(0, 101, 1)
    pd = np.arange(0, 101, 1)
    ed = np.arange(0, 101, 1)
    gb = np.arange(0, 101, 1)
    gs = np.arange(0, 101, 1)
    kc = np.arange(0, 101, 1)
    risk = np.arange(0, 101, 1)

    # Üyelik fonksiyonlarının oluşturulması

    ph_low = mf.trimf(ph, [0, 0, 50])
    ph_med = mf.trimf(ph, [0, 50, 100])
    ph_hig = mf.trimf(ph, [50, 100, 100])

    zf_low = mf.trimf(zf, [0, 0, 50])
    zf_med = mf.trimf(zf, [0, 50, 100])
    zf_hig = mf.trimf(zf, [50, 100, 100])

    ai_very_low = mf.trimf(ai, [0, 0, 100])
    ai_very_hig = mf.trimf(ai, [0, 100, 100])

    i_low = mf.trimf(i, [0, 0, 50])
    i_med = mf.trimf(i, [0, 50, 100])
    i_hig = mf.trimf(i, [50, 100, 100])

    pd_very_low = mf.trimf(pd, [0, 0, 25])
    pd_low = mf.trimf(pd, [0, 25, 50])
    pd_med = mf.trimf(pd, [25, 50, 75])
    pd_hig = mf.trimf(pd, [50, 75, 100])
    pd_very_hig = mf.trimf(pd, [75, 100, 100])

    ed_very_low = mf.trimf(ed, [0, 0, 25])
    ed_low = mf.trimf(ed, [0, 25, 50])
    ed_med = mf.trimf(ed, [25, 50, 75])
    ed_hig = mf.trimf(ed, [50, 75, 100])
    ed_very_hig = mf.trimf(ed, [75, 100, 100])

    gb_low = mf.trimf(gb, [0, 0, 50])
    gb_med = mf.trimf(gb, [0, 50, 100])
    gb_hig = mf.trimf(gb, [50, 100, 100])

    gs_low = mf.trimf(gs, [0, 0, 50])
    gs_med = mf.trimf(gs, [0, 50, 100])
    gs_hig = mf.trimf(gs, [50, 100, 100])

    kc_very_low = mf.trimf(kc, [0, 0, 25])
    kc_low = mf.trimf(kc, [0, 25, 50])
    kc_med = mf.trimf(kc, [25, 50, 75])
    kc_hig = mf.trimf(kc, [50, 75, 100])
    kc_very_hig = mf.trimf(kc, [75, 100, 100])

    risk_very_hig = mf.trimf(risk, [0, 0, 25])
    risk_hig = mf.trimf(risk, [0, 25, 50])
    risk_med = mf.trimf(risk, [25, 50, 75])
    risk_low = mf.trimf(risk, [50, 75, 100])
    risk_very_low = mf.trimf(risk, [75, 100, 100])

    # Veri görselleştirme
    #ax3, ax4, ax5, ax6, ax7, ax8, ax9

    fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(6, 10))

    ax0.plot(ph, ph_low, 'r', linewidth=2, label='Düşük')
    ax0.plot(ph, ph_med, 'g', linewidth=2, label='Orta')
    ax0.plot(ph, ph_hig, 'b', linewidth=2, label='Yüksek')
    ax0.set_title('Proje Süreci Hakimiyeti')
    ax0.legend()

    ax1.plot(zf, zf_low, 'r', linewidth=2, label='Düşük')
    ax1.plot(zf, zf_med, 'g', linewidth=2, label='Orta')
    ax1.plot(zf, zf_hig, 'b', linewidth=2, label='Yüksek')
    ax1.set_title('Zaman Dilimi Farklılığı')
    ax1.legend()

    ax2.plot(ai, ai_very_low, 'r', linewidth=2, label='Düşük')
    ax2.plot(ai, ai_very_hig, 'b', linewidth=2, label='Yüksek')
    ax2.set_title('Adım Adım İlerleme')
    ax2.legend()

    plt.tight_layout()

    fig, (ax3, ax4, ax5) = plt.subplots(nrows=3, figsize=(6, 10))

    ax3.plot(i, i_low, 'r', linewidth=2, label='Düşük')
    ax3.plot(i, i_med, 'g', linewidth=2, label='Orta')
    ax3.plot(i, i_hig, 'b', linewidth=2, label='Yüksek')
    ax3.set_title('İletişim')
    ax3.legend()

    ax4.plot(pd, pd_very_low, 'y', linewidth=2, label='Çok Düşük')
    ax4.plot(pd, pd_low, 'r', linewidth=2, label='Düşük')
    ax4.plot(pd, pd_med, 'g', linewidth=2, label='Orta')
    ax4.plot(pd, pd_hig, 'b', linewidth=2, label='Yüksek')
    ax4.plot(pd, pd_very_hig, 'k', linewidth=2, label='Çok Yüksek')
    ax4.set_title('Proje Deneyimi')
    ax4.legend()

    ax5.plot(ed, ed_very_low, 'y', linewidth=2, label='Çok Düşük')
    ax5.plot(ed, ed_low, 'r', linewidth=2, label='Düşük')
    ax5.plot(ed, ed_med, 'g', linewidth=2, label='Orta')
    ax5.plot(ed, ed_hig, 'b', linewidth=2, label='Yüksek')
    ax5.plot(ed, ed_very_hig, 'k', linewidth=2, label='Çok Yüksek')
    ax5.set_title('Ekip Deneyimi')
    ax5.legend()

    plt.tight_layout()

    fig, (ax6, ax7, ax8, ax9) = plt.subplots(nrows=4, figsize=(6, 10))

    ax6.plot(gb, gb_low, 'r', linewidth=2, label='Düşük')
    ax6.plot(gb, gb_med, 'g', linewidth=2, label='Orta')
    ax6.plot(gb, gb_hig, 'b', linewidth=2, label='Yüksek')
    ax6.set_title('Görevlerin Birbirine Bağımlılığı')
    ax6.legend()

    ax7.plot(gs, gs_low, 'r', linewidth=2, label='Düşük')
    ax7.plot(gs, gs_med, 'g', linewidth=2, label='Orta')
    ax7.plot(gs, gs_hig, 'b', linewidth=2, label='Yüksek')
    ax7.set_title('Gerekliliklerin Sabit kalması')
    ax7.legend()

    ax8.plot(kc, kc_very_low, 'y', linewidth=2, label='Çok Düşük')
    ax8.plot(kc, kc_low, 'r', linewidth=2, label='Düşük')
    ax8.plot(kc, kc_med, 'g', linewidth=2, label='Orta')
    ax8.plot(kc, kc_hig, 'b', linewidth=2, label='Yüksek')
    ax8.plot(kc, kc_very_hig, 'k', linewidth=2, label='Çok Yüksek')
    ax8.set_title('Kaynak Çeşitliliği')
    ax8.legend()

    ax9.plot(risk, risk_very_low, 'y', linewidth=2, label='Çok Düşük')
    ax9.plot(risk, risk_low, 'r', linewidth=2, label='Düşük')
    ax9.plot(risk, risk_med, 'g', linewidth=2, label='Orta')
    ax9.plot(risk, risk_hig, 'b', linewidth=2, label='Yüksek')
    ax9.plot(risk, risk_very_hig, 'k', linewidth=2, label='Çok Yüksek')
    ax9.set_title('Risk Oranı')
    ax9.legend()

    plt.tight_layout()

    # input_ph
    # input_zf
    # input_ai
    # input_i
    # input_dp
    # input_ed
    # input_gb
    # input_gs
    # input_kc

    # Üyelik derecelerinin hesaplanması

    ph_fit_low = fuzz.interp_membership(ph, ph_low, input_ph)
    ph_fit_med = fuzz.interp_membership(ph, ph_med, input_ph)
    ph_fit_hig = fuzz.interp_membership(ph, ph_hig, input_ph)

    zf_fit_low = fuzz.interp_membership(zf, zf_low, input_zf)
    zf_fit_med = fuzz.interp_membership(zf, zf_med, input_zf)
    zf_fit_hig = fuzz.interp_membership(zf, zf_hig, input_zf)

    ai_fit_very_low = fuzz.interp_membership(ai, ai_very_low, input_ai)
    ai_fit_very_hig = fuzz.interp_membership(ai, ai_very_hig, input_ai)

    i_fit_low = fuzz.interp_membership(i, i_low, input_i)
    i_fit_med = fuzz.interp_membership(i, i_med, input_i)
    i_fit_hig = fuzz.interp_membership(i, i_hig, input_i)

    pd_fit_very_low = fuzz.interp_membership(pd, pd_very_low, input_pd)
    pd_fit_low = fuzz.interp_membership(pd, pd_low, input_pd)
    pd_fit_med = fuzz.interp_membership(pd, pd_med, input_pd)
    pd_fit_hig = fuzz.interp_membership(pd, pd_hig, input_pd)
    pd_fit_very_hig = fuzz.interp_membership(pd, pd_very_hig, input_pd)

    ed_fit_very_low = fuzz.interp_membership(ed, ed_very_low, input_ed)
    ed_fit_low = fuzz.interp_membership(ed, ed_low, input_ed)
    ed_fit_med = fuzz.interp_membership(ed, ed_med, input_ed)
    ed_fit_hig = fuzz.interp_membership(ed, ed_hig, input_ed)
    ed_fit_very_hig = fuzz.interp_membership(ed, ed_very_hig, input_ed)

    gb_fit_low = fuzz.interp_membership(gb, gb_low, input_gb)
    gb_fit_med = fuzz.interp_membership(gb, gb_med, input_gb)
    gb_fit_hig = fuzz.interp_membership(gb, gb_hig, input_gb)

    gs_fit_low = fuzz.interp_membership(gs, gs_low, input_gs)
    gs_fit_med = fuzz.interp_membership(gs, gs_med, input_gs)
    gs_fit_hig = fuzz.interp_membership(gs, gs_hig, input_gs)

    kc_fit_very_low = fuzz.interp_membership(kc, kc_very_low, input_kc)
    kc_fit_low = fuzz.interp_membership(kc, kc_low, input_kc)
    kc_fit_med = fuzz.interp_membership(kc, kc_med, input_kc)
    kc_fit_hig = fuzz.interp_membership(kc, kc_hig, input_kc)
    kc_fit_very_hig = fuzz.interp_membership(kc, kc_very_hig, input_kc)

    # Kuralların tabanları

    # PH GB GS ZF

    rule11 = np.fmin(ph_fit_hig, risk_very_low)
    rule12 = np.fmin(ph_fit_med, risk_med)
    rule13 = np.fmin(ph_fit_low, risk_very_hig)

    rule14 = np.fmin(zf_fit_hig, risk_hig)
    rule15 = np.fmin(zf_fit_med, risk_med)
    rule16 = np.fmin(zf_fit_low, risk_low)

    rule17 = np.fmin(gs_fit_hig, risk_low)
    rule18 = np.fmin(gs_fit_med, risk_med)
    rule19 = np.fmin(gs_fit_low, risk_hig)

    rule110 = np.fmin(gb_fit_hig, risk_very_hig)
    rule111 = np.fmin(gb_fit_med, risk_med)
    rule112 = np.fmin(gb_fit_low, risk_very_low)

    rule1_1 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_hig),
                zf_fit_hig), risk_med)
    rule1_2 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_hig),
                zf_fit_med), risk_med)
    rule1_3 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_hig),
                zf_fit_low), risk_med)

    rule1_4 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_med),
                zf_fit_hig), risk_med)
    rule1_5 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_med),
                zf_fit_med), risk_med)
    rule1_6 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_med),
                zf_fit_low), risk_med)

    rule1_7 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_low),
                zf_fit_hig), risk_med)
    rule1_8 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_low),
                zf_fit_med), risk_med)
    rule1_9 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_hig), gb_fit_low),
                zf_fit_low), risk_low)

    rule1_10 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_hig),
                zf_fit_hig), risk_hig)
    rule1_11 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_hig),
                zf_fit_med), risk_med)
    rule1_12 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_hig),
                zf_fit_low), risk_med)

    rule1_13 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_med),
                zf_fit_hig), risk_med)
    rule1_14 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_med),
                zf_fit_med), risk_med)
    rule1_15 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_med),
                zf_fit_low), risk_med)

    rule1_16 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_low),
                zf_fit_hig), risk_med)
    rule1_17 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_low),
                zf_fit_med), risk_med)
    rule1_18 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_med), gb_fit_low),
                zf_fit_low), risk_med)

    rule1_19 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_hig),
                zf_fit_hig), risk_hig)
    rule1_20 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_hig),
                zf_fit_med), risk_hig)
    rule1_21 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_hig),
                zf_fit_low), risk_hig)

    rule1_22 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_23 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_med),
                zf_fit_med), risk_hig)
    rule1_24 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_25 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_low),
                zf_fit_hig), risk_hig)
    rule1_26 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_low),
                zf_fit_med), risk_hig)
    rule1_27 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_hig, gs_fit_low), gb_fit_low),
                zf_fit_low), risk_med)

    rule1_28 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_hig),
                zf_fit_hig), risk_hig)
    rule1_29 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_hig),
                zf_fit_med), risk_med)
    rule1_30 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_hig),
                zf_fit_low), risk_med)

    rule1_31 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_32 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_med),
                zf_fit_med), risk_med)
    rule1_33 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_med),
                zf_fit_low), risk_med)

    rule1_34 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_low),
                zf_fit_hig), risk_med)
    rule1_35 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_low),
                zf_fit_med), risk_med)
    rule1_36 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_hig), gb_fit_low),
                zf_fit_low), risk_med)

    rule1_37 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_hig),
                zf_fit_hig), risk_hig)
    rule1_38 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_hig),
                zf_fit_med), risk_hig)
    rule1_39 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_hig),
                zf_fit_low), risk_hig)

    rule1_40 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_41 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_med),
                zf_fit_med), risk_hig)
    rule1_42 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_43 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_low),
                zf_fit_hig), risk_hig)
    rule1_44 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_low),
                zf_fit_med), risk_hig)
    rule1_45 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_med), gb_fit_low),
                zf_fit_low), risk_med)

    rule1_46 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_hig),
                zf_fit_hig), risk_very_hig)
    rule1_47 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_hig),
                zf_fit_med), risk_hig)
    rule1_48 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_hig),
                zf_fit_low), risk_hig)

    rule1_49 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_50 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_med),
                zf_fit_med), risk_hig)
    rule1_51 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_52 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_low),
                zf_fit_hig), risk_hig)
    rule1_53 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_low),
                zf_fit_med), risk_hig)
    rule1_54 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_med, gs_fit_low), gb_fit_low),
                zf_fit_low), risk_hig)

    rule1_55 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_hig),
                zf_fit_hig), risk_hig)
    rule1_56 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_hig),
                zf_fit_med), risk_hig)
    rule1_57 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_hig),
                zf_fit_low), risk_hig)

    rule1_58 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_59 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_med),
                zf_fit_med), risk_hig)
    rule1_60 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_61 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_low),
                zf_fit_hig), risk_hig)
    rule1_62 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_low),
                zf_fit_med), risk_hig)
    rule1_63 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_hig), gb_fit_low),
                zf_fit_low), risk_med)

    rule1_64 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_hig),
                zf_fit_hig), risk_very_hig)
    rule1_65 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_hig),
                zf_fit_med), risk_hig)
    rule1_66 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_hig),
                zf_fit_low), risk_hig)

    rule1_67 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_med),
                zf_fit_hig), risk_hig)
    rule1_68 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_med),
                zf_fit_med), risk_hig)
    rule1_69 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_70 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_low),
                zf_fit_hig), risk_hig)
    rule1_71 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_low),
                zf_fit_med), risk_hig)
    rule1_72 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_med), gb_fit_low),
                zf_fit_low), risk_hig)

    rule1_73 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_hig),
                zf_fit_low), risk_hig)
    rule1_74 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_hig),
                zf_fit_hig), risk_very_hig)
    rule1_75 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_hig),
                zf_fit_med), risk_very_hig)

    rule1_76 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_med),
                zf_fit_hig), risk_very_hig)
    rule1_77 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_med),
                zf_fit_med), risk_very_hig)
    rule1_78 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_med),
                zf_fit_low), risk_hig)

    rule1_79 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_low),
                zf_fit_hig), risk_very_hig)
    rule1_80 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_low),
                zf_fit_med), risk_very_hig)
    rule1_81 = np.fmin(
        np.fmin(np.fmin(np.fmin(ph_fit_low, gs_fit_low), gb_fit_low),
                zf_fit_low), risk_hig)

    #ED KÇ I

    rule2_1 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_low), i_fit_low),
        risk_hig)
    rule2_2 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_low), i_fit_med),
        risk_hig)
    rule2_3 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_low), i_fit_hig),
        risk_hig)

    rule2_4 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_low), i_fit_low),
                      risk_hig)
    rule2_5 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_low), i_fit_med),
                      risk_med)
    rule2_6 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_low), i_fit_hig),
                      risk_med)

    rule2_7 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_med), i_fit_low),
                      risk_med)
    rule2_8 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_med), i_fit_med),
                      risk_med)
    rule2_9 = np.fmin(np.fmin(np.fmin(ed_fit_very_low, kc_fit_med), i_fit_hig),
                      risk_med)

    rule2_10 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_hig), i_fit_low), risk_med)
    rule2_11 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_hig), i_fit_med), risk_med)
    rule2_12 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_hig), i_fit_hig), risk_low)

    rule2_13 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_hig), i_fit_low),
        risk_med)
    rule2_14 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_hig), i_fit_med),
        risk_low)
    rule2_15 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_low, kc_fit_very_hig), i_fit_hig),
        risk_low)

    rule2_16 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_low), i_fit_low), risk_hig)
    rule2_17 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_low), i_fit_med), risk_hig)
    rule2_18 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_low), i_fit_hig), risk_med)

    rule2_19 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_low), i_fit_low),
                       risk_hig)
    rule2_20 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_low), i_fit_med),
                       risk_med)
    rule2_21 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_low), i_fit_hig),
                       risk_med)

    rule2_22 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_med), i_fit_low),
                       risk_med)
    rule2_23 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_med), i_fit_med),
                       risk_med)
    rule2_24 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_med), i_fit_hig),
                       risk_med)

    rule2_25 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_hig), i_fit_low),
                       risk_med)
    rule2_26 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_hig), i_fit_med),
                       risk_low)
    rule2_27 = np.fmin(np.fmin(np.fmin(ed_fit_low, kc_fit_hig), i_fit_hig),
                       risk_low)

    rule2_28 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_hig), i_fit_low), risk_low)
    rule2_29 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_hig), i_fit_med), risk_low)
    rule2_30 = np.fmin(
        np.fmin(np.fmin(ed_fit_low, kc_fit_very_hig), i_fit_hig), risk_low)

    rule2_31 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_low), i_fit_low), risk_hig)
    rule2_32 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_low), i_fit_med), risk_med)
    rule2_33 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_low), i_fit_hig), risk_med)

    rule2_34 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_low), i_fit_low),
                       risk_med)
    rule2_35 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_low), i_fit_med),
                       risk_med)
    rule2_36 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_low), i_fit_hig),
                       risk_med)

    rule2_37 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_med), i_fit_low),
                       risk_med)
    rule2_38 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_med), i_fit_med),
                       risk_med)
    rule2_39 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_med), i_fit_hig),
                       risk_low)

    rule2_40 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_hig), i_fit_low),
                       risk_med)
    rule2_41 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_hig), i_fit_med),
                       risk_low)
    rule2_42 = np.fmin(np.fmin(np.fmin(ed_fit_med, kc_fit_hig), i_fit_hig),
                       risk_low)

    rule2_43 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_hig), i_fit_low), risk_low)
    rule2_44 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_hig), i_fit_med), risk_low)
    rule2_45 = np.fmin(
        np.fmin(np.fmin(ed_fit_med, kc_fit_very_hig), i_fit_hig),
        risk_very_low)

    rule2_46 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_low), i_fit_low), risk_med)
    rule2_47 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_low), i_fit_med), risk_med)
    rule2_48 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_low), i_fit_hig), risk_med)

    rule2_49 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_low), i_fit_low),
                       risk_med)
    rule2_50 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_low), i_fit_med),
                       risk_med)
    rule2_51 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_low), i_fit_hig),
                       risk_low)

    rule2_52 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_med), i_fit_low),
                       risk_med)
    rule2_53 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_med), i_fit_med),
                       risk_low)
    rule2_54 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_med), i_fit_hig),
                       risk_low)

    rule2_55 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_hig), i_fit_low),
                       risk_low)
    rule2_56 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_hig), i_fit_med),
                       risk_low)
    rule2_57 = np.fmin(np.fmin(np.fmin(ed_fit_hig, kc_fit_hig), i_fit_hig),
                       risk_low)

    rule2_58 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_hig), i_fit_low), risk_low)
    rule2_59 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_hig), i_fit_med), risk_low)
    rule2_60 = np.fmin(
        np.fmin(np.fmin(ed_fit_hig, kc_fit_very_hig), i_fit_hig),
        risk_very_low)

    rule2_61 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_low), i_fit_low),
        risk_med)
    rule2_62 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_low), i_fit_med),
        risk_med)
    rule2_63 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_low), i_fit_hig),
        risk_med)

    rule2_64 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_low), i_fit_low), risk_med)
    rule2_65 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_low), i_fit_med), risk_low)
    rule2_66 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_low), i_fit_hig), risk_low)

    rule2_67 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_med), i_fit_low), risk_low)
    rule2_68 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_med), i_fit_med), risk_low)
    rule2_69 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_med), i_fit_hig), risk_low)

    rule2_70 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_hig), i_fit_low), risk_low)
    rule2_71 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_hig), i_fit_med), risk_low)
    rule2_72 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_hig), i_fit_hig),
        risk_very_low)

    rule2_73 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_hig), i_fit_low),
        risk_low)
    rule2_74 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_hig), i_fit_med),
        risk_very_low)
    rule2_75 = np.fmin(
        np.fmin(np.fmin(ed_fit_very_hig, kc_fit_very_hig), i_fit_hig),
        risk_very_low)

    rule2_111 = np.fmin(ed_fit_very_hig, risk_very_low)
    rule2_112 = np.fmin(ed_fit_hig, risk_low)
    rule2_113 = np.fmin(ed_fit_med, risk_med)
    rule2_114 = np.fmin(ed_fit_low, risk_hig)
    rule2_115 = np.fmin(ed_fit_very_low, risk_very_hig)

    rule2_211 = np.fmin(kc_fit_very_hig, risk_very_low)
    rule2_212 = np.fmin(kc_fit_very_hig, risk_low)
    rule2_213 = np.fmin(kc_fit_med, risk_med)
    rule2_214 = np.fmin(kc_fit_low, risk_hig)
    rule2_215 = np.fmin(kc_fit_very_low, risk_very_hig)

    rule2_311 = np.fmin(i_fit_hig, risk_low)
    rule2_312 = np.fmin(i_fit_med, risk_med)
    rule2_313 = np.fmin(i_fit_low, risk_hig)

    #PD GS Aİ

    rule3_1 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_low), ai_fit_very_hig),
        risk_med)

    rule3_2 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_low), ai_fit_very_low),
        risk_hig)

    rule3_3 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_med), ai_fit_very_hig),
        risk_med)

    rule3_4 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_med), ai_fit_very_low),
        risk_med)

    rule3_5 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_hig), ai_fit_very_hig),
        risk_med)

    rule3_6 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_low, gs_fit_hig), ai_fit_very_low),
        risk_med)

    rule3_7 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_low), ai_fit_very_hig), risk_med)

    rule3_8 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_low), ai_fit_very_low), risk_med)

    rule3_9 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_med), ai_fit_very_hig), risk_med)

    rule3_10 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_med), ai_fit_very_low), risk_med)

    rule3_11 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_hig), ai_fit_very_hig), risk_low)

    rule3_12 = np.fmin(
        np.fmin(np.fmin(pd_fit_low, gs_fit_hig), ai_fit_very_low), risk_med)

    rule3_13 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_low), ai_fit_very_hig), risk_med)

    rule3_14 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_low), ai_fit_very_low), risk_med)

    rule3_15 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_med), ai_fit_very_hig), risk_low)

    rule3_16 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_med), ai_fit_very_low), risk_med)

    rule3_17 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_hig), ai_fit_very_hig), risk_low)

    rule3_18 = np.fmin(
        np.fmin(np.fmin(pd_fit_med, gs_fit_hig), ai_fit_very_low), risk_low)

    rule3_19 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_low), ai_fit_very_hig), risk_low)

    rule3_20 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_low), ai_fit_very_low), risk_med)

    rule3_21 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_med), ai_fit_very_hig), risk_low)

    rule3_22 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_med), ai_fit_very_low), risk_low)

    rule3_23 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_hig), ai_fit_very_hig), risk_low)

    rule3_24 = np.fmin(
        np.fmin(np.fmin(pd_fit_hig, gs_fit_hig), ai_fit_very_low), risk_low)

    rule3_25 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_low), ai_fit_very_hig),
        risk_low)

    rule3_26 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_low), ai_fit_very_low),
        risk_med)

    rule3_27 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_med), ai_fit_very_hig),
        risk_low)

    rule3_28 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_med), ai_fit_very_low),
        risk_low)

    rule3_29 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_hig), ai_fit_very_hig),
        risk_very_low)

    rule3_30 = np.fmin(
        np.fmin(np.fmin(pd_fit_very_hig, gs_fit_hig), ai_fit_very_low),
        risk_low)

    rule31 = np.fmin(pd_fit_very_low, risk_very_hig)
    rule32 = np.fmin(pd_fit_low, risk_hig)
    rule33 = np.fmin(pd_fit_med, risk_med)
    rule34 = np.fmin(pd_fit_hig, risk_low)
    rule35 = np.fmin(pd_fit_very_hig, risk_very_low)

    rule36 = np.fmin(gs_fit_low, risk_hig)
    rule37 = np.fmin(gs_fit_med, risk_med)
    rule38 = np.fmin(gs_fit_hig, risk_low)
    rule39 = np.fmin(ai_fit_very_low, risk_very_hig)  # adim adim ilerleme
    rule310 = np.fmin(ai_fit_very_hig, risk_very_low)

    # Birleşim kümelerinin oluşturulması

    list_very_hig = [
        rule1_46, rule1_64, rule1_74, rule1_75, rule1_76, rule1_77, rule1_79,
        rule1_80, rule1_78, rule2_19, rule31, rule39, rule2_115, rule2_215
    ]

    list_hig = [
        rule1_10, rule1_19, rule1_20, rule1_21, rule1_22, rule1_23, rule1_24,
        rule1_25, rule1_26, rule1_28, rule1_31, rule1_37, rule1_38, rule1_39,
        rule1_40, rule1_41, rule1_42, rule1_43, rule1_44, rule1_47, rule1_48,
        rule1_49, rule1_50, rule1_51, rule1_52, rule1_53, rule1_54, rule1_55,
        rule1_56, rule1_57, rule1_58, rule1_59, rule1_60, rule1_61, rule1_62,
        rule1_65, rule1_66, rule1_67, rule1_68, rule1_69, rule1_70, rule1_71,
        rule1_72, rule1_73, rule1_79, rule1_81, rule2_1, rule2_2, rule2_3,
        rule2_4, rule2_16, rule2_17, rule2_31, rule3_2, rule32, rule36,
        rule2_114, rule2_214, rule2_313, rule13, rule14, rule19, rule110
    ]

    list_med = [
        rule1_1, rule1_2, rule1_3, rule1_4, rule1_5, rule1_6, rule1_7, rule1_8,
        rule1_11, rule1_12, rule1_13, rule1_14, rule1_15, rule1_16, rule1_17,
        rule1_18, rule1_27, rule1_29, rule1_30, rule1_32, rule1_33, rule1_34,
        rule1_35, rule1_36, rule1_45, rule1_63, rule2_5, rule2_6, rule2_7,
        rule2_8, rule2_9, rule2_10, rule2_11, rule2_13, rule2_18, rule2_20,
        rule2_21, rule2_22, rule2_23, rule2_24, rule2_25, rule2_32, rule2_33,
        rule2_34, rule2_35, rule2_36, rule2_37, rule2_38, rule2_40, rule2_46,
        rule2_47, rule2_48, rule2_49, rule2_50, rule2_52, rule2_61, rule2_62,
        rule2_63, rule2_64, rule3_1, rule3_3, rule3_4, rule3_5, rule3_6,
        rule3_7, rule3_8, rule3_9, rule3_10, rule3_12, rule3_13, rule3_14,
        rule3_16, rule3_20, rule3_26, rule33, rule37, rule2_113, rule2_213,
        rule2_312, rule12, rule15, rule18, rule111
    ]
    list_low = [
        rule2_12, rule2_14, rule2_15, rule2_26, rule2_27, rule2_28, rule2_29,
        rule2_30, rule2_39, rule2_41, rule2_42, rule2_43, rule2_44, rule2_51,
        rule2_53, rule2_54, rule2_55, rule2_56, rule2_57, rule2_58, rule2_59,
        rule2_65, rule2_66, rule2_67, rule2_68, rule2_69, rule2_70, rule2_71,
        rule2_73, rule3_11, rule3_15, rule3_17, rule3_18, rule3_19, rule3_21,
        rule3_22, rule3_23, rule3_24, rule3_25, rule3_27, rule3_28, rule3_30,
        rule1_9, rule34, rule38, rule2_112, rule2_212, rule2_311, rule16,
        rule17, rule112
    ]
    list_very_low = [
        rule2_45, rule2_60, rule2_72, rule2_74, rule2_75, rule3_29, rule35,
        rule310, rule2_111, rule2_211, rule11
    ]

    out_very_hig = []
    out_hig = []
    out_med = []
    out_low = []
    out_very_low = []

    n = 0
    first = list_very_hig[n]
    for n in range(len(list_very_hig) - 1):
        out_very_hig = np.fmax(first, list_very_hig[n + 1])
        first = out_very_hig

    n = 0
    first = list_hig[n]
    for n in range(len(list_hig) - 1):
        out_hig = np.fmax(first, list_hig[n + 1])
        first = out_hig

    n = 0
    first = list_med[n]
    for n in range(len(list_med) - 1):
        out_med = np.fmax(first, list_med[n + 1])
        first = out_med

    n = 0
    first = list_low[n]
    for n in range(len(list_low) - 1):
        out_low = np.fmax(first, list_low[n + 1])
        first = out_low

    n = 0
    first = list_very_low[n]
    for n in range(len(list_very_low) - 1):
        out_very_low = np.fmax(first, list_very_low[n + 1])
        first = out_very_low

    # Veri görselleştirme

    risk0 = np.zeros_like(risk)

    fig, ax11 = plt.subplots(figsize=(10, 4))

    ax11.fill_between(risk, risk0, out_very_hig, facecolor='r', alpha=0.7)
    ax11.plot(risk, out_very_hig, 'r', linestyle='--')

    ax11.fill_between(risk, risk0, out_hig, facecolor='g', alpha=0.7)
    ax11.plot(risk, out_hig, 'k', linestyle='--')

    ax11.fill_between(risk, risk0, out_med, facecolor='g', alpha=0.7)
    ax11.plot(risk, out_med, 'y', linestyle='--')

    ax11.fill_between(risk, risk0, out_low, facecolor='g', alpha=0.7)
    ax11.plot(risk, out_low, 'y', linestyle='--')

    ax11.fill_between(risk, risk0, out_very_low, facecolor='g', alpha=0.7)
    ax11.plot(risk, out_very_low, 'y', linestyle='--')
    ax11.set_title('Risk Çıkışı')

    plt.tight_layout()

    # Durulaştırma

    out_list = [out_very_hig, out_hig, out_med, out_low, out_very_low]

    n = 0
    first = out_list[n]
    for n in range(len(out_list) - 1):
        out_risk = np.fmax(first, out_list[n + 1])
        first = out_risk

    defuzzified = fuzz.defuzz(risk, out_risk, 'centroid')

    result = fuzz.interp_membership(risk, out_risk, defuzzified)

    # Sonuç

    print("Başarı Değeri:", defuzzified)
    myLabel = tk.Label(root, text=100 - defuzzified, font=("Calibri", 13))
    myLabel.place(relwidth=0.22, relheight=0.08, relx=0.75, rely=0.8)

    # Veri Görselleştirme

    risk0 = np.zeros_like(risk)
    fig, ax10 = plt.subplots(figsize=(7, 4))

    ax10.plot(risk, out_very_hig, 'b', linewidth=0.5, linestyle='--')
    ax10.plot(risk, out_hig, 'b', linewidth=0.5, linestyle='--')
    ax10.plot(risk, out_med, 'b', linewidth=0.5, linestyle='--')
    ax10.plot(risk, out_low, 'b', linewidth=0.5, linestyle='--')
    ax10.plot(risk, out_very_low, 'b', linewidth=0.5, linestyle='--')
    ax10.fill_between(risk, risk0, out_risk, facecolor='Orange', alpha=0.7)
    ax10.plot([defuzzified, defuzzified], [0, result],
              'k',
              linewidth=1.5,
              alpha=0.9)
    ax10.set_title('Ağırlık Merkezi ile Durulaştırma')

    plt.tight_layout()
    plt.show()

    return defuzzified
    def __init__(self):
        # Create input and output variables
        self.lsonar = ctrl.Antecedent(self.sonar_interval, 'lsonar')
        self.rsonar = ctrl.Antecedent(self.sonar_interval, 'rsonar')
        self.last_theta = ctrl.Antecedent(self.theta_interval, 'last_theta')
        self.theta = ctrl.Consequent(self.theta_interval, 'theta')
        self.v_x = ctrl.Consequent(self.v_interval, 'v_x')

        # we need membership functions!
        distance_levels = ['dangerous', 'unsafe', 'safe']
        theta_directions = ['left', 'centre', 'right']
        velocity_levels = ['slow', 'medium', 'fast']

        self.lsonar.automf(names=distance_levels)
        self.rsonar.automf(names=distance_levels)
        self.last_theta.automf(names=theta_directions)
        self.theta.automf(names=theta_directions)
        self.v_x.automf(names=velocity_levels)

        low_mshp = mshp.trimf(self.sonar_interval, [0.25, 0.25, 0.31])
        mid_mshp = mshp.trimf(self.sonar_interval, [0.28, 0.35, 0.45])
        high_mshp = mshp.trapmf(self.sonar_interval, [0.4, 0.6, 2.55, 2.55])

        self.lsonar['dangerous'] = low_mshp
        self.lsonar['unsafe'] = mid_mshp
        self.lsonar['safe'] = high_mshp

        self.rsonar['dangerous'] = low_mshp
        self.rsonar['unsafe'] = mid_mshp
        self.rsonar['safe'] = high_mshp

        left_angle_mshp = mshp.gaussmf(self.theta_interval, 0.7, 0.2)
        centre_angle_mshp = mshp.gaussmf(self.theta_interval, 0, 0.1)
        right_angle_mshp = mshp.gaussmf(self.theta_interval, -0.7, 0.2)
        
        self.theta['left'] = left_angle_mshp
        self.theta['centre'] = centre_angle_mshp
        self.theta['right'] = right_angle_mshp

        self.last_theta['left'] = left_angle_mshp
        self.last_theta['centre'] = centre_angle_mshp
        self.last_theta['right'] = right_angle_mshp

        self.v_x['slow'] = mshp.trimf(self.v_interval, [0, 0, 0.32])
        self.v_x['medium'] = mshp.gaussmf(self.v_interval, 0.5, 0.36)
        self.v_x['fast'] = mshp.trapmf(self.v_interval, [0.75, 0.95, 1.0, 1.0])

        # Here the rules are defined!
        # look at http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_control_system_advanced.html#set-up-the-fuzzy-control-system
        # and http://pythonhosted.org/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html
        # for good examples
        rules = []

        # Sonars are NOT dangerous, go fast and forward
        rules.append(ctrl.Rule(label="FastAndForward", 
                               antecedent=(~self.lsonar['dangerous'] & ~self.rsonar['dangerous']), 
                               consequent=(self.theta['centre'], self.v_x['fast'])))

        # Right sonar reads dangerous, left does not, steer left
        rules.append(ctrl.Rule(label="SteerLeftCaution", 
                               antecedent=(~self.lsonar['dangerous'] & self.rsonar['dangerous']), 
                               consequent=(self.theta['left'], self.v_x['slow'])))
        # Left sonar reads dangerous, right does not, steer left
        rules.append(ctrl.Rule(label="SteerRightCaution", 
                               antecedent=(self.lsonar['dangerous'] & ~self.rsonar['dangerous']), 
                               consequent=(self.theta['right'], self.v_x['slow'])))

        # Right sonar is NOT safe, left reads safe, turn left full speed
        rules.append(ctrl.Rule(label="SteerLeftReckless", 
                               antecedent=(self.lsonar['safe'] & ~self.rsonar['safe']), 
                               consequent=(self.theta['left'], self.v_x['fast'])))
        # Left sonar is NOT safe, right reads safe, turn right full speed
        rules.append(ctrl.Rule(label="SteerRightReckless", 
                               antecedent=(~self.lsonar['safe'] & self.rsonar['safe']), 
                               consequent=(self.theta['right'], self.v_x['fast'])))

        # Left sonar is NOT dangerous and right is NOT safe, turn left medium speed
        rules.append(ctrl.Rule(label="SteerLeftWatchSpeed", 
                               antecedent=(~self.lsonar['dangerous'] & ~self.rsonar['safe']), 
                               consequent=(self.theta['left'], self.v_x['medium'])))
        # Right sonar is NOT dangerous and left is NOT safe, turn right medium speed
        rules.append(ctrl.Rule(label="SteerRightWatchSpeed", 
                               antecedent=(~self.lsonar['safe'] & ~self.rsonar['dangerous']), 
                               consequent=(self.theta['right'], self.v_x['medium'])))

        # Last theta was right, right sonar is dangerous, turn left slow speed
        rules.append(ctrl.Rule(label="SteerLeftMedSpeed", 
                               antecedent=(self.rsonar['dangerous'] & self.last_theta['right']), 
                               consequent=(self.theta['left'], self.v_x['medium'])))
        # Last theta was left, left sonar is dangerous, turn right slow speed
        rules.append(ctrl.Rule(label="SteerRightMedSpeed", 
                               antecedent=(self.lsonar['dangerous'] & self.last_theta['left']), 
                               consequent=(self.theta['right'], self.v_x['medium'])))

        # Last theta was left, rsonar reads not dangerous, turn centre, full speed
        rules.append(ctrl.Rule(label="OutOfDangerFromLeft", 
                               antecedent=(~self.rsonar['dangerous'] & self.last_theta['left']), 
                               consequent=(self.theta['centre'], self.v_x['fast'])))
        # Last theta was right, lsonar reads not dangerous, turn centre, full speed
        rules.append(ctrl.Rule(label="OutOfDangerFromRight", 
                               antecedent=(~self.lsonar['dangerous'] & self.last_theta['right']), 
                               consequent=(self.theta['centre'], self.v_x['fast'])))

        # Create the control system
        self.system = ctrl.ControlSystem(rules=rules)

        # System is created, just create a simulation, input values and call compute()
        self.sim = ctrl.ControlSystemSimulation(self.system)
import numpy as np
from skfuzzy import control as ctrl
from skfuzzy import membership as mf

speed = ctrl.Antecedent(np.arange(0, 85, 0.1), 'speed')
distance = ctrl.Antecedent(np.arange(0, 3000, 0.5), 'distance')
brake = ctrl.Consequent(np.arange(0, 100, 0.5), 'brake')
throttle = ctrl.Consequent(np.arange(0, 100, 0.5), 'throttle')

speed['stopped'] = mf.trimf(speed.universe, [0, 0, 2])
speed['very slow'] = mf.trimf(speed.universe, [1, 2.5, 4])
speed['slow'] = mf.trimf(speed.universe, [2.5, 6.5, 10.5])
speed['medium fast'] = mf.trimf(speed.universe, [6.5, 26.5, 46.5])
speed['fast'] = mf.trapmf(speed.universe, [26.5, 70, 85, 85])

distance['at'] = mf.trimf(distance.universe, [0, 0, 2])
distance['very near'] = mf.trimf(distance.universe, [1, 3, 5])
distance['near'] = mf.trimf(distance.universe, [3, 101.5, 200])
distance['medium far'] = mf.trimf(distance.universe, [100, 1550, 3000])
distance['far'] = mf.trapmf(distance.universe, [1500, 2250, 3000, 3000])

brake['no'] = mf.trimf(brake.universe, [0, 0, 40])
brake['very slight'] = mf.trimf(brake.universe, [20, 50, 80])
brake['slight'] = mf.trimf(brake.universe, [70, 83.5, 97])
brake['medium'] = mf.trimf(brake.universe, [95, 97, 99])
brake['full'] = mf.trimf(brake.universe, [98, 100, 100])

throttle['no'] = mf.trimf(throttle.universe, [0, 0, 2])
throttle['very slight'] = mf.trimf(throttle.universe, [1, 3, 5])
throttle['slight'] = mf.trimf(throttle.universe, [3, 16.5, 30])
throttle['medium'] = mf.trimf(throttle.universe, [20, 50, 80])
示例#14
0
plt.scatter(df_date, df_avg, color='red')
plt.plot(df_date, lr.predict(df_date), color='blue')
plt.show()

egim = tahmin[1] - tahmin[0]
print('Eğim:', egim)

egim = egim + 1
egim100 = (100 * egim) / 2

print(egim100)

#4le çarptıkkkkk
x_std = np.arange(0, 101, 1)
std_low = mf.trimf(x_std, [0, 28, 56])
std_med = mf.trimf(x_std, [28, 56, 84])
std_high = mf.trimf(x_std, [56, 84, 100000])

x_egim = np.arange(0, 101, 1)
egim_inc = mf.trimf(x_egim, [0, 100, 100])
egim_dec = mf.trimf(x_egim, [0, 0, 100])

x_risk = np.arange(0, 101, 1)
risk_az = mf.trimf(x_risk, [0, 0, 50])
risk_orta = mf.trimf(x_risk, [30, 50, 70])
risk_cok = mf.trimf(x_risk, [50, 100, 100])

plt.set_title = 'Egim'
plt.plot(x_egim, egim_inc, 'r', linewidth=2, label="Artan")
plt.plot(x_egim, egim_dec, 'b', linewidth=2, label="Azalan")
plt.scatter(df_date, df_avg, color='red')
plt.plot(df_date, lr.predict(df_date), color='blue')
plt.show()

# calculate slope with predicted data
slope = prediction[1] - prediction[0]
print('Slope:', slope)

# formula for linear regression slope in stock market
slope = slope + 1
slope100 = (100 * slope) / 2
#print(slope100)

# computes standart deviation values using a triangular membership function
x_std = np.arange(0, 101, 1)
std_low = mf.trimf(x_std, [0, 28, 56])
std_med = mf.trimf(x_std, [28, 56, 84])
std_high = mf.trimf(x_std, [56, 84, 100000])

# computes slope values using a triangular membership function
x_slope = np.arange(0, 101, 1)
slope_inc = mf.trimf(x_slope, [0, 100, 100])
slope_dec = mf.trimf(x_slope, [0, 0, 100])

# computes risk values using a triangular membership function
x_risk = np.arange(0, 101, 1)
low_risk = mf.trimf(x_risk, [0, 0, 50])
med_risk = mf.trimf(x_risk, [30, 50, 70])
high_risk = mf.trimf(x_risk, [50, 100, 100])

plt.set_title = 'Slope'
示例#16
0
# -*- coding: utf-8 -*-

import numpy as np
import skfuzzy as fuzz
import skfuzzy.membership as mf
import matplotlib.pyplot as plt

# Değişkenlerin oluşturulması

x_pedal = np.arange(0, 101, 1)
x_speed = np.arange(0, 101, 1)
y_brake = np.arange(0, 101, 1)

# Üyelik fonksiyonlarının oluşturulması

pedal_low = mf.trimf(x_pedal, [0, 0, 50])
pedal_med = mf.trimf(x_pedal, [0, 50, 100])
pedal_hig = mf.trimf(x_pedal, [50, 100, 100])

speed_low = mf.trimf(x_pedal, [0, 0, 60])
speed_med = mf.trimf(x_pedal, [20, 50, 80])
speed_hig = mf.trimf(x_pedal, [40, 100, 100])

brake_poor = mf.trimf(y_brake, [0, 0, 100])
brake_strong = mf.trimf(y_brake, [0, 100, 100])

# Veri görselleştirme

fig, (ax0, ax1, ax2) = plt.subplots(nrows=3, figsize=(6, 10))

ax0.plot(x_pedal, pedal_low, 'r', linewidth=2, label='Düşük')
示例#17
0
 def __estimate(self, abc):
     euro_courses = np.asarray([self.euro_course])
     response = trimf(euro_courses, abc)
     return response[0]
示例#18
0
# In[45]:


x_bodytemp = np.arange(20, 50 , 1)
x_respiratory = np.arange(0, 50 , 1)
x_pulse = np.arange(0, 150 , 1)
y_areacolour = np.arange(0, 4, 1)


# In[46]:


bodytemp_verylow = mf.trapmf(x_bodytemp, [-100, 0, 30, 34.5])
bodytemp_low = mf.trapmf(x_bodytemp, [0, 34.5, 35 ,36 ])
bodytemp_normal = mf.trimf(x_bodytemp, [36, 36.5, 37])
bodytemp_high = mf.trapmf(x_bodytemp, [36, 38, 41, 42])
bodytemp_veryhigh = mf.trapmf(x_bodytemp, [41, 42,45, 100])


# In[47]:


respiratory_low = mf.trimf(x_respiratory, [-100, 0, 12])
respiratory_normal = mf.trapmf(x_respiratory, [8, 12, 20, 24])
respiratory_high = mf.trimf(x_respiratory, [20, 50, 100])


# In[48]:

import numpy as np
from skfuzzy import control as ctrl
from skfuzzy import membership as mf
import matplotlib.pyplot as plt

service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
food = ctrl.Antecedent(np.arange(0, 11, 1), 'food')
tips = ctrl.Consequent(np.arange(0, 31, 1), 'tips')

# service['poor'] = mf.trimf(service.universe, [0, 0, 5])
# service['average'] = mf.trimf(service.universe, [0, 5, 10])
# service['good'] = mf.trimf(service.universe, [5, 10, 10])
service['poor'] = mf.trimf(service.universe, [0, 0, 3])
service['average'] = mf.trimf(service.universe, [2, 5, 8])
service['good'] = mf.trimf(service.universe, [6, 10, 10])

food['poor'] = mf.trimf(food.universe, [0, 0, 5])
food['average'] = mf.trimf(food.universe, [0, 5, 10])
food['good'] = mf.trimf(food.universe, [5, 10, 10])

tips['low'] = mf.trimf(tips.universe, [0, 0, 15])
tips['medium'] = mf.trimf(tips.universe, [0, 15, 30])
tips['high'] = mf.trimf(tips.universe, [15, 30, 30])

rule1 = ctrl.Rule(service['poor'] & food['poor'], tips['low'])
rule2 = ctrl.Rule(service['poor'] & food['average'], tips['low'])
rule3 = ctrl.Rule(service['poor'] & food['good'], tips['medium'])
rule4 = ctrl.Rule(service['average'] & food['poor'], tips['low'])
rule5 = ctrl.Rule(service['average'] & food['average'], tips['medium'])
rule6 = ctrl.Rule(service['average'] & food['good'], tips['high'])
rule7 = ctrl.Rule(service['good'] & food['poor'], tips['medium'])