Exemplo n.º 1
0
def fuzzyOutputSystem(A, B, A1):
    R = []
    for i in range(0, int(A.size / A[0].size)):
        R.append(fuzzy.relation_min(A[i], B[i]))
    R = numpy.array(R)
    mx = -100
    R_max = []
    h = []
    count = 0

    for i in range(0, int(R[0].size / R[0][0].size)):
        for j in range(0, int(R[0][0].size)):
            for k in range(0, int(R.size / R[0].size)):
                if mx < R[k][i][j]:
                    mx = R[k][i][j]
            h.append(mx)
            mx = -100
            count += 1
            if len(h) == int(R[0][0].size):
                R_max.append(h)
                h = []

    R_max = numpy.array(R_max)
    result = fuzzy.maxmin_composition(A1, R_max)
    return result
Exemplo n.º 2
0
def fuzzyOutput(A, B, A1):
    R = fuzzy.relation_min(A, B)
    if A1.size != R.size:
        for i in range(0, R.size - A1.size + 1):
            A1 = numpy.concatenate(
                (A1, numpy.array([numpy.zeros(R[0].size + 1)])))
    result = fuzzy.maxmin_composition(A1, R)
    return result
Exemplo n.º 3
0
print("Matriks Suhu:")
print(in_1)
print("")
print("Matriks Kelembaban:")
print(in_2)
print("")
print("Matriks CO:")
print(in_3)
print("")
print("Matriks NO2:")
print(in_4)

rul = []
for i in range(5):
    for j in range(5):
        rule = fuzz.relation_min(in_3[i], in_4[j])
        rul.append(rule)
        #print(rule)
penyebut = np.sum(rul)
#Pembilang
rul = []
for i in range(5):
    for j in range(5):
        rule = fuzz.relation_min(in_3[i], in_4[j])
        rulxx = rule * FAM[i][j]
        rul.append(rulxx)
        #print(rulxx)
pembilang = np.sum(rul)
#print (pembilang)
#print (penyebut)
hasil = pembilang / penyebut
Exemplo n.º 4
0
    print("Rendah : " + str(in_3[2]))
#%%
print("Matriks Nilai wawancara")
print(in_1)
print("")
print("Matriks Nilai psikotes")
print(in_2)
print("Matriks Nilai tpa")
print(in_3)
#%%
#Inferensi dan Defazzifikasi dengan Metode Sugeno
#Penyebut
rul = []
for i in range(3):
    for j in range(3):
        rule = fuzz.relation_min(in_1[i], in_2[j])
        rul.append(rule)
penyebut = np.sum(rul)

#Pembilang
rul = []
for i in range(3):
    for j in range(3):
        rule = fuzz.relation_min(in_1[i], in_2[j])
        rulxx = rule * M[i][j]
        rul.append(rulxx)
pembilang = np.sum(rul)
hasil = pembilang / penyebut

print("Index Kelayakan Diterima  : " + str(hasil))
if hasil >= 0 and hasil <= 20:
Exemplo n.º 5
0
def ispu_prediction(input_suhu, input_kelembaban, input_CO, input_NO2):
    # Generate universe variables
    suhu = np.arange(0, 51, 1)
    kelembaban = np.arange(0, 101, 1)
    CO = np.arange(0, 101, 1)
    NO2 = np.arange(0, 12001, 1)

    # Generate fuzzy membership functions
    dingin = fuzz.trapmf(suhu, [0, 0, 18.5, 20.5])
    sejuk = fuzz.trimf(suhu, [18.5, 20.5, 22.8])
    nyaman = fuzz.trimf(suhu, [20.5, 22.8, 25.8])
    hangat = fuzz.trimf(suhu, [22.8, 25.8, 27.2])
    panas = fuzz.trapmf(suhu, [25.8, 27.2, 51, 51])

    sangat_kering = fuzz.trimf(kelembaban, [0, 15, 25])
    kering = fuzz.trimf(kelembaban, [15, 25, 45])
    ideal = fuzz.trimf(kelembaban, [25, 45, 65])
    lembab = fuzz.trimf(kelembaban, [45, 65, 85])
    sangat_lembab = fuzz.trimf(kelembaban, [65, 85, 101])

    baik = fuzz.trimf(CO, [0, 7, 12])
    sedang = fuzz.trimf(CO, [10, 15, 25])
    tidak_sehat = fuzz.trimf(CO, [17, 25, 32])
    sangat_tidak_sehat = fuzz.trimf(CO, [25, 34, 46])
    berbahaya = fuzz.trapmf(CO, [34, 46, 101, 101])

    baik_x = fuzz.trapmf(NO2, [0, 15, 30, 35])
    sedang_x = fuzz.trapmf(NO2, [30, 35, 50, 75])
    tidak_sehat_x = fuzz.trimf(NO2, [55, 75, 85])
    sangat_tidak_sehat_x = fuzz.trimf(NO2, [75, 85, 100])
    berbahaya_x = fuzz.trapmf(NO2, [100, 120, 150, 300])

    BA = 50
    SE = 100
    TS = 199
    STS = 299
    BE = 500

    BA = 50
    SE = 100
    TS = 199
    STS = 299
    BE = 500
    FAM = [[BA, SE, TS, STS, BE], [SE, SE, TS, STS, BE], [TS, TS, TS, STS, BE],
           [STS, STS, STS, STS, BE], [BE, BE, BE, BE, BE]]

    suhu_wilayah = int(input_suhu)
    kelembaban_wilayah = int(input_kelembaban)
    CO_wilayah = int(input_CO) * 11.5 / 1000
    NO2_wilayah = int(input_NO2) * 1.88

    in_1 = []
    in_1.append(fuzz.interp_membership(suhu, dingin, suhu_wilayah))
    in_1.append(fuzz.interp_membership(suhu, sejuk, suhu_wilayah))
    in_1.append(fuzz.interp_membership(suhu, nyaman, suhu_wilayah))
    in_1.append(fuzz.interp_membership(suhu, hangat, suhu_wilayah))
    in_1.append(fuzz.interp_membership(suhu, panas, suhu_wilayah))

    in_2 = []
    in_2.append(
        fuzz.interp_membership(kelembaban, sangat_kering, kelembaban_wilayah))
    in_2.append(fuzz.interp_membership(kelembaban, kering, kelembaban_wilayah))
    in_2.append(fuzz.interp_membership(kelembaban, ideal, kelembaban_wilayah))
    in_2.append(fuzz.interp_membership(kelembaban, lembab, kelembaban_wilayah))
    in_2.append(
        fuzz.interp_membership(kelembaban, sangat_lembab, kelembaban_wilayah))

    in_3 = []
    in_3.append(fuzz.interp_membership(CO, baik, CO_wilayah))
    in_3.append(fuzz.interp_membership(CO, sedang, CO_wilayah))
    in_3.append(fuzz.interp_membership(CO, tidak_sehat, CO_wilayah))
    in_3.append(fuzz.interp_membership(CO, sangat_tidak_sehat, CO_wilayah))
    in_3.append(fuzz.interp_membership(CO, berbahaya, CO_wilayah))

    in_4 = []
    in_4.append(fuzz.interp_membership(NO2, baik_x, NO2_wilayah))
    in_4.append(fuzz.interp_membership(NO2, sedang_x, NO2_wilayah))
    in_4.append(fuzz.interp_membership(NO2, tidak_sehat_x, NO2_wilayah))
    in_4.append(fuzz.interp_membership(NO2, sangat_tidak_sehat_x, NO2_wilayah))
    in_4.append(fuzz.interp_membership(NO2, berbahaya_x, NO2_wilayah))

    print("Derajat Keanggotaan Suhu:")
    if in_1[0] > 0:
        print("dingin :" + str(in_1[0]))
    if in_1[1] > 0:
        print("sejuk :" + str(in_1[1]))
    if in_1[2] > 0:
        print("nyaman :" + str(in_1[2]))
    if in_1[3] > 0:
        print("hangat :" + str(in_1[3]))
    if in_1[4] > 0:
        print("panas :" + str(in_1[4]))

    print("")
    print("Derajat Keanggotaan Kelembaban:")
    if in_2[0] > 0:
        print("sangat kering :" + str(in_2[0]))
    if in_2[1] > 0:
        print("kering :" + str(in_2[1]))
    if in_2[2] > 0:
        print("ideal :" + str(in_2[2]))
    if in_2[3] > 0:
        print("lembab :" + str(in_2[3]))
    if in_2[4] > 0:
        print("sangat lembab :" + str(in_2[4]))

    print("")
    print("Derajat Keanggotaan CO:")
    if in_3[0] > 0:
        print("baik :" + str(in_3[0]))
    if in_3[1] > 0:
        print("sedang :" + str(in_3[1]))
    if in_3[2] > 0:
        print("tidak sehat :" + str(in_3[2]))
    if in_3[3] > 0:
        print("sangat tidak sehat :" + str(in_3[3]))
    if in_3[4] > 0:
        print("berbahaya :" + str(in_3[4]))

    print("")
    print("Derajat Keanggotaan NO2:")
    if in_4[0] > 0:
        print("baik :" + str(in_4[0]))
    if in_4[1] > 0:
        print("sedang :" + str(in_4[1]))
    if in_4[2] > 0:
        print("tidak sehat :" + str(in_4[2]))
    if in_4[3] > 0:
        print("sangat tidak sehat :" + str(in_4[3]))
    if in_4[4] > 0:
        print("berbahaya :" + str(in_4[4]))

    print("Matriks Suhu:")
    print(in_1)
    print("")
    print("Matriks Kelembaban:")
    print(in_2)
    print("")
    print("Matriks CO:")
    print(in_3)
    print("")
    print("Matriks NO2:")
    print(in_4)

    rul = []
    for i in range(5):
        for j in range(5):
            rule = fuzz.relation_min(in_3[i], in_4[j])
            rul.append(rule)
            #print(rule)
    penyebut = np.sum(rul)
    #Pembilang
    rul = []
    for i in range(5):
        for j in range(5):
            rule = fuzz.relation_min(in_3[i], in_4[j])
            rulxx = rule * FAM[i][j]
            rul.append(rulxx)
            #print(rulxx)
    pembilang = np.sum(rul)
    #print (pembilang)
    #print (penyebut)
    hasil = pembilang / penyebut
    #print (hasil)

    #logic hasil
    print("ISPU :" + str(hasil))
    if hasil >= 0 and hasil <= 50.5:
        print("Baik")
    if hasil > 50.5 and hasil <= 100.5:
        print("Sedang")
    if hasil > 100.5 and hasil <= 199.5:
        print("Tidak Sehat")
    if hasil > 199.5 and hasil <= 299.5:
        print("Sangat Tidak Sehat")
    if hasil >= 299.5:
        print("Berbahaya")

    return hasil, suhu_wilayah, kelembaban_wilayah, CO_wilayah, NO2_wilayah