Skip to content

Commit

Permalink
Cleanup some dead code (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxd3 authored Nov 29, 2024
1 parent f07d31b commit 1d47fe2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "JuliaBUGS"
uuid = "ba9fb4c0-828e-4473-b6a1-cd2560fee5bf"
version = "0.7.1"
version = "0.7.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
16 changes: 13 additions & 3 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,8 @@ function check_var_group(var_group::Vector{<:VarName}, model::BUGSModel)
end

function AbstractPPL.evaluate!!(rng::Random.AbstractRNG, model::BUGSModel)
(; evaluation_env, g) = model
vi = deepcopy(evaluation_env)
logp = 0.0
evaluation_env = deepcopy(model.evaluation_env)
for (i, vn) in enumerate(model.flattened_graph_node_data.sorted_nodes)
is_stochastic = model.flattened_graph_node_data.is_stochastic_vals[i]
node_function = model.flattened_graph_node_data.node_function_vals[i]
Expand All @@ -444,7 +443,16 @@ function AbstractPPL.evaluate!!(rng::Random.AbstractRNG, model::BUGSModel)
else
dist = node_function(model.evaluation_env, loop_vars)
value = rand(rng, dist) # just sample from the prior
logp += logpdf(dist, value)
if model.transformed
# see below for why we need to transform the value
value_transformed = Bijectors.transform(Bijectors.bijector(dist), value)
logp +=
Distributions.logpdf(dist, value) + Bijectors.logabsdetjac(
Bijectors.inverse(Bijectors.bijector(dist)), value_transformed
)
else
logp += Distributions.logpdf(dist, value)
end
evaluation_env = setindex!!(evaluation_env, value, vn)
end
end
Expand All @@ -467,6 +475,8 @@ function AbstractPPL.evaluate!!(model::BUGSModel)
if model.transformed
# although the values stored in `evaluation_env` are in their original space,
# here we behave as accepting a vector of parameters in the transformed space
# this is so that we have consistent logp values between
# (1) set values in original space then evaluate (2) directly evaluate with the values in transformed space
value_transformed = Bijectors.transform(Bijectors.bijector(dist), value)
logp +=
Distributions.logpdf(dist, value) + Bijectors.logabsdetjac(
Expand Down

2 comments on commit 1d47fe2

@sunxd3
Copy link
Member Author

@sunxd3 sunxd3 commented on 1d47fe2 Nov 29, 2024

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/120371

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.2 -m "<description of version>" 1d47fe2ae5b5ddefc53d64aa7116801580b07bea
git push origin v0.7.2

Please sign in to comment.