Closed cscherrer closed 2 years ago
:exclamation: No coverage uploaded for pull request base (
main@49c3ddc
). Click here to learn what that means. The diff coverage isn/a
.:exclamation: Current head edbfc10 differs from pull request most recent head 6655917. Consider uploading reports for the commit 6655917 to get more accurate results
@@ Coverage Diff @@
## main #35 +/- ##
=======================================
Coverage ? 42.36%
=======================================
Files ? 45
Lines ? 1435
Branches ? 0
=======================================
Hits ? 608
Misses ? 827
Partials ? 0
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.
FixedRNG
FixedRNG()
is anAbstractRNG
that is, well, fixed. It always returns the same value. Like this:One possibility for this is to move it to MeasureBase (code is short), and use it to define a fallback method for
testvalue
.rand
ModelPosterior
rand
returns a sample from the latent space. To get a return value, callpredict
Return-related functions
drop_return
is nowdropreturn
hasreturn(m)
returns eitherHasReturn()
orNoReturn()
, depending whether the model contains areturn
statementConfigurations (
<:AbstractConfig
)I've saved the best for last. There's kind of a lot here, so let's just walk through a simple example,
logdensity_def
.First we define
AbstractConfig
subtypes are used for dispatch in Tilde, and can also hold information to be referenced as the model is run.Next, here's the top-level call:
AbstractConditionalModel
can be eitherModelClosure
(a model with specified argument) orModelPosterior
(if it has also been conditioned on some observations).The
logdensityof
call is very simple: it just sets the config and then callsrunmodel
, which does the work.runmodel
takes four arguments:AbstractConditionalModel
pars
, which is just another place to specify values of more variables. This is more efficient than pulling the model apart and rebuilding it each time with different values. We expectpars
to change often.ctx
. This is typically a NamedTuple. It's different from a config in that a context is expected to be updated at each~
statement in the model.Now, if a model we're using happens to have a
return
statement, we need to be sure not to call it. To make this more general, we replace everyreturn r
withreturn retfun(cfg, r, ctx)
. If the model has noreturn
statement, a model will implicitly return a named tuple of all variables appearing on the left of a~
.Say our model has an observed value
x
, and contains the statementTilde first rewrites this (using
Tilde.opticize
) asNext, we often want different behavior depending whether a value has been observed. For this we have an abstract type
MaybeObserved
, with instancesObserved
andUnobserved
.Since
x
is observed, we represent it asObserved{:x}(x)
. This is a handy way to pass the information:x
x
Finally, the line
x[j] ~ Normal()
is converted toThe
tilde
function needs to dispatch on the type ofcfg
(and possibly other values), and return an updatedx
and context.In this case, that function looks like this:
That
pred
line is a little weird.d
might itself be a model, in which case our observations would be of the latent variables of that model. For the cased
is not a model, there's a fallback method,predict(m, x) = x
.