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

Track := variables in resulting chains #693

Open
torfjelde opened this issue Oct 16, 2024 · 0 comments
Open

Track := variables in resulting chains #693

torfjelde opened this issue Oct 16, 2024 · 0 comments

Comments

@torfjelde
Copy link
Member

Currently, := variables are "tracked" as if they are just random variables. This can be annoying in certain cases where we make use of chains obtained from sample calls, e.g. when using generated_quantities, since variables in := expressions aren't treated differently.

Ideally, we should keep track of which variables are actually "deterministic" (i.e. occur in a := expression) vs. "random" (i.e. occur in a ~ expression).

Example:

julia> using DynamicPPL, Distributions

julia> @model function demo()
           x ~ Normal()
           y := x + 100
       end;

julia> model = demo();

julia> varinfo = VarInfo(model);

julia> values_as(varinfo, OrderedDict)
OrderedDict{VarName{:x, typeof(identity)}, Float64} with 1 entry:
  x => 0.66373

julia> values_as_in_model(model, varinfo)
OrderedDict{Any, Any} with 2 entries:
  x => 0.66373
  y => 100.664

Ideally, the values_as_in_model should also keep track of which are considered determinstic and random.

This should be fairly "trivial" to add, since it's mainly an issue of adding the some way to keep track of this information in the tilde calls, e.g. here

function tilde_assume(context::ValuesAsInModelContext, right, vn, vi)
if is_tracked_value(right)
value = right.value
logp = zero(getlogp(vi))
else
value, logp, vi = tilde_assume(childcontext(context), right, vn, vi)
end
# Save the value.
push!(context, vn, value)
# Save the value.
# Pass on.
return value, logp, vi
end

Miiight be a nice issue for you @penelopeysm to have a go at if you want? Should be a nice way to familiarize yourself with DynamicPPL.jl:)

Tag: @mhauru

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

1 participant