'How is inference by enumeration done on bayesian networks?
For instance, if given the following Bayesian network and probabilities how would I find P(BgTV | not(GfC). I attempted to do so by simply using the equivalence that P(A|B) = P(A and B)/P(B) but that resulted in me having a value of 200% which is not possible. Do I need to treat George_feeds_cat as a dependent event as per the network and use what I know from baseball_game_on_TV and George_watches_TV to calculate the odds? Any guidance would be much appreciated!
Solution 1:[1]
Indeed, you need all the parameters for answering your question (oCF seems to be independent from BgTV and GwTV but knowing GfC, this is not the case anymore).
Using the columns, instead of the symbols, you want :
P(A|C)=P(A,C)/P(C)=sum_{B,D} P(A,B,C,D) / sum_{A,B,D} P(A,B,C,D)
with the joint distribution factorized using the BN
P(A,B,C,D)=P(A)*P(B|A)*P(C)*P(D|C,B)
In Python using the package pyAgrum, you would write :
# model
import pyAgrum as gum
bn=gum.fastBN("BgTV->GwTV->GfC<-oCF")
# where do those numbers come from ? :-)
bn.cpt("BgTV").fillWith([1-0.3041096,0.3041096])
bn.cpt("oCF").fillWith([1-0.169863,0.169863])
bn.cpt("GwTV")[{"BgTV":0}]=[1-0.1181102,0.1181102]
bn.cpt("GwTV")[{"BgTV":1}]=[1-0.9279279,0.9279279]
bn.cpt("GfC")[{"GwTV":0,"oCF":0}]=[1-0.9587629,0.9587629]
bn.cpt("GfC")[{"GwTV":0,"oCF":1}]=[1-0.3157895,0.3157895]
bn.cpt("GfC")[{"GwTV":1,"oCF":0}]=[1-0.706422,0.706422]
bn.cpt("GfC")[{"GwTV":1,"oCF":1}]=[1-0.0416667,0.0416667]
# compute
joint=bn.cpt("BgTV")*bn.cpt("GwTV")*bn.cpt("GfC")*bn.cpt("oCF")
joint.margSumIn(["GfC","BgTV"])/joint.margSumIn("GfC")
which should give you
|| BgTV |
GfC ||0 |1 |
------||---------|---------|
0 || 0.5159 | 0.4841 |
1 || 0.7539 | 0.2461 ||
Where you see that P(BgTV=1|GfC=0)=48.41%
Using a notebook, the model :
And the inference (using another method with junction tree) :
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |