|
| Hi,
I am new to perl, I need some idea on implementing this. Any help will be blessing for me.
I am unable to attach rtf or doc file generated by mac text editor. So copied txt but had to replace summation symoble in msg as it is not supported or I dont know how to use for this post:
Summ = summation i.e math symbol for summation.
For e.g Summ
R = {1}
Thank you.
Goal : To code bayesian network using perl
Step 1 : I have network :
X T
\ /
R
|
Y
Step 2 : I make txt file
Node Parent Children
X NA R
T NA R
R X,T Y
Y R NA
Step 3 : I make a hash table to store this values:
e.g. nodes%
1) nodes{nodeId} // value = Stores node e.g R
2)nodes{nodeId}{'parent'} // value = Stores an array of all the parents for that node For e.g. X,T
3)nodes{nodeId}{'chid'} //value = Stores an array of all children for that node. For e.g Y
Step 4: I need to calculate bayesian network.
You can think each node as a gene and also the network as boolean network where each node is either 0,1
For e.g. I need to calculate P(Y =0 |X=0)
It means that I dont know anything about the other variable state i.e it is hidden: So I have to consider all combination for the network : i.e. I need to calculate joint probability of network.
So I joint probability of complete network
Formula : P(Y=0|X=0) = P(X) P(T) P(R|X,T) P(Y=0 | R)
[ P(X) P(T) Summ [Summ P(R|X,T)P(Y=0 | R) ] ]
R={0,1} (X = {0} , T = {0,1})
(I need help in implement this in perl : i.e. automate)
May be following way :
Now we know that X and Y are given , all other variables can take 0 or 1 so we need cal. joint probability
In bayes net generally ancestor in our case is assigned some prior : for our case
P(X=0) = P(X=1) = 0.5 (as an example)
P(T=0) = P(T =1 ) = 0.5
So when I need to calculate joint prob P(Y=0|X=0)
Step a : I should generate topology list: For e.g in our case it would be X,T,R,Y ( this would be generated by asking question : who is ancestor (X,T) : , Who is child of this ... i.e. I need someway of keeping track like what should be calculated.
[Question : Should I have a new array which will store this ?????)
if I have list than I should be able to come with something for generating the formula :
[ P(X) P(T) Summ [ Summ P(R|X,T)P(Y=0 | R) ] ]
R={0,1} (X = {0} , T = {0,1})
__________
Problem II :
For Example We have same graph and Now intermediate variable is know :
P(Y=0 | R =1, X =0 )
Than joint probability
[ P(X) P(T) Summa[ Summa P(R|X,T)P(Y=0 | R) ] ]
R={1} (X = {0} , T = {0,1})
But I need help on implementing this all in perl.
OR :
P(Y=0 , R=1 | X =0 )
________________________________________
_______________________________ |
|