Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于pgmpy库的信念传播——算法理解_Python_Algorithm_Belief Propagation_Pgmpy - Fatal编程技术网

Python 基于pgmpy库的信念传播——算法理解

Python 基于pgmpy库的信念传播——算法理解,python,algorithm,belief-propagation,pgmpy,Python,Algorithm,Belief Propagation,Pgmpy,我现在开始使用pgmpy库来实现概率图形模型。使用此库获得的概率与手动获得的概率不同(例如,使用SamIam)。 以下是用SamIam制作的非常小的图形模型的屏幕截图,用于检查概念构思: 我使用pgmpy的代码 from pgmpy.models import BayesianModel from pgmpy.factors import TabularCPD from pgmpy.inference import BeliefPropagation student_model = Bayes

我现在开始使用pgmpy库来实现概率图形模型。使用此库获得的概率与手动获得的概率不同(例如,使用SamIam)。 以下是用SamIam制作的非常小的图形模型的屏幕截图,用于检查概念构思:

我使用pgmpy的代码

from pgmpy.models import BayesianModel
from pgmpy.factors import TabularCPD
from pgmpy.inference import BeliefPropagation

student_model = BayesianModel([('D', 'G'), ('I', 'G')])

difficulty_cpd = TabularCPD(variable='D', variable_card=2, values=[[0.6, 0.4]])
intel_cpd = TabularCPD(variable='I', variable_card=2, values=[[0.7, 0.3]])
grade_cpd = TabularCPD(variable='G',variable_card=3, values=[[0.3, 0.05, 0.9, 0.5], [0.4, 0.25, 0.08, 0.3], [0.3, 0.7, 0.02, 0.2]], evidence=['I', 'D'], evidence_card=[2, 2])

student_model.add_cpds(grade_cpd, difficulty_cpd, intel_cpd)

print (student_model.nodes())
print (student_model.get_cpds('D'))
print (student_model.get_cpds('I'))
print (student_model.get_cpds('G'))

belief_propagation = BeliefPropagation(student_model)
res = belief_propagation.query(variables=["G"])
print (res['G'])
我得到以下结果

phi(G)的值与Samiam中的值不同

根据Samiam中使用的算法,我们应该得到G_0:

P(G_0) = P(G_0|I_0,D_0) + P(G_0|I_0,D_1) + P(G_0|I_1,D_0) + P(G_0|I_1,D_1)
P(G_0) = 0.3*0.7*0.6 + 0.05*0.7*0.4 + 0.9*0.3*0.6 + 0.5*0.3*0.4 = 0.3620

有人能告诉我如何计算这些phi(G)值(实际使用的是哪种算法),以及如何获得与SamIam中相同的值。

我已经收到关于的答复。看起来库的更新是解决方案,我已经收到关于的答复。看起来库的更新就是解决方案
P(G_0) = P(G_0|I_0,D_0) + P(G_0|I_0,D_1) + P(G_0|I_1,D_0) + P(G_0|I_1,D_1)
P(G_0) = 0.3*0.7*0.6 + 0.05*0.7*0.4 + 0.9*0.3*0.6 + 0.5*0.3*0.4 = 0.3620