-
Notifications
You must be signed in to change notification settings - Fork 31
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
Fix for generated_quantities
#534
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
I'm happy with the general idea. We could also store the mapping inside |
I don't quite see how that would work; can you elaborate? |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
I mean we could store |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Hmm, I don't think I like that. IMO the |
|
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…e' into torfjelde/nested-get-and-setindxe
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #534 +/- ##
==========================================
+ Coverage 81.24% 81.32% +0.07%
==========================================
Files 24 25 +1
Lines 2932 2982 +50
==========================================
+ Hits 2382 2425 +43
- Misses 550 557 +7
☔ View full report in Codecov by Sentry. |
Co-authored-by: David Widmann <[email protected]>
Should we maybe wait until ConstructionBase.jl gets its version bump? Seems like the PR isn't far from going through. |
so we can make use of this also for Turing.predict, etc.
I think it might be worth having another look at this PR @yebai @sunxd3 @devmotion I added a couple of methods + moved the new functionality in to |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Make sense to me! |
Co-authored-by: Xianda Sun <[email protected]>
…e' into torfjelde/nested-get-and-setindxe
This should now be good to go once the tests pass:) |
As mentioned elsewhere, now that there is no longer such an easy mapping between the strings in the a resulting
Chains
to the variables in a givenVarInfo
, some methods, e.g.generated_quantities
don't work so well (TuringLang/Turing.jl#2077).This PR is one attempt at fixing this. It's not particularly satisfying but I struggle to see another way around which wouldn't require substantial changes to MCMCChains.jl.
The idea is basically as follows:
chains.info
field we add a dict-like mapping fromVarName
toSymbol
.chains
using aVarName
by simply mapping theVarName
to the correspondingSymbol
, and performing indexing as usual.nested_getindex
andnested_setindex!
which "tries a bit harder" to well,getindex
andsetindex!
. When I say "tries a bit harder" I mean that if we can't quite locate the corresponding varname, we see if we can identify a varname that subsumes it (aparent_varname
) and then use the "remainder"-lens to interact with the reconstructed object.The result: we preserve the structure-information present in
VarName
inChains
, and usingnested_setindex!
we can then correctly updated more structural variables, e.g. `Cholesky** variables.The downside: this is completely reliant on the
Chains
being constructed with theinfo
field having this varname-to-symbol mapping. Luckily, we can easily enforce this in chains returned from Turing.jl.Thoughts?
Fixes #515