-
-
Notifications
You must be signed in to change notification settings - Fork 58
Make fit_pathfinder more similar to fit_laplace and pm.sample #447
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
Conversation
This looks alright to me. Thoughts @ricardoV94 ? |
CC @aphc14 |
pymc_extras/__init__.py
Outdated
from pymc_extras.inference.find_map import find_MAP | ||
from pymc_extras.inference.fit import fit | ||
from pymc_extras.inference.laplace import fit_laplace | ||
from pymc_extras.inference import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use explicit imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course. I'll fix that when I have a few minutes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
The inference data containing the results of the Pathfinder algorithm. | ||
|
||
References | ||
---------- | ||
Zhang, L., Carpenter, B., Gelman, A., & Vehtari, A. (2022). Pathfinder: Parallel quasi-Newton variational inference. Journal of Machine Learning Research, 23(306), 1-49. | ||
""" | ||
|
||
if initvals is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't mutate the model, make a copy perhaps if there's no better way to just forward the initvals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would normally agree. However, I tried it, but model.copy() does not produce a working model sometimes - most notably when any transformations are used.
Should I use some other copy function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@velochy you want the clone_model
function https://github.com/pymc-devs/pymc/blob/2842401f95de74ab37b7750cff455af28cddaffa/pymc/model/fgraph.py#L374
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for that @zaxtax
Updated the code. Also added a test to check if initvals are used correctly.
@ricardoV94 it currently also fails a test on including blackjax, which is currently included in pathfinder.py |
Yup, that is a good idea. closes #443 |
The inference data containing the results of the Pathfinder algorithm. | ||
|
||
References | ||
---------- | ||
Zhang, L., Carpenter, B., Gelman, A., & Vehtari, A. (2022). Pathfinder: Parallel quasi-Newton variational inference. Journal of Machine Learning Research, 23(306), 1-49. | ||
""" | ||
|
||
if initvals is not None: | ||
for rv_name, ivals in initvals.items(): | ||
model.set_initval(model.named_vars[rv_name], ivals) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might need to ensure that ivals is a support point for the RV. For example, x ~ Uniform(-1, 1) would have nan
initial values with model.set_initval(model.named_vars["x"], 2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While in the ideal world, I would agree, in practice
a) It is very nontrivial to do as I understand, as the limits are not specified anywhere where they are easy to take
b) pm.sample does no such checks, and the goal of this PR is to be compatible with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, seems fair enough. Thanks for this submission @velochy
Maybe we make a requirements-test.txt file like arviz has?
https://github.com/arviz-devs/arviz/blob/main/requirements-test.txt
…On Wed, 9 Apr 2025, 14:28 Margus Niitsoo, ***@***.***> wrote:
@ricardoV94 <https://github.com/ricardoV94> it currently also fails a
test on including blackjax, which is currently included in pathfinder.py
How would you like to handle it? Do I bring the include lower down so it
is only included when used, or do I add it to the requirements of the
package?
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUM66WC34I7BYIQZWT32YUG5LAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZGUZTOMRUG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
*velochy* left a comment (pymc-devs/pymc-extras#447)
<#447 (comment)>
@ricardoV94 <https://github.com/ricardoV94> it currently also fails a
test on including blackjax, which is currently included in pathfinder.py
How would you like to handle it? Do I bring the include lower down so it
is only included when used, or do I add it to the requirements of the
package?
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUM66WC34I7BYIQZWT32YUG5LAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZGUZTOMRUG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Considering you have a standing PR on this, does it not make more sense to just have your quickfix merged separately? |
Definitely!
…On Wed, 9 Apr 2025, 18:00 Margus Niitsoo, ***@***.***> wrote:
Yup, that is a good idea. closes #443
<#443>
Considering you have a standing PR on this, does it not make more sense to
just have your quickfix merged separately?
I don't think it conflicts with anything I've done here
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUIEXAGQCBW56OPD6R32YU7ZZAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOJQGIYDINJWHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
*velochy* left a comment (pymc-devs/pymc-extras#447)
<#447 (comment)>
Yup, that is a good idea. closes #443
<#443>
Considering you have a standing PR on this, does it not make more sense to
just have your quickfix merged separately?
I don't think it conflicts with anything I've done here
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUIEXAGQCBW56OPD6R32YU7ZZAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOJQGIYDINJWHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
1ee9bcf
to
370ffe0
Compare
The latest test failure is due to pathfinder using |
Is there anything I should still do? |
Try to rebase your PR. If it still fails for unrelated reasons, that's not on you to resolve
…On Mon, 14 Apr 2025, 17:04 Margus Niitsoo, ***@***.***> wrote:
Is there anything I should still do?
Tests are failing for things unrelated to this PR to the best of my
understanding, and I have addressed all of the comments
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUNBG4YRRB3WV4M534T2ZPE7LAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGAZDCNBVGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
*velochy* left a comment (pymc-devs/pymc-extras#447)
<#447 (comment)>
Is there anything I should still do?
Tests are failing for things unrelated to this PR to the best of my
understanding, and I have addressed all of the comments
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUNBG4YRRB3WV4M534T2ZPE7LAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBSGAZDCNBVGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
f53445a
to
b81684d
Compare
"identity" : Applies log importance weights directly without resampling. | ||
None : No importance sampling weights. Returns raw samples of size (num_paths, num_draws_per_path, N) where N is number of model parameters. Other methods return samples of size (num_draws, N). | ||
|
||
- **"psis"** : Pareto Smoothed Importance Sampling (default). Usually most stable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these ** characters? They aren't consistent the style used elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Can you also move the import of |
b81684d
to
3416258
Compare
I'm not sure why the build source distribution test is still unhappy. Can you investigate why importing jax still happens? |
…ue for pathfinder and cleaned relevant docs a bit
3416258
to
ef44c82
Compare
I think it was because of the import from pymc.sampling.jax. Moved that down as well. Hopefully tests will pass now |
What is still needed to get it merged? Review from @jessegrabowski ? |
Just giving others one last chance to chime in before I merge it 😀
…On Wed, 16 Apr 2025, 14:55 Margus Niitsoo, ***@***.***> wrote:
What is still needed to get it merged? Review from @jessegrabowski
<https://github.com/jessegrabowski> ?
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUMGP6MZSWI6CUJPSID2ZZHMBAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBZGUYDINBVGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
*velochy* left a comment (pymc-devs/pymc-extras#447)
<#447 (comment)>
What is still needed to get it merged? Review from @jessegrabowski
<https://github.com/jessegrabowski> ?
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACCUMGP6MZSWI6CUJPSID2ZZHMBAVCNFSM6AAAAAB2HVSQBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQMBZGUYDINBVGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This arose out of https://discourse.pymc.io/t/pymc-extras-fit-compatibility-with-pm-sample/16763/5