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

Infer BN joint probability with evidence #143

Open
SEICS opened this issue Jul 8, 2022 · 3 comments
Open

Infer BN joint probability with evidence #143

SEICS opened this issue Jul 8, 2022 · 3 comments

Comments

@SEICS
Copy link

SEICS commented Jul 8, 2022

Hello,

I wonder what is the syntax to query a Bayesian Network's (BN) joint probability with some evidence? The docs seem a little bit too brief and lots of syntaxes are not mentioned.

Based on this infer statement:
infer(ExactInference(), bn, [:distance], evidence=Assignment(:carrier_id=>15))

I have tried to omit the query objects (e.g., [:a,:b]) from the infer statement:
infer(ExactInference(), bn, evidence=Assignment(:carrier_id=>15))

and BayesNets.jl output compilation errors:
MethodError: no method matching infer(::ExactInference, ::DiscreteBayesNet; evidence=Dict{Symbol, Any}(:carrier_id => 15))

I wonder if such feature is implemented or will it be on plan? Really looking forward to your reply! Thank you so much!

@tawheeler
Copy link
Contributor

A call to infer produces a joint distribution over all given target variables (which cannot include evidence variables). To get the effect you requested, just expand [:distance] to include all variables in the BN other than carrier_id.

@SEICS
Copy link
Author

SEICS commented Jul 11, 2022

Thank you for the reply. Sorry again, assuming that I have a BN as "year -> distance -> origin_id", and I have observed origin_id=>1, I wonder how can I get the joint distribution for this BN with this evidence?

What I have tried:

result = infer(ExactInference(), bn, [:year,:distance], evidence=Assignment(:origin_id=>1)).potential
result = sum(result, dims=(1, 2))

and it gives me:

julia> include("/Users/jw/Desktop/test.jl")
[1.0;;]

which means I got the joint distribution of this BN as 1. This sum up to one should not happen because of the evidence. I wonder what did I do wrong? Thank you for help!

@tawheeler
Copy link
Contributor

The result of infer is going to be a factor table, which will have normalized probability values. Summing over them will always produce 1.

If it isn't displaying properly, please try viewing the factor in IJulia, or maybe printing it out after converting it to a DataFrame. convert(DataFrame, ϕ).

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