Skip to content

Fix: importance_sampling=None produces error #427

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 3 commits into from
Mar 8, 2025

Conversation

aphc14
Copy link
Contributor

@aphc14 aphc14 commented Feb 18, 2025

Fix handling of importance_sampling="none" or None option

Changes

  • Modified the handling of importance sampling parameter to treat "none" and None consistently
  • Updated function signatures and documentation to clarify the importance sampling options

Added/Modified Tests

  • When importance sampling is disabled (None), samples retain shape (num_paths, num_draws_per_path, N) (where N are the number of model parameters)
  • Other importance sampling methods return samples of shape (num_draws, N)
  • Tighten np.testing.assert_allclose tolerance as increasing jitter brings parameter estimates closer to the reference value

… "none" or None

- Moved importance sampling logic from `multipath_pathfinder` to `fit_pathfinder` to fix error method is "none" or None
- Update docstrings to clarify importance sampling method behavior
- Use match statement for method selection in importance_sampling
- Test different importance sampling approaches (psis, psir, identity, None)
Copy link
Member

@fonnesbeck fonnesbeck left a comment

Choose a reason for hiding this comment

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

LGTM. Just one question.


if importance_sampling is not None:
importance_sampling = importance_sampling.lower()
importance_sampling = None if importance_sampling == "none" else importance_sampling
Copy link
Member

Choose a reason for hiding this comment

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

I thought you had globally removed the use of "none"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I thought about allowing a string for None as "none" to keep it consistent with the other importance_sampling options (i.e., "psis", "psir", "identity"). Come to think of it, None would be consistent with Python APIs in general with mixed argument types (str | None, int | None, etc).

I'll send another commit to remove the use of "none".

@aphc14 aphc14 requested a review from fonnesbeck February 19, 2025 09:56
@zaxtax
Copy link
Contributor

zaxtax commented Mar 1, 2025

Is this good to merge?

@aphc14
Copy link
Contributor Author

aphc14 commented Mar 2, 2025

Yes I believe so. @fonnesbeck ?

@zaxtax zaxtax merged commit 49e2818 into pymc-devs:main Mar 8, 2025
5 checks passed
@zaxtax
Copy link
Contributor

zaxtax commented Mar 8, 2025

I just went ahead and merged this. Thanks @aphc14 !

@aphc14
Copy link
Contributor Author

aphc14 commented Mar 10, 2025

Thanks @zaxtax !

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