1、直接定值:Yager与Semts的融合规则适用
2、计算加权因子:Dempster与Dubios&Prade的融合规则适用
3、自动学习加权因子
1.1.这里就先不详细写推导过程,本博文主要写的是程序复现这一部分
#基于通用框架的改进的Dempster方法 #本程序并不完善,过于冗余 # #如果想增加(减少)数据源的个数,那么需要在 def K(X_set,n)和def m(str_one) 函数下, #1、增加(减少)空集合,及set_1,set_2,这些是用来做 ∩ 运算 #2、增加(减少)for循环 #3、改变if条件语句 import math #1、首先说明辩框X set_List=['A','B','C']; X_set=set(set_List);#变成集合 empty_set=set();#这是一个空集 #2、列出不同证据源的bpa # m_1={'A':0.98,'B':0.01,'C':0.01}; # m_2={'A':0,'B':0.01,'C':0.99}; k=0.1;#固定值 #e=0.1,0.01,0.001,0.0001;#变化值 e=0.0001 z=1-k-e;#z+e+k=1 m_1={
'A':e,'B':k,'C':z}; m_2={
'A':z,'B':k,'C':e}; #3、计算K值即冲突质量m(ϕ) def K(X_set,n): sum=0.00; set_1=set(); set_2=set(); if(n<1): #print("只有一个证据,Fail!\n"); return -1; #print("当前有{0}个证据来源\n".format(n)); for m1 in X_set: set_1.add(m1); for m2 in X_set: set_2.add(m2); #print(type(set_2),set_2) if(set_1.intersection(set_2)==set()): #此时相交集合为空集合 sum+=m_1[m1]*m_2[m2]; set_2.clear() set_1.clear(); #print(sum); return sum; #4、计算m_∩(A) def m(str_one): i=1 sum=0.00 set_one=set(str_one);#将字符str_one放在一个集合中 set_2=set();#为了方便集合运算,创建一个临时的空集合 for m2 in m_2: set_2.add(m2); if(set_one.intersection(set_2)==set_one): sum+=m_1[str_one]*m_2[m2]; i+=1 set_2.clear(); #dict_one=dict.fromkeys(str_one,sum) #return dict_one return sum; #5、计算单个的加权因子w(A,m),A={H1,H2,H3} def weight_compute(X_set,n,str_one): m_insert=m(str_one); m_empty=K(X_set,n); if m_empty!=1: weights = m_insert / (1 - m_empty); else: print("Failed:m_empty=1") exit(0); return weights; #6、计算出所有的加权因子 #以字典的形式返回 def weight_Frame(X_set): n=2; dict_result=dict(); for str_one in X_set: values=weight_compute(X_set,n,str_one); values=round(values,4) dict_result.update(dict.fromkeys(str_one,values)); return dict_result; #7、计算出在通用框架下Dempster融合之后的值 def combination_Evidence(X_set,n): dict_weight=weight_Frame(X_set);#这是权重 dict_result=dict();#这是结果 sum=0.000 for str_item in X_set: m_insert=m(str_item);#M∩(H) m_empty=K(X_set,n);#M(∅) m_weight=weight_compute(X_set,n,str_item);#加权因子 sum=m_insert+m_weight*m_empty; #print("m_insert=",m_insert,"m_weight=",m_weight,"m_empty=",m_empty) #print("sum",sum) sum=round(sum,4) dict_result.update(dict.fromkeys(str_item,sum)); return dict_result; if __name__ == '__main__': print("**********加权因子***************\n"); print(weight_Frame(X_set)); print("\n"); print("**********融合后的结果***********\n") print(combination_Evidence(X_set, 2))
利用下面定义的w(A,m)的通用框架可以直接推改进的公式
#这是在通用框架下的Dubios&Prade规则 #这个新的规则之前没有写过原版的,就直接写改进的吧 #这个程序主要分为:m*、m_intersection、m_empty #1、确定辩框 theta=['A','B','C']; theta_set=set(theta); #2、确定证据源 k=0.1;#固定值 e=0.1;#变化值 z=1-k-e;#因变量 m_1={
'A':e,'B':k,'C':z}; m_2={
'A':z,'B':k,'C':e}; #2.1 抽取每一个证据源中的焦元,返回一个集合 def focal_Element(m_dict): key_m=[]; m_key=m_dict.keys(); for item in m_key: key_m.append(item) keym_set=set(key_m); return keym_set; #3、计算m_empty def computeEmpty(m_1,m_2,n): F1=focal_Element(m_1); F2=focal_Element(m_2); # 构造空集合 theta_set1 = set(); theta_set2 = set(); empty = set(); m_empty = 0.00 for item1 in F1: theta_set1.update(item1); for item2 in F2: theta_set2.update(item2); if (theta_set1.intersection(theta_set2) == empty): m_empty += m_1[item1] * m_2[item2]; theta_set2.clear(); theta_set1.clear(); return m_empty; #4、计算m* def computLocal(m_1,m_2,n,thetaSet): F1=focal_Element(m_1); F2=focal_Element(m_2); #空集合 f1_set=set(); f2_set=set(); empty=set(); m_local=dict(); for item1 in F1: f1_set.update(item1); for item2 in F2: f2_set.update(item2); if (f1_set.intersection(f2_set) == empty): if(f1_set.union(f2_set).intersection(thetaSet)!=empty): sum = m_1[item1] * m_2[item2]; str_=item1+"∪"+item2; str_copy=item2+"∪"+item1; #sum = round(sum, 4); if str_copy not in m_local.keys(): if str_ in m_local.keys(): m_local[str_] = sum; else: m_local[str_]=sum; else: m_local[str_copy]=m_local[str_copy]+sum; f2_set.clear(); f1_set.clear(); return m_local; #5、计算 m_intersection def computeInter(m_1,m_2,thetaSet): F1=focal_Element(m_1); F2=focal_Element(m_2); #空集合 f1_set=set(); f2_set=set(); strSet=set(); inter=dict(); for item0 in thetaSet: strSet.update(item0); sum=0.00 for item1 in F1: f1_set.update(item1); for item2 in F2: f2_set.update(item2); if(f1_set.intersection(f2_set)==strSet): sum+=m_1[item1]*m_2[item2]; f2_set.clear(); f1_set.clear(); inter.update(dict.fromkeys(item0,sum)); strSet.clear(); return inter; #6、计算融合 def combinationEvidence(m_1,m_2,n,thetaSet): m_insert=computeInter(m_1,m_2,thetaSet);#字典类型 m_empty=computeEmpty(m_1,m_2,n);#float类型 m_local=computLocal(m_1,m_2,n,thetaSet);#字典类型 #计算出各个w值 print("***************加权因子********************"); for item1 in m_local.keys(): if item1 in m_local: m_local[item1]=round(m_local[item1]*m_empty,4); print(m_local); print(); print("**************融合后的MASS*****************"); #m_combination=dict(); for item0 in thetaSet: if item0 in m_insert: m_intersection=m_insert[item0]; else: m_intersection=0; if item0 in m_local: m_c=m_local[item0]; else: m_c=0 print(item0,round(m_intersection+m_c,4)); print() print("***************intersection*****************"); print(m_insert); return 0; if __name__ == '__main__': print("e = ",e) combinationEvidence(m_1,m_2,2,theta_set);