Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ConditionalDiscreteDistribution' is not defined #11

Closed
fareez-ahamed opened this issue May 26, 2015 · 8 comments
Closed

'ConditionalDiscreteDistribution' is not defined #11

fareez-ahamed opened this issue May 26, 2015 · 8 comments

Comments

@fareez-ahamed
Copy link

I'm trying to use ConditionalDiscreteDistribution according to the examples but getting this error. ConditionalDiscreteDistribution seems to be missing in the repo as well when I was searching for it. Am I missing something?

@jmschrei
Copy link
Owner

It's been renamed ConditionalProbabilityTable. I'll go fix the examples later today. The renaming was because I fundamentally shifted the way conditional probabilities were calculated (for efficient conversion to joint probabilities) and associated API, and wanted to make sure people were notified somehow, even if only through an error message. Sorry for the inconvenience.

The README shows how to set up these new tables in the Monty Hall example.

@fareez-ahamed
Copy link
Author

Thanks @jmschrei for the quick response 😃

But I find ConditionalProbabilityTable requires of lot of hardcoding compared to ConditionalDiscreteDistribution.

# Gender, given survival data
gender = ConditionalProbabilityTable(
            [[ 'survive', 'male',   0.0 ],
             [ 'survive', 'female', 1.0 ],
             [ 'perish', 'male',    1.0 ],
           [ 'perish', 'female',  0.0]], [passenger] )

where as ConditionalDiscreteDistribution

gender = ConditionalDiscreteDistribution({
      'survive' : DiscreteDistribution({ 'male' : 0.0, 'female' : 1.0 }),
      'perish' : DiscreteDistribution({ 'male' : 1.0, 'female' : 0.0 })
      }, [passenger])

@jmschrei
Copy link
Owner

It looks to me that ConditionalProbabilityTable is taking less characters.

Internally it made a lot more sense to go with the CPT format rather than the CDD format. I can re-add CDDs if you're using them in isolation, but I already tried making them work with Bayes nets to pretty terrible results.

The primary issue comes in that marginalizing over variables can get really intense in the tree-like structure nested dictionaries give you, whereas with the vector format it's trivial to marginalize any variable. This is a major component of converting to a joint distribution, necessary when you're using a factor graph to do inference on a Bayes net.

@fareez-ahamed
Copy link
Author

Yes you are correct! As the number of dependent distributions increase, the tree structure gets complex...

Actually I started trying CDD when I couldn't get CPT working in my case

https://github.com/fareez-ahamed/pylearn/blob/master/scripts/ex4-titanic-disaster.py

This code throws the following error at network.bake()

Traceback (most recent call last):
  File "D:\code\pylearn\scripts\ex4-titanic-disaster.py", line 42, in <module>
    network.bake()
  File "pomegranate\BayesianNetwork.pyx", line 126, in pomegranate.BayesianNetwork.BayesianNetwork.bake (pomegranate\BayesianNetwork.c:3531)
  File "pomegranate\distributions.pyx", line 2347, in pomegranate.distributions.ConditionalProbabilityTable.joint (pomegranate\distributions.c:38893)
ZeroDivisionError: float division by zero

@jmschrei
Copy link
Owner

Okay, I see what the problem is. I was conflating two different cases. I tried to hack together a solution, but I'm not comfortable that it is the optimal one. I will go through the entire distribution scheme I have set up and find a better way to code it.

@jmschrei
Copy link
Owner

Ironically, the way this came about was that I kept running more and more complex Bayes nets, fixing bugs as I went, but didn't go back to check to make sure they still worked on the earlier examples. Moral of the story; always encode unit tests, not examples.

@fareez-ahamed
Copy link
Author

So this float division by zero is an error in pomegranate or my code is doing something wrong with pomegranate?

@jmschrei
Copy link
Owner

Something wrong with pomegranate. I'm moving this to the other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants