-
Notifications
You must be signed in to change notification settings - Fork 37
Yongchao version: extracting parameter values for a model from chain #495
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
Conversation
…m:TuringLang/DynamicPPL.jl into torfjelde/extract-model-values-from-chain
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…into yongchao/extract-model-values-from-chain
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
src/model_utils.jl
Outdated
| ### Yong ############################################################## | ||
| # Yong added the below new functions on 2023-07-04, they are doing the some functionalities as Tor's functions. Some redundancy needs to be removed? | ||
| using Turing, Distributions, DynamicPPL, MCMCChains, Random, Test | ||
| using Distributions, DynamicPPL, MCMCChains, Random, Test |
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.
We shouldn't depend on DynamicPPL -- self-dependency is not needed. As long as the code is defined from inside DynamicPPL.jl, it will automatically have access to all DynamicPPL functionalities.
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.
yes, removed now.
Pull Request Test Coverage Report for Build 5520892964
💛 - Coveralls |
src/model_utils.jl
Outdated
| ### Yong ############################################################## | ||
| # Yong added the below new functions on 2023-07-04, they are doing the some functionalities as Tor's functions. Some redundancy needs to be removed? | ||
| # using Turing, Distributions, DynamicPPL, MCMCChains, Random, Test | ||
| using Distributions, Random, Test |
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.
Some more comments on this:
- There is no need to import
DistributionsorRandomas it is already imported by DynamicPPL (see here and here) - There is no need to import
Testpackage fromDynamicPPLas it is only useful for testing. You can import them fromruntests.jl
I think many of these issues are from bad programing practices, i.e., scripting instead of setting up a proper workflow and sticking to it consistently.
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.
Yes, I learned about the best practice this afternoon, particularly where to put the using stuff for docs, src and test folders. Thanks for that.
I thus removed all the imports after checking their presence in their project files.
|
What is this PR doing that my PR isn't? I ask because right now it's somewhat unclear why another PR was needed. |
|
Thanks @torfjelde for checking this. These new functions are doing the same thing as yours, in a lightly different ways? After these tests, would it be possible to merge these functions into yours as multi-dispatched versions? |
Codecov ReportPatch coverage has no change and project coverage change:
Additional details and impacted files@@ Coverage Diff @@
## master #495 +/- ##
==========================================
- Coverage 76.40% 74.51% -1.90%
==========================================
Files 21 22 +1
Lines 2522 2586 +64
==========================================
Hits 1927 1927
- Misses 595 659 +64
☔ View full report in Codecov by Sentry. |
|
@YongchaoHuang can you clarify the main implementation differences, the pros and cons? We will only merge one PR based on merit. |
Sure. Below is a raw comparison. Same functionalities: Differences:
It outputs a logical True/False indicator (if PR481 has multi-dispatched functions for this: they output an array My understanding is that, when testing if a
It iteratively extracts each PR481 also iteratively tests each the presence of each The only confusion for me here is again the presence of the output array
This allows one to extract the sample values of any user-specified Then I defined two methods for extracting sample values from chain: they both return an further, we may not be happy just extract a single row of sample values for all variables; we may want to specify the index ranges for chain number and iteration number. So I defined and multi-dispatched the following functions: They return an PR481 defines multiple functions for Similar to PR481 has two functions to extract all values from chain for all variables from model: This implementation is very efficient (nicer than my for loops - though some optimization work can be done in PR495 as well). However, it doesn't allow user-specified ranges of chain number and iteration number, e.g. I want the parameter values at chain 1:2 and iteration 100:200. Above are a crude comparison of both PRs, I may have missed/misunderstood some details. Please correct me if anything wrong or confusing @torfjelde @yebai |
Replies
A couple of things:
But what if I want to use a
This is a very common pattern in Julia. This is more memory efficient, and we're not going to be differentiating through this code, so mutation is not an issue.
This is the most robust way we have doing things, and ,in particular, it gives us
As above, this is very common in Julia.
This seems like unnecessary complication to me; it's really just replacing a
Why change the return-value from the
As before, we don't want to work with stirngs.
Same as above, it's just a NoteAll in all, I'd give two pieces of advice here @yongchao:
|
Many thanks @torfjelde for the explanations, they are really helpful. The reason why I raises this new PR is, I thought these functions can be done in a slightly simple way, and the user interfaces look more clean I guess (e.g. the use of Some quick thoughts:
|
|
Closed in favour of #497 |
Alternative to #481 by @YongchaoHuang