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

[Merged by Bors] - Introduction of SamplingContext: keeping it simple #259

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 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
30c8345
Merge branch 'tor/tilde-simplification' into tor/sampling-context-simple
torfjelde Jun 7, 2021
1015f0e
added impl of matchingvalue for contexts
torfjelde Jun 7, 2021
23c86a7
reverted the change that makes assume always resample
torfjelde Jun 7, 2021
17f5abe
removed the inds arguments from assume and dot_assume to stay non-bre…
torfjelde Jun 7, 2021
dbd61f0
Update src/context_implementations.jl
yebai Jun 7, 2021
b10ba3f
added missing sampler arg to tilde_observe
torfjelde Jun 7, 2021
43779e8
Merge branch 'tor/sampling-context-simple' of github.com:TuringLang/D…
torfjelde Jun 7, 2021
bc5029f
added missing sampler argument in dot_tilde_observe
torfjelde Jun 7, 2021
7eac33d
fixed order of arguments in some dot_assume calls
torfjelde Jun 7, 2021
8599481
formatting
torfjelde Jun 7, 2021
90a8c45
formatting
torfjelde Jun 7, 2021
f9d4ff8
added missing sampler argument in tilde_observe for SamplingContext
torfjelde Jun 7, 2021
e424fe7
added missing word in a docstring
torfjelde Jun 7, 2021
70957d2
updated submodel macro
torfjelde Jun 8, 2021
d00cdcf
removed unwrap_childcontext and related since its not needed for this PR
torfjelde Jun 8, 2021
639fd6e
updated submodel macro
torfjelde Jun 8, 2021
c9a06fb
fixed evaluation implementations of dot_assume
torfjelde Jun 8, 2021
2fe5f40
updated pointwise_loglikelihoods and related
torfjelde Jun 8, 2021
b532ca6
added proper tests for pointwise_loglikelihoods
torfjelde Jun 8, 2021
4e2274e
updated DPPL tests to reflect recent changes
torfjelde Jun 8, 2021
dbb48c5
Merge branch 'tor/tilde-simplification' into tor/sampling-context-simple
torfjelde Jun 8, 2021
10899f3
formatting
torfjelde Jun 8, 2021
1f21ce4
formatting
torfjelde Jun 8, 2021
7004506
renamed mean_of_mean_models used in tests
torfjelde Jun 8, 2021
fa6c4d6
bumped dppl version in integration tests
torfjelde Jun 9, 2021
684d829
Apply suggestions from code review
torfjelde Jun 9, 2021
07bb284
Apply suggestions from code review
torfjelde Jun 9, 2021
c7c6a3c
fixed ambiguity error
torfjelde Jun 9, 2021
c259999
Merge branch 'tor/sampling-context-simple' of github.com:TuringLang/D…
torfjelde Jun 9, 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
1 change: 1 addition & 0 deletions src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export AbstractVarInfo,
SampleFromPrior,
SampleFromUniform,
# Contexts
SamplingContext,
DefaultContext,
LikelihoodContext,
PriorContext,
Expand Down
33 changes: 14 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 Down Expand Up @@ -449,8 +433,12 @@ end

"""
matchingvalue(sampler, vi, value)
matchingvalue(context::AbstractContext, vi, value)

Convert the `value` to the correct type for the `sampler` or `context` and the `vi` object.

Convert the `value` to the correct type for the `sampler` and the `vi` object.
For a `context` that is _not_ a `SamplingContext`, we fall back to
`matchingvalue(SampleFromPrior(), vi, value)`.
"""
function matchingvalue(sampler, vi, value)
T = typeof(value)
Expand All @@ -467,6 +455,13 @@ function matchingvalue(sampler, vi, value)
end
matchingvalue(sampler, vi, value::FloatOrArrayType) = get_matching_type(sampler, vi, value)

function matchingvalue(context::AbstractContext, vi, value)
return matchingvalue(SampleFromPrior(), vi, value)
end
function matchingvalue(context::SamplingContext, vi, value)
return matchingvalue(context.sampler, vi, value)
end

"""
get_matching_type(spl::AbstractSampler, vi, ::Type{T}) where {T}

Expand Down
Loading