generated from greta-dev/greta.template
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor ZIP and ZINB #17
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…, need to explore how the distribution is defined and why this could be happening from the TF end
…latter is less foolproof because I am not sure how greta handles negative integers for ZINB that only support non-negative integers), then (2) leverage on tf_lchoose that's already being used in some greta distributions, and finally (3) calculate things in log space before converting them back to regular space
… not sure if this is necessary, see greta-dev#15 (comment))
* add coda, cramer, distributional, extraDistr, likelihoodExplore, mvtnorm, and truncdist to Suggests * Update to Roxygen 7.3.1 * use globalVariables to capture NOTE * use new sentinel package structure - "greta-distributions-packate.R" * import some greta internals directly into helpers.R
Hi @hrlai ! thanks so much for this. I've made some changes to get checks to pass appropriately. Currently running into issues verifying that the distributions are matching the ones that they reference. I'll check back in on this. But keen to get this merged soon :) |
This was referenced Dec 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request builds on #15 . Changes in 08c82fd and 093ae0b addresses question raised in #15 (comment) , where the log likelihood doesn't quite match the output of
extraDistr::dzip
anddzinb
. In the refactor codes, the R equivalent for ZIP now looks identical toextraDistr
:Created on 2022-11-30 with reprex v2.0.2
And ZINB also looks identical to
extraDistr
:Created on 2022-11-30 with reprex v2.0.2
Two things that I am not sure if 100% efficient or correct:
relu(x)
with1 - sign(abs(x))
because I don't feel comfortable withrelu
giving negativex
increasing values. I feel that it should be more like a step function to turn thepi_var
component "on" or "off" depending on whetherx == 0
. There might be a better way of doing ifelse-like condition in tensorflow but I don't know how...tf_lchoose
correctly...Earlier comments here and here actually only showed that
sample
is working, not thelog_prob
. I think we need to use these ZIP and ZINB withdistribution
ormodel
and thenmcmc
to properly test them, so here you go. For ZIP (sorryreprex
keeps crashing for the codes below, don't know why):And for ZINB:
Both ZIP and ZINB models seem to retrieve the true values well. Though the ZINB model seems to struggle a bit inferring the proportion of zeros.
Hope this makes sense. Will use it on real data and report any peculiarities back. Not 100% sure everything's correct 😉