-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Refactored LKJCorr and _LKJCholeskyCov #4784
Conversation
Thanks for this PR @kc611 ! In the wrapper function |
I have a couple of examples where I'm trying using The context is that I'm trying to enable correlated priors for group-specific effects in Bambi and I'm trying to figure out what is the most efficient way of doing it in PyMC3. |
Hi Tomas, |
pymc3/tests/test_distributions.py
Outdated
@@ -2051,7 +2051,6 @@ def test_wishart(self, n): | |||
pass | |||
|
|||
@pytest.mark.parametrize("x,eta,n,lp", LKJ_CASES) | |||
@pytest.mark.xfail(reason="Distribution not refactored yet") | |||
def test_lkj(self, x, eta, n, lp): |
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.
@ricardoV94 is the case (np.array([0.7,0,-0.7]), 0, 3, -np.inf)
here a extreme corner case ?
It looks like previously, this tests didn't pass through random
(which now is it's rng_fn
) for logp
, now it does. And hence fails.
Here the example notebook. I uploaded it to Google Drive because Github does not allow sharing notebooks here. |
Codecov Report
@@ Coverage Diff @@
## main pymc-devs/pymc#4784 +/- ##
==========================================
- Coverage 80.44% 76.00% -4.45%
==========================================
Files 82 88 +6
Lines 14132 14142 +10
==========================================
- Hits 11369 10749 -620
- Misses 2763 3393 +630
|
There's also https://github.com/pymc-devs/pymc3/issues/3473 which would be good to address. |
Any progress on this one? |
Porting the So I'll probably need help on this one. Possibly from someone who is familiar with this distribution and the sampling thereof. |
6599c94
to
f4bd741
Compare
@kc611 I think you need to rebase. |
Dear all, traceback:
I can work around this by simply using a single |
And another problem.
(sorry for the bad news; just trying myself to get it working and hope to help by sharing the pitfalls) |
Hi @falkmielke , glad to see you interested in our work. Seems like the current implementation works for you locally for certain cases. Is that right ?
I think in case of a singular
This seems to be an issue we'll need to look into. However at first glance it seems that this is a P.S. : The reason why this PR is halted is because the sampling from |
Dear @kc611 , I am now stuck with new shape problems, which are again over the top of my head. I guess most are related to other work in progress (e.g. I saw this PR). I'll try to formulate reports once I can clarify what's going on. Thanks for pointing out the unexpected results. No worries, all my data and results are "reality-checked". For me as a layman, it is a bit frustrating to be working on the dev version, constantly crashing into new issues; but it's also fun and I hope the issues I stumble upon help you guys in further development :) Cheers! |
Hi again @kc611 et al., I'd like to share some more observations, since I fail to get this running in most cases. Again, this is just the perspective of an end user not closely following the dev progress. I've been drawn into this because I require the latest build to get posterior sampling to work, and I'm still hoping to achieve this. I appreciate any hints or pointers to other PRs which help me to get this running! Meanwhile, I'll keep pulling the latest versions and keep fingers crossed that one day versionspymc: v4.0 (Sep 22 from github) use casesJust a brief overview of what my use cases are: IssuesNote that all issues I describe here happen in model construction time, i.e. prior to sampling. Issue 1: compute_corrFirst off, a detail, there is an unintuitive difference between [*.*.0] and [*.*.1]. When setting Issue 2: shaped
|
7de4596
to
29a7931
Compare
pymc/distributions/multivariate.py
Outdated
sd_vals = at.sqrt(variance) | ||
|
||
# TODO: Since the sd_dist logp is added independently, | ||
# we can perhaps compose the logp terms in a more clean way |
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.
The issue with calling logpt
directly over here is that logpt
tries to filter the input values according to RV's shape. So we'd have to put an limitation on shapes if we try to do it like that.
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 didn't mean that. But this approach seems fine in any case. As long as it doesn't result in some value variable missing warnings
|
||
def random(self, point=None, size=None): | ||
samples = np.linalg.cholesky(C)[..., tril_idx[0], tril_idx[1]] |
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.
The LKJCorrRV
can be called over here if this particular operation (i.e. np.linalg.cholesky(C)
) along with C *= D[..., :, np.newaxis] * D[..., np.newaxis, :]
can be done after we index the C
array as C[..., tril_idx[0], tril_idx[1]]
.
If that's the case then sure we could avoid rewriting the code above and directly call LKJCorrRV.rng_fn
upon these arguments.
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 am not sure, but worth investigating it
@kc611 Did you get a chance to resume work on this PR? What were the remaining issues? |
* `sd_dist` is now a standard parameter (with a prior specified outside of the distribution)
I think I found a bug in the old random method of the LKJCholeskyCov |
😨 is it too bad? Do you want a second pair of eyes to double check that? |
Closing in favor of #5382 |
This PR refactors
LKJCorr
and_LKJCholeskyCov
multivariate distributions forv4
.