-
Notifications
You must be signed in to change notification settings - Fork 8
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
Make NestedModel
a bit more general
#76
Conversation
@torfjelde do you know what's breaking the tests? |
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 change seems good, I'm curious about the choice of creating a custom struct for PriorTransformAndLogLike
- can you explain your thinking a bit?
Also, for changing the proposals to pass the whole NestedModel
- could you just pass a prior_and_loglike
function instead? This might make tests easier since you don't have to construct a NestedModel
just to run the MCMC proposal. The current way the proposals are written is pretty agnostic of the NestedModel and Nested structs.
Also, the tests are failing because you need to update these tests to use the new proposal interface:
NestedSamplers.jl/test/proposals/proposals.jl
Lines 16 to 17 in 2b3423c
logl(X) = -sum(x->x^2, X) | |
prior(u) = 2u .- 1 # Uniform -1, to 1 |
It's really just to allow the user to specify the
Agreed. I actually had it implemented this way initially, but then I changed it to passing the EDIT: Oh I remember. The idea was that you could use other types of EDIT 2: And the current implementation also supports
Yeah I realized, just hadn't gotten around to it yet, but thanks 👍 |
Codecov Report
@@ Coverage Diff @@
## main #76 +/- ##
==========================================
- Coverage 90.55% 88.62% -1.93%
==========================================
Files 13 13
Lines 540 554 +14
==========================================
+ Hits 489 491 +2
- Misses 51 63 +12
Continue to review full report at Codecov.
|
Well... that is definitely the weirdest mix of test failures and successes I have ever seen. Fails on 1.3 Windows and 1.7 Mac, but totally fine on 1.3 Mac and 1.7 Windows. And then somehow, everything passes on Julia-latest, which is weird in and of itself. |
If you look at the logs, you can see that it's a numerical errors, i.e. that the approximation isn't good enough. Hence the "weird" pattern of behavior is likely just due to difference in RNG on the different architectures. |
I thought that might be the case, but everything is supposed to be using That being said I believe I found the error, in models.jl: |
Ah, nice catch 👍 Trying with the global |
Ok, now Windows nightly is failing some of the random numeric tests, which is very weird given everything I see has StableRNG attached to it. Literally went through every call to |
An idea: We can create a |
thanks for cleaning up the rng in the testing @ParadaCarleton. Overall the PR looks good, if there's just this test failing I'm happy to merge and I'll deal with that myself. |
That does seem to be the only problem, yeah. |
@mileslucas want to merge this, or should I? |
Thanks @torfjelde @ParadaCarleton ! |
This PR makes the following changes:
NestedModel
now only has a single field:prior_transform_and_loglikelihood
, which mapsu ↦ (v, logl)
, whereu
is a uniform random variable,v
isu
transformed, andlogl
is the loglikelihood atv
.prior_transform(model, u)
: replaces thenested_model.prior_transform
, allowing us to overload for othermodel
types too, if we so desire.loglikelihood(model, u)
: replaces thenested_model.loglike
, allowing us to overload for othermodel
types too, if we so desire.prior_transform_and_loglikelihood(model, u)
: combines bothprior_transfrom
andloglikelihood
into a single function call. This is useful because these two methods will often share computation in non-trivial models. All uses ofprior_transfrom
andloglikelihood
in#master
follows the patternv = prior_transform(u); logl = loglikelihood(v)
, and so combining these into a single function doesn't really change much internally.model
is passed around instead of functionsprior_transform
andloglike
, and then we instead use the newly introduced methods, e.g.prior_transform_and_loglikelihood(model, u)
instead.As an example/motivational use-cases, this PR makes it quite easy to make a
DynamicPPL.Model
compatible with NestedSamplers.jl:then we can just convert a
model::DynamicPPL.Model
into aNestedModel
by callingNestedModel(model)
.With a bit more code, we can also easily make a
NestedSampler
which is compatible with Turing rather than just converting into aNestedModel
, e.g. we get parameter names: https://gist.github.com/torfjelde/5dd1ed93a81759c98ff0ef3feeb24237.