Skip to content

Register Op as subclass of Distributions with rv_type defined #6493

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 1 commit into from
Feb 1, 2023

Conversation

ricardoV94
Copy link
Member

No description provided.

This is the case of distributions that return SymbolicRandomVariables
@ricardoV94 ricardoV94 requested review from cluhmann, michaelosthege and larryshamalama and removed request for cluhmann January 30, 2023 16:10
@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Merging #6493 (92d62f5) into main (90b6bec) will decrease coverage by 23.00%.
The diff coverage is 88.88%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #6493       +/-   ##
===========================================
- Coverage   94.74%   71.74%   -23.00%     
===========================================
  Files         148      148               
  Lines       27578    27790      +212     
===========================================
- Hits        26129    19939     -6190     
- Misses       1449     7851     +6402     
Impacted Files Coverage Δ
pymc/distributions/distribution.py 96.01% <80.00%> (-1.46%) ⬇️
pymc/tests/distributions/test_distribution.py 98.73% <100.00%> (+0.03%) ⬆️
pymc/sampling_jax.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/sampling/test_jax.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/logprob/test_utils.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/logprob/test_cumsum.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/tuning/test_scaling.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/logprob/test_mixture.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/tuning/test_starting.py 0.00% <0.00%> (-100.00%) ⬇️
pymc/tests/logprob/test_abstract.py 0.00% <0.00%> (-100.00%) ⬇️
... and 72 more

@michaelosthege
Copy link
Member

I'm not familiar with __new__ or clsdict. What's the purpose of this change?

One of the test failures will be get fixed by #6475. Just sayin' :)

@larryshamalama
Copy link
Member

I'm not familiar with __new__ or clsdict. What's the purpose of this change?

My understanding is that symbolic Ops were not subclasses of Distribution prior to this PR, but it was the case for RV Ops. Is that correct @ricardoV94 ? However, I forgot why it is beneficial to have such Ops to be subclasses of Distribution...

@ricardoV94
Copy link
Member Author

ricardoV94 commented Jan 31, 2023

The reason for these changes is to have distributions that return RandomVariables and SymbolicRandomVariables behave the same.

The metaclass does 2 things:

  1. Dispatching logp/logcdf/moment methods when implemented as methods of the class
  2. Register the Op class as a subclass of the PyMC distribution

Before this PR, it only did those for classes that return RandomVariables Op (as those were all the cases in early V4)

I was recently writing a test in another library where I asserted we were creating the right variables by saying isinstance(rv.owner.op, pm.Normal) but this only works for regular distributions. It doesn't work for Censored for example, in which case I had to import the specific rv_type and do isinstance(rv.owner.op, CensoredRV)

There is no reason for this distinction. As long as we keep the Distribution pseudo-classes they should work the same regardless of the type of objects they return.

@larryshamalama larryshamalama merged commit 65c1c68 into pymc-devs:main Feb 1, 2023
@ricardoV94 ricardoV94 deleted the register_rv_type branch June 6, 2023 03:03
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