-
Notifications
You must be signed in to change notification settings - Fork 36
InitContext
, part 3 - Introduce InitContext
#981
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
base: py/hasgetvalue
Are you sure you want to change the base?
Conversation
Benchmark Report for Commit b55c1e1Computer Information
Benchmark Results
|
DynamicPPL.jl documentation for PR #981 is available at: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## py/hasgetvalue #981 +/- ##
==================================================
+ Coverage 81.92% 82.18% +0.26%
==================================================
Files 37 38 +1
Lines 3994 4048 +54
==================================================
+ Hits 3272 3327 +55
+ Misses 722 721 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
""" | ||
prefix(model::Model, x::VarName) | ||
prefix(model::Model, x::Val{sym}) | ||
prefix(model::Model, x::Any) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code was shifted verbatim to src/model.jl
to avoid circular dependencies between files.
90e95e1
to
21cf568
Compare
InitContext
InitContext
, part 3 - Introduce InitContext
f1d5f20
to
025aa8b
Compare
Note that, apart from being simpler code, Distributions.Uniform also doesn't allow the lower and upper bounds to be exactly equal (but we might like to keep that option open in DynamicPPL, e.g. if the user wants to initialise all values to the same value in linked space).
025aa8b
to
b55c1e1
Compare
Part 1: Adding
hasvalue
andgetvalue
to AbstractPPLPart 2: Removing
hasvalue
andgetvalue
from DynamicPPLThis is Part 3/N of splitting up #967.
This PR solely adds the code for a new leaf context,
InitContext
. Its behaviour is to always override existing values inside a VarInfo.A long-held goal of mine is to split up
contexts.jl
andcontext_implementations.jl
such that each context is in its own file. To help get us to this stage, I've put all theInitContext
-related code insidesrc/contexts/init.jl
. This should, hopefully, also make reviewing easier.InitContext
comes in three forms:PriorInit
: Samples values from the prior;UniformInit(min, max)
: Samples values from betweenmin
andmax
before invlinking them back into the support of the original distribution;ParamsInit(params)
: Takes values fromparams
, which can be a NamedTuple or a Dict. Also takes a fallback strategy, which is used in case the varname is not found inparams
.PriorInit
andUniformInit
have almost one-to-one correspondence withSampleFromPrior
andSampleFromUniform
. I haven't removed them yet because a LOT of stuff depends onSampleFromPrior
. We will eventually remove all of it but doing it in a single PR would make it way too big.However,
ParamsInit
is new. Its purpose is to set fixed values in a VarInfo in a principled manner. Right now, there is a fair amount of code that does low-level VarInfo manipulation by reaching inside and modifying the underlying arrays, such asinitialise_values!!
, andsetval_and_resample!
. This is prone to bugs, and also leads to (for example) the VarInfo's logp being out of sync. (All of that code will be removed in subsequent PRs.)ParamsInit
accomplishes the same in a much cleaner way, although in some cases it may necessitate one extra model evaluation. Because initialisation is not meant to happen within a tight loop (by definition it happens once), I don't consider performance to be an important issue.Closes #375.