import matplotlib.pyplot as plt
import numpy as np
PH = 0.5   # 结论的先验概率
PE = 0.4   # 证据的先验概率
LS = 5     # 充分性度量
LN = 0.1   # 必要性度量
def calculation(x):
    PHNE = LN * PH / ((LN-1)*PH + 1)
    PHE = LS * PH / ((LS-1)*PH + 1)
    if x >=0 and x <= PE:
        return PHNE + (PH-PHNE) / PE * x
    elif x >= PE and x <= 1:
        return PH + (PHE - PH) / (1 - PE) * (x - PE)
    else:
        print("输入非法!")
        return
x = float(input("请输入P(E|S):"))
print("P(H|S)=", calculation(x))
plt_x = np.arange(0,1,0.01)
plt_y = np.zeros(len(plt_x))
for i in range(len(plt_x)):
    plt_y[i]= calculation(plt_x[i])
plt.plot(plt_x, plt_y)
plt.xlabel('P(E|S)')
plt.ylabel('P(H|S)')
axes = plt.gca()
axes.set_xlim([0,1])
axes.set_ylim([0,1])
plt.show()
Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐