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

Rename logprob/joint_logp to logprob/basic and move logcdf and icdf functions there #6599

Merged
merged 3 commits into from
Mar 25, 2023

Conversation

ricardoV94
Copy link
Member

This PR is a spinoff of #6597, to facilitate review.

Important changes:

  • logprob/joint_logprob module was renamed to logprob/basic.py
    It holds all the user-facing probability constructors
  • The dispatch call helpers in abstract are now private-named functions and their behavior is clarified
  • logp no longer calls the heavier factorized_joint_logprob. It immediately dispatches on the IR

@ricardoV94 ricardoV94 added the major Include in major changes release notes section label Mar 14, 2023
@ricardoV94 ricardoV94 changed the title Refactor joint logprob module Rename logprob/joint_logp to logprob/basic and move logcdf and icdf helpers there Mar 14, 2023
@ricardoV94 ricardoV94 changed the title Rename logprob/joint_logp to logprob/basic and move logcdf and icdf helpers there Rename logprob/joint_logp to logprob/basic and move logcdf and icdf functions there Mar 14, 2023
@ricardoV94 ricardoV94 force-pushed the refactor_joint_logprob_module branch from dc42929 to bf2b1d7 Compare March 14, 2023 10:33
@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Merging #6599 (7821ebe) into main (2fcce43) will decrease coverage by 0.02%.
The diff coverage is 97.05%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6599      +/-   ##
==========================================
- Coverage   92.03%   92.02%   -0.02%     
==========================================
  Files          93       93              
  Lines       15746    15750       +4     
==========================================
+ Hits        14492    14494       +2     
- Misses       1254     1256       +2     
Impacted Files Coverage Δ
pymc/distributions/mixture.py 95.40% <66.66%> (-0.03%) ⬇️
pymc/logprob/abstract.py 98.80% <94.73%> (+1.21%) ⬆️
pymc/distributions/bound.py 100.00% <100.00%> (ø)
pymc/distributions/continuous.py 97.70% <100.00%> (ø)
pymc/distributions/discrete.py 98.73% <100.00%> (ø)
pymc/distributions/timeseries.py 94.54% <100.00%> (ø)
pymc/distributions/truncated.py 99.30% <100.00%> (+<0.01%) ⬆️
pymc/logprob/__init__.py 100.00% <100.00%> (ø)
pymc/logprob/basic.py 98.92% <100.00%> (ø)
pymc/logprob/cumsum.py 100.00% <100.00%> (ø)
... and 7 more

... and 1 file with indirect coverage changes

@michaelosthege michaelosthege added this to the v5.2.0 milestone Mar 16, 2023
@ricardoV94 ricardoV94 force-pushed the refactor_joint_logprob_module branch from bf2b1d7 to 4e14f43 Compare March 16, 2023 13:34
pymc/logprob/basic.py Show resolved Hide resolved
"""Return the log-probability graph of a Random Variable"""

value = pt.as_tensor_variable(value, dtype=rv.dtype)
try:
return logp_logprob(rv, value)
return logp_logprob(rv, value, **kwargs)
except NotImplementedError:
Copy link
Member

Choose a reason for hiding this comment

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

Let me see if I understand this correctly:

We enter this NonImplementedError in cases where the rv.owner.op has a type that was not registered anywhere with @_logprob.register(...), and so that falls back to the default (non)-implementation in abstract.py.

In these cases, why would the FunctionGraph approach work?

Copy link
Member Author

@ricardoV94 ricardoV94 Mar 16, 2023

Choose a reason for hiding this comment

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

It falls back to the intermediate representation (IR) which converts stuff like Exp(Beta) into MeasurableExp(Beta) (or whatever is deemed valid), which itself has a logp method dispatched.

That's basically how inference for non basic RVs is carried out.

pymc/logprob/abstract.py Outdated Show resolved Hide resolved
@ricardoV94 ricardoV94 force-pushed the refactor_joint_logprob_module branch 2 times, most recently from 7dec389 to a9ff874 Compare March 24, 2023 06:10
@ricardoV94 ricardoV94 force-pushed the refactor_joint_logprob_module branch from a9ff874 to 7821ebe Compare March 24, 2023 06:43
@ricardoV94
Copy link
Member Author

Ready for re-review

Copy link
Member

@Armavica Armavica left a comment

Choose a reason for hiding this comment

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

Ok, I think I understand this well enough. I like the clearer hierarchy of functions and the reduction of user-facing logp-related functions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logprob major Include in major changes release notes section
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants