Skip to content

Introduction of SamplingContext #253

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d70e1be
added sampling context and unwrap_childcontext
torfjelde May 31, 2021
f743990
updated tilde methods
torfjelde May 31, 2021
3d2e7e2
updated model call signature
torfjelde May 31, 2021
4f1d396
updated compiler
torfjelde May 31, 2021
b187d74
formatting
torfjelde May 31, 2021
ee99f8c
added getsym for vectors
torfjelde May 31, 2021
c4845d0
Update src/varname.jl
torfjelde May 31, 2021
a0c05f3
fixed some signatures for Model
torfjelde May 31, 2021
307cd7e
fixed a method call
torfjelde May 31, 2021
5972771
fixed method signatures
torfjelde Jun 1, 2021
c4ecd0e
sort of fixed the matchingvalue functionality for model
torfjelde Jun 1, 2021
a34b51c
formatting
torfjelde Jun 1, 2021
6368282
Merge branch 'tor/tilde-simplification' into tor/sampler-context
torfjelde Jun 1, 2021
e4a2cf8
removed left-over acclogp! that should not be here anymore
torfjelde Jun 1, 2021
7605785
export SamplingContext
torfjelde Jun 1, 2021
354ac52
use context instead of ctx to refer to contexts
torfjelde Jun 1, 2021
b7a2b3b
formatting
torfjelde Jun 1, 2021
9e0fc9a
use context instead of ctx for variables
torfjelde Jun 1, 2021
7a4a1a3
use context instead of ctx to refer to contexts
torfjelde Jun 1, 2021
7899473
Update src/compiler.jl
torfjelde Jun 2, 2021
1630476
Update src/context_implementations.jl
torfjelde Jun 2, 2021
6892d2b
Apply suggestions from code review
torfjelde Jun 2, 2021
fec00b6
Merge branch 'master' into tor/sampler-context
torfjelde Jun 3, 2021
ffb4933
Merge branch 'master' into tor/sampler-context
torfjelde Jun 4, 2021
f52550f
introduce EvaluationContext and make PriorContext and LikelihoodConte…
torfjelde Jun 4, 2021
800ee2d
Merge branch 'tor/tilde-simplification' into tor/sampler-context
torfjelde Jun 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export AbstractVarInfo,
SampleFromPrior,
SampleFromUniform,
# Contexts
DefaultContext,
SamplingContext,
EvaluationContext,
LikelihoodContext,
PriorContext,
MiniBatchContext,
Expand Down
24 changes: 5 additions & 19 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,7 @@ function generate_tilde(left, right)
if !(left isa Symbol || left isa Expr)
return quote
$(DynamicPPL.tilde_observe!)(
__context__,
__sampler__,
$(DynamicPPL.check_tilde_rhs)($right),
$left,
__varinfo__,
__context__, $(DynamicPPL.check_tilde_rhs)($right), $left, __varinfo__
)
end
end
Expand All @@ -304,9 +300,7 @@ function generate_tilde(left, right)
$isassumption = $(DynamicPPL.isassumption(left))
if $isassumption
$left = $(DynamicPPL.tilde_assume!)(
__rng__,
__context__,
__sampler__,
$(DynamicPPL.unwrap_right_vn)(
$(DynamicPPL.check_tilde_rhs)($right), $vn
)...,
Expand All @@ -316,7 +310,6 @@ function generate_tilde(left, right)
else
$(DynamicPPL.tilde_observe!)(
__context__,
__sampler__,
$(DynamicPPL.check_tilde_rhs)($right),
$left,
$vn,
Expand All @@ -337,11 +330,7 @@ function generate_dot_tilde(left, right)
if !(left isa Symbol || left isa Expr)
return quote
$(DynamicPPL.dot_tilde_observe!)(
__context__,
__sampler__,
$(DynamicPPL.check_tilde_rhs)($right),
$left,
__varinfo__,
__context__, $(DynamicPPL.check_tilde_rhs)($right), $left, __varinfo__
)
end
end
Expand All @@ -355,9 +344,7 @@ function generate_dot_tilde(left, right)
$isassumption = $(DynamicPPL.isassumption(left))
if $isassumption
$left .= $(DynamicPPL.dot_tilde_assume!)(
__rng__,
__context__,
__sampler__,
$(DynamicPPL.unwrap_right_left_vns)(
$(DynamicPPL.check_tilde_rhs)($right), $left, $vn
)...,
Expand All @@ -367,7 +354,6 @@ function generate_dot_tilde(left, right)
else
$(DynamicPPL.dot_tilde_observe!)(
__context__,
__sampler__,
$(DynamicPPL.check_tilde_rhs)($right),
$left,
$vn,
Expand Down Expand Up @@ -398,10 +384,8 @@ function build_output(modelinfo, linenumbernode)
# Add the internal arguments to the user-specified arguments (positional + keywords).
evaluatordef[:args] = vcat(
[
:(__rng__::$(Random.AbstractRNG)),
:(__model__::$(DynamicPPL.Model)),
:(__varinfo__::$(DynamicPPL.AbstractVarInfo)),
:(__sampler__::$(DynamicPPL.AbstractSampler)),
:(__context__::$(DynamicPPL.AbstractContext)),
],
modelinfo[:allargs_exprs],
Expand All @@ -411,7 +395,9 @@ function build_output(modelinfo, linenumbernode)
evaluatordef[:kwargs] = []

# Replace the user-provided function body with the version created by DynamicPPL.
evaluatordef[:body] = modelinfo[:body]
evaluatordef[:body] = quote
$(modelinfo[:body])
end

## Build the model function.

Expand Down
Loading