Discussion
Up to the Bugs Forum
Please feel free to communicate anything you feel could help this project move on. You can receive an email each time a new message is posted by setting up your personal preferences.
marginalizing with jointree
hi ahazan.
What you're trying to do and the results you get are all normal. The ML learning engine simply counts the number of occurances of each combination of the variables and provides that value as the ML expectation.
If a case never occurs, there is no way of knowing what value to give and you end up with 0/0 division. What you would like to have is a priori information which could be easily translated as 'visual counts'. For example, by counting one visual count for each state of each variable you would end up with a very small probability for never observed values (instead of nans).
So actually, this message should be posted in the Features Request discussion, since the a priori feature is not yet implemented in OpenBayes.
I invite you to take a look at the theory of ML (maximum likelihood) learning and you will realise that it is very easy implement in practice. Depending on your python and bayesian skills you can choose either of the following options :
1) implement the dirichlet's a priori your self and submit the code so that other users can use it as well and correct possible bugs.
2) or wait for me to implement it myself. Just for the info, this is an important feature that will certainly be implemented in the near future.
Please tell me your plans
Kosta
What you're trying to do and the results you get are all normal. The ML learning engine simply counts the number of occurances of each combination of the variables and provides that value as the ML expectation.
If a case never occurs, there is no way of knowing what value to give and you end up with 0/0 division. What you would like to have is a priori information which could be easily translated as 'visual counts'. For example, by counting one visual count for each state of each variable you would end up with a very small probability for never observed values (instead of nans).
So actually, this message should be posted in the Features Request discussion, since the a priori feature is not yet implemented in OpenBayes.
I invite you to take a look at the theory of ML (maximum likelihood) learning and you will realise that it is very easy implement in practice. Depending on your python and bayesian skills you can choose either of the following options :
1) implement the dirichlet's a priori your self and submit the code so that other users can use it as well and correct possible bugs.
2) or wait for me to implement it myself. Just for the info, this is an important feature that will certainly be implemented in the near future.
Please tell me your plans
Kosta
When using a priori values (Dirichlet), some people talk about an augmented Bayesian net (e.g. Neapolitan in Learning Bayesian Networks). And I have allready implemented this because I needed it for EM-learning. You can find a version of my adapted distributions class in my personal folder on this site, inside the EM-algorithm folder. ( I uploaded it a while ago). Just take a look at all the functions that have "augm(ented)" in their name.
It is used in my version of the EM-algorithm (also in my folder), but it is easy to adapt to the LearnMLParams function. Actually, you could just use my EMLearning function instead of the LearnMLParams and it should work (allthough slower).
I can add it to the official toolbox when I'm back at the office.
wannes
It is used in my version of the EM-algorithm (also in my folder), but it is easy to adapt to the LearnMLParams function. Actually, you could just use my EMLearning function instead of the LearnMLParams and it should work (allthough slower).
I can add it to the official toolbox when I'm back at the office.
wannes
Wannes,
I just a look at your augmented BNs and it seems like you've done a very good work.
From this week on I'll start working on ver 0.2 of OpenBayes.
I've created a page on the site (Development folder) where we can set the features that will be implemented in that version.
Any comment or feature are welcome. Any code contribution is even more welcome!
Kosta
I just a look at your augmented BNs and it seems like you've done a very good work.
From this week on I'll start working on ver 0.2 of OpenBayes.
I've created a page on the site (Development folder) where we can set the features that will be implemented in that version.
Any comment or feature are welcome. Any code contribution is even more welcome!
Kosta
wannes:
It is used in my version of the EM-algorithm (also in my folder), but it is easy to adapt to the LearnMLParams function. Actually, you could just use my EMLearning function instead of the LearnMLParams and it should work (allthough slower).
I'd like to adapt your code in a useful way...
where should I create/ override functions that incorporate your changes?
It is used in my version of the EM-algorithm (also in my folder), but it is easy to adapt to the LearnMLParams function. Actually, you could just use my EMLearning function instead of the LearnMLParams and it should work (allthough slower).
I'd like to adapt your code in a useful way...
where should I create/ override functions that incorporate your changes?
I have just submitted a modief version of LearnMLParams (inference.py) ... Not sure it is correct...
Thank you ahazan (this is your last name right?)
Your code will be integrated into the new version of OpenBayes. For the moment I put your page into the development folder.
You might be interested by the document I put online in the development folder : OpenBayes version 2 : Issues
kosta
Your code will be integrated into the new version of OpenBayes. For the moment I put your page into the development folder.
You might be interested by the document I put online in the development folder : OpenBayes version 2 : Issues
kosta
Powered by Ploneboard
I am facing a problem when marginalizing using the JoinTree algorithm. If the cases do not represent all possible variable values, when marginalizing, the JoinTree returns a table made of 'Nan'. This does not happen with MCMC
Thanks for your feedback.
Amaury Hazan
The code is the following:
from OpenBayes import JoinTree, MCMCEngine
from OpenBayes import BNet, BVertex, DirEdge
from copy import deepcopy
from time import time
#create the BNET
bnet = BNet( 'Language 1 Bayesian Network' )
nbins=2
# actual node : n0, past event node: n1
n0 = bnet.add_v( BVertex('n0', True, nbins))
n1 = bnet.add_v( BVertex('n1', True, nbins))
bnet.add_e( DirEdge( len(bnet.e), n1, n0) )
bnet.InitDistributions()
ie = JoinTree(bnet)
#ie = MCMCEngine(bnet)
case1=dict()
case1['n0']=1
case1['n1']=0
#this second case for representing all possible values
#note that if you add this case, the marginalization with JoinTree will work
#but if you then set nbins to 3 it will fail
case2=dict()
case2['n0']=0
case2['n1']=1
cases=[]
cases.append(case1)
#cases.append(case2)
#learning parameters
ie.LearnMLParams(cases)
obs=dict()
obs['n1']=0
ie.SetObs(obs)
print ie.Marginalise('n0').cpt
### end