0
import math
from pomegranate import *
import pomegranate as pg
guest= pg.DiscreteDistribution({'A':1./3,'B':1./3,'C':1./3})
prize= pg.DiscreteDistribution({'A':1./3,'B':1./3,'C':1./3})
monty=pg.ConditionalProbabilityTable(
    [['A','A','A',0.0],
     ['A','A','B',0.5],
     ['A','A','C',0.5],
     ['A','B','A',0.0],
     ['A','B','B',0.0],  
     ['A','B','C',1.0], 
     ['A','C','A',0.0], 
     ['A','C','B',1.0], 
     ['A','C','C',0.0], 
     ['B','A','A',0.0], 
     ['B','A','B',0.0], 
     ['B','A','C',1.0], 
     ['B','B','A',0.5],
     ['B','B','B',0.0], 
     ['B','B','C',0.5], 
     ['B','C','A',1.0], 
     ['B','C','B',0.0], 
     ['B','C','C',0.0], 
     ['C','A','A',0.0], 
     ['C','A','B',1.0], 
     ['C','A','C',0.0],
     ['C','B','A',1.0], 
     ['C','B','B',0.0], 
     ['C','B','C',0.0], 
     ['C','C','A',0.5], 
     ['C','C','B',0.5], 
     ['C','C','C',0.0]],[guest,prize])   

s1=pg.State(guest,name="guest")
s2=pg.State(prize,name="prize")
s3=pg.State(monty,name="monty")
network=pg.BayesianNetwork("Monty Hall Problem")
network.add_states(s1,s2,s3)
network.add_edge(s1,s2)
network.add_edge(s1,s3)
network.bake()

beliefs=network.predict_proba({'guest':'A'})
beliefs=map(str,beliefs)
print("\n".join("{}\t{}".format(state.name,belief)for state,belief in zip(network.states,beliefs)))



beliefs=network.predict_proba({'guest':'A','monty':'B'})
print("\n".join("{}\t{}".format(state.name,belief)for state,belief in zip(network.states,beliefs)))

I am facing the error:

Traceback (most recent call last):
  File "Bayesian_network_monty.py", line 43, in <module>
    beliefs=network.predict_proba({'guest':'A'})
  File "pomegranate\BayesianNetwork.pyx", line 609, in pomegranate.BayesianNetwork.BayesianNetwork.predict_proba
  File "pomegranate\FactorGraph.pyx", line 345, in pomegranate.FactorGraph.FactorGraph.predict_proba
  File "pomegranate\distributions\JointProbabilityTable.pyx", line 188, in pomegranate.distributions.JointProbabilityTable.JointProbabilityTable.marginal
**AttributeError: 'NoneType' object has no attribute 'log_probability'**

How can I resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Hi Medha Mansi! Welcome to StackOverflow! Just wanted to let you know that people may comment with suggestions on how to make your post better or vote up and down on your post. If people vote down, don't worry about it - it's just them signalling that there's better ways of asking your question; it doesn't mean that your question won't be answered. (I think your question was very well done, so I have given it an upvote.) I don't know `pomegranate` enough to be able to help here, but I wish you the best with your first question. Congrats! – Pro Q Mar 23 '20 at 17:21
  • I can't think how this shouty txtspk question deserves an upvote, but I have done my duty and downvoted (please note @ProQ). Medha, please make an effort with your questions, which means not using all-caps shouting, not using txtspk, formatting error blocks. This is a professional Q&A platform, not a chatroom. – halfer Mar 25 '20 at 12:33
  • While your wording is not very kind, you are correct - thank you for editing. – Pro Q Mar 25 '20 at 14:50

0 Answers0