3
$\begingroup$

I am trying to build a fuzzy inference system in python using skfuzzy library. I have 4 variables depending on which output class is decided.

def fuzzInferenceself():

### Input ###
    hf_very_poor = fuzz.trimf(hotel_facility, [0, 0.15, 0.3])
    hf_poor = fuzz.trimf(hotel_facility, [2.5,0.3,0.45])
    hf_average = fuzz.trimf(hotel_facility, [0.4, 0.5, 0.75])
    hf_good = fuzz.trimf(hotel_facility, [0.7, 0.85, 0.9])
    hf_very_good = fuzz.trimf(hotel_facility, [0.875, 0.92, 1.0])
    vc_less = fuzz.trimf(visited_count, [0, 0.05, 0.1])
    vc_average = fuzz.trimf(visited_count, [0.05, 0.2, 0.35])
    vc_many = fuzz.trapmf(visited_count, [0.3,0.45,0.55,0.7])
    vc_a_lot = fuzz.trapmf(visited_count, [0.65,0.8,0.9,1.0])
    rm_very_poor = fuzz.trimf(hotel_facility, [0, 0.15, 0.3])
    rm_poor = fuzz.trimf(hotel_facility, [2.5,0.3,0.45])
    rm_average = fuzz.trimf(hotel_facility, [0.4, 0.5, 0.75])
    rm_good = fuzz.trimf(hotel_facility, [0.7, 0.8, 0.9])
    rm_very_good = fuzz.trimf(hotel_facility, [0.85, 0.9,1.0])

## output ####
    class_very_poor = fuzz.gaussmf(class_score,1,0.5)
    class_poor = fuzz.gaussmf(class_score,1.75,0.65)
    class_average = fuzz.gaussmf(class_score,2.25,0.75)
    class_good = fuzz.gaussmf(class_score,3,0.25)
    class_very_good = fuzz.gaussmf(class_score, 3.5, 0.5)


def hotelFaclilityClassification(self,A):
    hf_vp= fuzz.interp_membership(hotel_facility, hf_very_poor, A)
    hf_p= fuzz.interp_membership(hotel_facility, hf_poor, A)
    hf_av= fuzz.interp_membership(hotel_facility, hf_average, A)
    hf_gd= fuzz.interp_membership(hotel_facility, hf_good, A)
    hf_vg= fuzz.interp_membership(hotel_facility, hf_very_good, A) 
    return dict(hfVP = hf_vp, hfP = hf_p, hfAV = hf_av,hGD = hf_gd, hVG = hf_vg)

def visitCountClassification(B):
    vc_l = fuzz.interp_membership(visited_count,vc_less)
    vc_av = fuzz.interp_membership(visited_count,vc_average)
    vc_mn = fuzz.interp_membership(visited_count,vc_many)
    vc_al = fuzz.interp_membership(visited_count,vc_a_lot)
    return dict(vcL = vc_l, vcAV=vc_av, vcMN = vc_mn, vcAL = vc_al )

def roomFacilityClassification(C):
    rm_vp = fuzz.interp_membership(room_facility,rm_very_poor)
    rm_p =  fuzz.interp_membership(room_facility,rm_poor)
    rm_av = fuzz.interp_membership(room_facility,rm_average)
    rm_gd = fuzz.interp_membership(room_facility,rm_good)
    rm_vg = fuzz.interp_membership(room_facility,rm_very_good)
    return dict(rmVP = rm_vp, rmP = rm_p, rmAV = rm_av, rmGD = rm_gd, rmVG = rm_vg)

A similar function for price is: def priceClassification(D).

The rules are as follows:

"If Hotel facility score is Very good, visited count is alot, room facility is very good,prices is less then class is very good."

I do not understand how to code the rules. All sources I have seen takes one input and one output variable. But this is not the case in my code.

Can anyone give me a good resource or idea about how to code this rule?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.