Skip to content

Allow draws from Weibull, MvStudentT, LKJCorr and LKJCholeskyCovRV in alternative backends #7685

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

Merged
merged 6 commits into from
Mar 7, 2025

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Feb 19, 2025

This PR converts more RandomVariable Ops to SymbolicRandomVariable (built on top of other RV Ops), which makes them automatically compatible with alternative backends.

Depends on:
pymc-devs/pytensor#1222
pymc-devs/pytensor#1223


📚 Documentation preview 📚: https://pymc--7685.org.readthedocs.build/en/7685/

@ricardoV94 ricardoV94 force-pushed the more_symboic_rvs branch 5 times, most recently from 431666f to 5e57d03 Compare February 25, 2025 08:35
@ricardoV94 ricardoV94 changed the title Make more distributions symbolic so they work in different backends Weibull, MvStudentT, LKJCorr and LKJCholeskyCovRV can now be sampled in alternative backends Feb 27, 2025
@ricardoV94 ricardoV94 changed the title Weibull, MvStudentT, LKJCorr and LKJCholeskyCovRV can now be sampled in alternative backends Allow draws from Weibull, MvStudentT, LKJCorr and LKJCholeskyCovRV in alternative backends Feb 27, 2025
@ricardoV94
Copy link
Member Author

I added an option to forward the decomposition method to the underlying MvNormal. This will require the next PyTensor release

@ricardoV94 ricardoV94 force-pushed the more_symboic_rvs branch 4 times, most recently from 374e582 to b7f4fc5 Compare March 4, 2025 11:17
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 98.95833% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.83%. Comparing base (355b475) to head (48ffc97).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
pymc/distributions/multivariate.py 98.68% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7685      +/-   ##
==========================================
+ Coverage   83.15%   92.83%   +9.67%     
==========================================
  Files         107      107              
  Lines       18313    18320       +7     
==========================================
+ Hits        15228    17007    +1779     
+ Misses       3085     1313    -1772     
Files with missing lines Coverage Δ
pymc/distributions/continuous.py 98.26% <100.00%> (+36.99%) ⬆️
pymc/distributions/distribution.py 93.62% <100.00%> (+1.17%) ⬆️
pymc/distributions/shape_utils.py 91.44% <ø> (+1.06%) ⬆️
pymc/distributions/transforms.py 98.47% <100.00%> (+16.03%) ⬆️
pymc/distributions/multivariate.py 93.90% <98.68%> (+36.72%) ⬆️

... and 34 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ricardoV94 ricardoV94 marked this pull request as ready for review March 6, 2025 17:01
Copy link
Member

@twiecki twiecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skimmed.

z = z / pt.sqrt(pt.einsum("ij,ij->i", z, z.copy()))[..., np.newaxis]
P = P[..., 0:mp1, mp1].set(pt.sqrt(y[..., np.newaxis]) * z)
P = P[..., mp1, mp1].set(pt.sqrt(1.0 - y))
C = pt.einsum("...ji,...jk->...ik", P, P.copy())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would P.mT @ P just work here? We know P will always be at least 2d.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Einsum should arrive at the same thing though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, and I love einsum more than the average person, and actually find it more readable. Just curious what you thought about the alternative

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .mt @ is a bit more direct (avoids the OFG that is inlined later), this makes it easier to review the changes :)

@ricardoV94 ricardoV94 merged commit e9b3c99 into pymc-devs:main Mar 7, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants