python中具有两个以上输入变量的模糊规则

2024-05-08 19:06:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用python构建一个模糊推理系统。我有4个变量,这取决于哪个输出类被决定。在

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)

价格的类似函数是:def priceClassification(D)。在

规则如下:

“如果酒店设施得分很好,到访人数很多,房间设施很好,价格比档次低就很好。”

我不懂如何编写规则。我看到的所有源都有一个输入和一个输出变量。但我的代码中不是这样。在

有谁能给我一个很好的资源或者关于如何编写这个规则的想法?在


Tags: rmcounthotelclassverymembershipgoodfacility