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

Allow non-scalar measurable switch mixtures #6796

Merged

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented Jun 26, 2023

This PR expands the supported Mixture graphs beyond the scalar case.

It comes at the cost of not creating a lazy evaluation logp graph that the old MixtureRV approach did, but benefits from allowing arbitrary measurable variables and not just pure RVs.

In a future PR I intend to introduce a lazy Mixture RV that brings back that functionality, but that's right now blocked by pymc-devs/pytensor#329

CC @shreyas3156


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

@codecov
Copy link

codecov bot commented Jun 26, 2023

Codecov Report

Merging #6796 (df9f1b8) into main (7b08fc1) will decrease coverage by 3.71%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #6796      +/-   ##
==========================================
- Coverage   91.92%   88.22%   -3.71%     
==========================================
  Files          95       95              
  Lines       16197    16233      +36     
==========================================
- Hits        14889    14321     -568     
- Misses       1308     1912     +604     
Impacted Files Coverage Δ
pymc/distributions/truncated.py 99.40% <100.00%> (-0.01%) ⬇️
pymc/logprob/mixture.py 96.90% <100.00%> (+0.57%) ⬆️

... and 21 files with indirect coverage changes

Copy link
Member

@larryshamalama larryshamalama left a comment

Choose a reason for hiding this comment

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

As always, looks great @ricardoV94 😅 As usual, some questions from my side

pymc/logprob/mixture.py Outdated Show resolved Hide resolved
pymc/logprob/mixture.py Show resolved Hide resolved
tests/logprob/test_mixture.py Outdated Show resolved Hide resolved
tests/logprob/test_mixture.py Show resolved Hide resolved

invalid_mix = pt.switch(valid_switch_cond, valid_true_branch, invalid_false_branch)
fgraph, _, _ = construct_ir_fgraph({invalid_mix: invalid_mix.type()})
assert not isinstance(fgraph.outputs[0].owner.op, MeasurableVariable)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be more clear to rename the fgraphs and invalid_mixes in this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure!

Copy link
Member Author

Choose a reason for hiding this comment

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

On a second thought... rename to what? I feel the names are pretty reasonable?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was just alluding to the redundancy in names (three presences of fgraph, two of invalid_mix).

@ricardoV94 ricardoV94 force-pushed the make_switch_mixtures_more_flexible_basic branch from 2441185 to 9f65891 Compare June 29, 2023 12:49
tests/logprob/test_mixture.py Show resolved Hide resolved

invalid_mix = pt.switch(valid_switch_cond, valid_true_branch, invalid_false_branch)
fgraph, _, _ = construct_ir_fgraph({invalid_mix: invalid_mix.type()})
assert not isinstance(fgraph.outputs[0].owner.op, MeasurableVariable)
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I was just alluding to the redundancy in names (three presences of fgraph, two of invalid_mix).

pymc/logprob/mixture.py Outdated Show resolved Hide resolved
@ricardoV94 ricardoV94 force-pushed the make_switch_mixtures_more_flexible_basic branch from 9f65891 to df9f1b8 Compare June 30, 2023 07:05
@ricardoV94 ricardoV94 merged commit cb2c77f into pymc-devs:main Jun 30, 2023
20 of 21 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.

2 participants