-
-
Notifications
You must be signed in to change notification settings - Fork 69
Add GrassiaIIGeometric Distribution #528
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
Open
ColtAllen
wants to merge
35
commits into
pymc-devs:main
Choose a base branch
from
ColtAllen:grassia2geo-dist
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
269dd75
dist and rv init commit
ColtAllen b264161
Merge branch 'pymc-devs:main' into grassia2geo-dist
ColtAllen d734c68
docstrings
ColtAllen 71bd632
Merge branch 'grassia2geo-dist' of https://github.com/ColtAllen/pymc-…
ColtAllen 48e93f3
Merge branch 'pymc-devs:main' into grassia2geo-dist
ColtAllen 93c4a60
unit tests
ColtAllen d2e72b5
alpha min value
ColtAllen 8685005
revert alpha lim
ColtAllen 026f182
small lam value tests
ColtAllen d12dd0b
ruff formatting
ColtAllen bcd9cac
TODOs
ColtAllen 78be107
WIP add covar support to RV
ColtAllen f3ae359
Merge branch 'main' into grassia2geo-dist
ColtAllen 8a30459
WIP time indexing
ColtAllen 7c7afc8
WIP time indexing
ColtAllen fa9c1ec
Merge branch 'grassia2geo-dist' of https://github.com/ColtAllen/pymc-…
ColtAllen b957333
WIP symbolic indexing
ColtAllen d0c1d98
delete test_simple.py
ColtAllen 264c55e
fix symbolic indexing errors
ColtAllen 05e7c55
Merge branch 'pymc-devs:main' into grassia2geo-dist
ColtAllen 0fa3390
clean up cursor code
ColtAllen 5baa6f7
warn for ndims deprecation
ColtAllen a715ec7
clean up comments and final TODO
ColtAllen f3c0f29
remove ndims deprecation and extraneous code
ColtAllen a232e4c
revert changes to irrelevant test
ColtAllen ffc059f
remove time_covariate_vector default args
ColtAllen 1d41eb7
revert remaining changes in irrelevant tests
ColtAllen 47ad523
remove test_sampling_consistency
ColtAllen 5b77263
checkpoint commit for log_cdf and test frameworks
ColtAllen eb7222f
checkpoint commit for log_cdf and test frameworks
ColtAllen b34e3d8
make C_t external function, code cleanup
ColtAllen 9803321
rng_fn cleanup
ColtAllen 5ff6853
WIP test frameworks
ColtAllen 63a0b10
inverse cdf
ColtAllen 932a046
covariate pos constraint and WIP RV
ColtAllen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,10 +425,12 @@ def rng_fn(cls, rng, r, alpha, time_covariate_vector, size): | |
# Calculate exp(time_covariate_vector) for all samples | ||
exp_time_covar = np.exp( | ||
time_covariate_vector | ||
).mean() # must average over time for correct broadcasting | ||
).mean() # Approximation required to return a t-scalar from a covariate vector | ||
lam_covar = lam * exp_time_covar | ||
|
||
samples = np.ceil(rng.exponential(size=size) / lam_covar) | ||
# Take uniform draws from the inverse CDF | ||
u = rng.uniform(size=size) | ||
samples = np.ceil(np.log(1 - u) / (-lam_covar)) | ||
|
||
return samples | ||
|
||
|
@@ -581,5 +583,5 @@ def C_t(t: pt.TensorVariable, time_covariate_vector: pt.TensorVariable) -> pt.Te | |
# If t_idx exceeds length of time_covariate_vector, use last value | ||
max_idx = pt.shape(time_covariate_vector)[0] - 1 | ||
safe_idx = pt.minimum(t_idx, max_idx) | ||
covariate_value = time_covariate_vector[safe_idx] | ||
return t * pt.exp(covariate_value) | ||
covariate_value = time_covariate_vector[..., safe_idx] | ||
return pt.exp(covariate_value).sum() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
This file contains hidden or 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
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.
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.
Are you sure about
log(1 - u)
? When I was writing in paper it seemed like it should just belog(u)
, or alternativelyexponential
and the-
inlam_covar
can be skippedThere 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.
Rather new to deriving inverse CDFs (and this particular derivation I did at 2am last night), but here's my general understanding:
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.
t is a vector so I don't think that makes sense. I'm not sure you can even invert the CDF of a multivariate distribution, because it won't be 1-1 in general.
Uh oh!
There was an error while loading. Please reload this page.
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.
t == len(C(t))
. I'm not happy with the approximation, but it was the only way I could think of to use the inverse CDF.The only alternative is
t
geometric draws for each sample covariate vector. To provide time context, the vector has to be aggregated in some way, be it sum, mean, or product. Might just have to start experimenting with PPCs in a notebook to see which agg option seems most viableThere 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.
From your description of the situation that sounds the most reasonable