Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add AbstractModel implementation of LogDensityProblems interface #110
Add AbstractModel implementation of LogDensityProblems interface #110
Changes from 3 commits
660b8bc
ccf5c6a
a13dd24
7833df3
3039cae
314cb57
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Maybe make
L
a subtype ofLogDensityProblems
? Otherwise, we import but never useLogDensityProblems.jl
.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.
There's no
LogDensityProblem
abstract type, so I'll just do what @devmotion suggested:)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.
My only concern is that wrappers can be very annoying due to method ambiguity issues (if e.g. someone defines methods for specific x and some abstract logdensity type, but is not aware of
LogDensityModel
) and since you are screwed if you forget to add some definition that should be forwarded (or some log densities define additional functions).Maybe don't define any
LogDensityProblems
functions at all? If you know it's a LogDensityModel, you can just calldimension(model.logdensity)
etc. in your sampler. And if not, you can't calldimension
etc. on your model anyway.So to summarize: I don't think
LogDensityProblems.dimension
etc. should be defined for the model.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.
There is no abstract logdensity type though? So If someone implements something like
LogDensityProblems.dimension
, it should always be a type they've defined themselves.Or am I misunderstanding you?
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.
My point is different (I think): I think it is sufficient if LogDensityProblems.dimension etc. are defined for
model.logdensity
and don't see the need for defining them formodel
. That would also avoid the issues with the wrapper.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.
I mean, yeah, you definitively can do without it, but IMO it can be annoying.
Most of the time you don't use AbstractMCMC in isolation, and so IMO it's nice to go
instead of
It's definitively not a big thing, but I can't see the downside of implementing these methods (since method ambiguities won't be an issue, as described above, unless someone is doing type-piracy).
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.
It will be an issue as soon as someone defines e.g.
logdensity(model::AbstractModel, x::MyType)
I think? And the new LogDensityProblemsAD is another issue: You would have to depend on it here as well if you want to supportADgradient(..., model::LogDensityModel)
(which IMO for the same reasons we should not do).In any case, I don't see a good reason why you should add these methods: If you work with
LogDensityModel
in a sampler, you already have to restrict your dispatches to this specific type of models because otherwise you can't calllogdensity
etc. So you know you only accept this type anyway, and then you can just as easily calldimension(model.logdensity)
in your sampler.The example I think is also not really a problem: In that case the user already has the
model.logdensity
since themodel
is constructed with it in the first place 🙂 And even if the user does not, I don't see a problem with usingmodel.logdensity
instead ofmodel
since it allows us to avoid all these wrapper-related issues.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.
Wouldn't it be even cooler and cleaner if it would just work automatically and you don't have to wrap your LogDensityProblem-compatible model? Maybe we should support arbitrary types of models that implement the LogDensityProblems interface in AbstractMCMC and downstream packages? If that's the general API then one could just sample with anything and always call
logdensity
etc, regardless of the type (if samplers want to support that - otherwise they could still restrictsample
to some specific types of models).A
LogDensityModel
would be mainly useful then if multiple sampler packages have the same structure of models. But its purpose would not be to forwardlogdensity
tologdensity
of some wrapped function/model - since in that case you could have used the wrapped function/model directly.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.
Aye it would be, but wouldn't
sample(model, ...)
without restricting toAbstractModel
be doomed to lead to method ambiguities?As I said, I'm happy to drop them and just get this
LogDensityModel
into the package without the forwarded methods, with its purpose just being to indicate that the wrapped object implements theLogDensityInterface
. So should I just do this then?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.
Is there a specific example you have in mind? I think it should be fine eg. if we define no method with type restriction on model in AbstractMCMC (as other arguments should also be more specific in downstream implementations) but maybe there's an example that would be problematic. Generally, I assume due to the AbstractSampler argument and the fact that StatsBase mainly deals with sampling arrays (IIRC) there should not be any problems with other (common) packages - but again, maybe I miss something.
I think this would be the best way forward - not only because I still have doubts regarding the interface for LogDensityProblems but also because IMO it's easier to add stuff incrementally than to remove and break functionality and interfaces again.
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.
No, just slightly worried it might happen, though I agree I'd expect it to generally be okay.
I agree with this 👍 I'll do that then:)
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.
Made the change; could you have a look now?:)