Skip to content
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

Implemented rng_fn to CAR/ICAR #7723

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Muhammad-Rebaal
Copy link

@Muhammad-Rebaal Muhammad-Rebaal commented Mar 15, 2025

Hi @jessegrabowski , @ricardoV94 !
I've implemented the rng_fn for the designated classes CAR/ICAR in the issue #7713 , so could you please review and let me know if there is anything needs to be changed .
Thank You !


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

Copy link

welcome bot commented Mar 15, 2025

Thank You Banner]
💖 Thanks for opening this pull request! 💖 The PyMC community really appreciates your time and effort to contribute to the project. Please make sure you have read our Contributing Guidelines and filled in our pull request template to the best of your ability.

Copy link
Member

@jessegrabowski jessegrabowski left a comment

Choose a reason for hiding this comment

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

Instead of doing all the decomposition here, just pass the precision matrix and set method = "eig" to multivariate_normal.

You will also need to add a test.

@ricardoV94
Copy link
Member

Unless there's some subtle complexity I would suggest to implement as a SymbolicRV like in: #7685

@Muhammad-Rebaal
Copy link
Author

Muhammad-Rebaal commented Mar 23, 2025

Instead of doing all the decomposition here, just pass the precision matrix and set method = "eig" to multivariate_normal.

You will also need to add a test.

Hi @jessegrabowski !

Yeah sure I'll do that . Is there any specified file for the test or I've to create a new file ?

Thank You !

@jessegrabowski
Copy link
Member

jessegrabowski commented Mar 23, 2025

Go into tests/distributions/test_multivariate.py::TestICAR::test_icar_rng_fn and update the test to no longer expect an error. Check the other test_rng_fn tests for how to validate the output.

It looks like you also have to run pre-commit

@Muhammad-Rebaal
Copy link
Author

Muhammad-Rebaal commented Mar 23, 2025

Go into tests/distributions/test_multivariate.py::TestICAR::test_icar_rng_fn and update the test to no longer expect an error. Check the other test_rng_fn tests for how to validate the output.

It looks like you also have to run pre-commit

Thanks @jessegrabowski for timely response!

I've updated the rng_fn and added the test as per your request. Let me know if anything needs to change ?

Once again Thank You !

@jessegrabowski
Copy link
Member

Did you check the PR that Ricardo linked? This would be the preferred way to go.

@Muhammad-Rebaal
Copy link
Author

Did you check the PR that Ricardo linked? This would be the preferred way to go.

You're referring that to write the rng_fn like SymbolicRV or something else?

@jessegrabowski
Copy link
Member

jessegrabowski commented Mar 23, 2025

You would convert the entire distribution into a SymbolicMVNormalUsedInternally subclass, like how MvStudentTRV was changed in the linked PR (check here specifically). Then no rng_fn is required at all. The rv_op signature will take all the inputs (mu, W, alpha, tau), and the extended_signature will be "[rng],[size],(n),(n,n),(),()->[rng],(n)", because mu is a vector, W is a matrix,andalphaandtau` are scalars, and it returns a vector.

Then do the same logic you already did in the rng_fn to compute draws, but symbolically in the rv_op. It will return:

        return cls(
            inputs=[rng, size, mu, W, alpha, tau],
            outputs=[next_rng, draws],
            method=method,
        )(rng, size, nu, mean, scale)

The method argument should be eig by default.

@Muhammad-Rebaal
Copy link
Author

You would convert the entire distribution into a SymbolicMVNormalUsedInternally subclass, like how MvStudentTRV was changed in the linked PR (check here specifically). Then no rng_fn is required at all. The rv_op signature will take all the inputs (mu, W, alpha, tau), and the extended_signature will be "[rng],[size],(n),(n,n),(),()->[rng],(n)", because mu is a vector, W is a matrix,andalphaandtau` are scalars, and it returns a vector.

Then do the same logic you already did in the rng_fn to compute draws, but symbolically in the rv_op. It will return:

        return cls(
            inputs=[rng, size, mu, W, alpha, tau],
            outputs=[next_rng, draws],
            method=method,
        )(rng, size, nu, mean, scale)

The method argument should be eig by default.

Hey @jessegrabowski !
Hope you are fine !

I've implemented that part but struggling with test part . Can you help me out with and tell me that what I'm missing ? Here's the link of the code file & error

Thank You !

@jessegrabowski
Copy link
Member

You can push the code you have so far and we can look at it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants