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

Variable elimination reimplementation #240

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

naseweisssss
Copy link
Collaborator

No description provided.

@@ -10,7 +18,9 @@ using JuliaBUGS.ProbabilisticGraphicalModels:
condition!,
decondition,
ancestral_sampling,
is_conditionally_independent
is_conditionally_independent,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
is_conditionally_independent,
is_conditionally_independent,

@coveralls
Copy link

coveralls commented Nov 27, 2024

Pull Request Test Coverage Report for Build 12068346100

Details

  • 0 of 53 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.8%) to 70.065%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/experimental/ProbabilisticGraphicalModels/bayesnet.jl 0 53 0.0%
Totals Coverage Status
Change from base Build 11953015266: -1.8%
Covered Lines: 1395
Relevant Lines: 1991

💛 - Coveralls

Copy link
Contributor

github-actions bot commented Nov 27, 2024

BridgeStan not found at location specified by $BRIDGESTAN environment variable, downloading version 2.5.0 to /home/runner/.bridgestan/bridgestan-2.5.0
Done!
Model dogs produces error: ErrorException("log_density() failed with exception: Exception: bernoulli_lpmf: Probability parameter is inf, but must be in the interval [0, 1] (in '/home/runner/work/JuliaBUGS.jl/JuliaBUGS.jl/benchmark/stan/bugs_examples/vol1/dogs/dogs.stan', line 37, column 6 to line 38, column 62)\n")

Model Parameter Count Data Count Stan Density Time (µs) Stan Density Gradient Time (µs) JuliaBUGS Density Time with Graph Walk (µs) JuliaBUGS Density Gradient Time with ReverseDiff.jl(compiled tape) (µs)
rats 65 150 5.6384 8.23533 65.361 89.316
pumps 12 10 1.00462 1.29413 13.8208 6.40175
dogs 2 720 NA NA 171.008 146.883
seeds 26 21 2.44273 3.03556 27.01 22.853
surgical_realistic 14 12 1.27804 1.59411 14.587 8.449
magnesium 108 96 10.4395 12.2275 120.263 78.656
salm 22 18 2.36775 3.11678 21.028 13.069
equiv 15 20 2.69955 3.64425 19.266 14.978
dyes 9 30 1.03641 1.32427 11.947 13.896
stacks 6 21 1.13332 1.68906 18.284 15.368
epil 303 236 32.21 38.642 277.405 235.167
blockers 47 44 3.26711 3.72813 60.077 28.583
oxford 244 240 16.1 18.765 347.3 203.613
lsat 1006 5000 184.212 224.496 2235.08 1162.08
bones 33 422 72.575 90.819 444.215 181.066
mice 20 65 7.29125 9.394 28.3625 39.123
kidney 64 58 10.66 16.11 70.06 79.5975
leuk 18 714 20.338 26.509 216.432 209.168
leukfr 40 714 26.62 34.734 242.08 258.87

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

JuliaFormatter

[JuliaFormatter] reported by reviewdog 🐶


[JuliaFormatter] reported by reviewdog 🐶


[JuliaFormatter] reported by reviewdog 🐶


[JuliaFormatter] reported by reviewdog 🐶


[JuliaFormatter] reported by reviewdog 🐶

BitVector(), # is_stochastic
Int[], # stochastic_ids
Int[], # deterministic_ids
Function[] # deterministic_functions - Added this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
Function[] # deterministic_functions - Added this
Function[], # deterministic_functions - Added this

Comment on lines +113 to +116
bn::BayesianNetwork{V,T},
name::V,
dist::Union{Distribution,Function},
is_observed::Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
bn::BayesianNetwork{V,T},
name::V,
dist::Union{Distribution,Function},
is_observed::Bool
bn::BayesianNetwork{V,T}, name::V, dist::Union{Distribution,Function}, is_observed::Bool

function marginal_distribution(bn::BayesianNetwork{V}, query_var::V) where {V}
# Get query variable id
query_id = bn.names_to_ids[query_var]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


# Get topological ordering
ordered_vertices = Graphs.topological_sort_by_dfs(bn.graph)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

if any(isnothing, parent_values)
return nothing
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

ordered_vertices = [1, 2] # Eliminate X1, then X2
query_id = 3 # Query X3
result = eliminate_variables(bn, ordered_vertices, query_id, Dict{Symbol,Any}())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


@testset "Marginal Distribution P(X3|X1)" begin
bn = BayesianNetwork{Symbol}()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


# X1 ~ Uniform(0,1)
add_stochastic_vertex!(bn, :X1, Uniform(0, 1), false)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# X2 ~ Bernoulli(X1)
add_stochastic_vertex!(bn, :X2, x1 -> Bernoulli(x1), false)
add_edge!(bn, :X1, :X2)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# X3 ~ Normal(μ(X2), 1)
add_stochastic_vertex!(bn, :X3, x2 -> Normal(x2 == 1 ? 10.0 : 2.0, 1.0), false)
add_edge!(bn, :X2, :X3)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

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

Successfully merging this pull request may close these issues.

2 participants